Skip to content

Commit

Permalink
Remove ImmutableList from api's model objects
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Roldan <gabriel.roldan@gmail.com>
  • Loading branch information
Gabriel Roldan authored and groldan committed May 2, 2019
1 parent bbb3c79 commit 121f70c
Show file tree
Hide file tree
Showing 85 changed files with 341 additions and 342 deletions.
Expand Up @@ -35,7 +35,6 @@
import org.opengis.feature.type.PropertyType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import com.google.common.collect.ImmutableList;
import com.google.common.hash.Funnel;
import com.google.common.hash.Funnels;
import com.google.common.hash.Hasher;
Expand Down Expand Up @@ -111,8 +110,8 @@ public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node>
@Nullable SortedMap<Integer, Bucket> buckets) {

final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
trees = trees == null ? ImmutableList.of() : trees;
features = features == null ? ImmutableList.of() : features;
trees = trees == null ? Collections.emptyList() : trees;
features = features == null ? Collections.emptyList() : features;
buckets = buckets == null ? Collections.emptySortedMap() : buckets;
HashObjectFunnels.tree(hasher, trees, features, buckets.values());

Expand Down Expand Up @@ -154,8 +153,8 @@ public static ObjectId hashTree(@Nullable List<Node> trees, @Nullable List<Node>
@Nullable Iterable<Bucket> buckets) {

final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
trees = trees == null ? ImmutableList.of() : trees;
features = features == null ? ImmutableList.of() : features;
trees = trees == null ? Collections.emptyList() : trees;
features = features == null ? Collections.emptyList() : features;
buckets = buckets == null ? Collections.emptySet() : buckets;
HashObjectFunnels.tree(hasher, trees, features, buckets);

Expand Down
Expand Up @@ -9,10 +9,9 @@
*/
package org.locationtech.geogig.model;

import java.util.List;
import java.util.Optional;

import com.google.common.collect.ImmutableList;

/**
* A revision commit is an immutable data structure that represents the full state of the repository
* at a given point in time (by pointing to a root {@link RevTree tree}), and contains information
Expand Down Expand Up @@ -91,7 +90,7 @@ public interface RevCommit extends RevObject {
*
* @return the list of parent commit ids for this commit
*/
public ImmutableList<ObjectId> getParentIds();
public List<ObjectId> getParentIds();

/**
* Short cut for {@code getParentIds().get(parentIndex)}, retuning an optional with the parent
Expand Down
Expand Up @@ -15,8 +15,6 @@
import org.locationtech.geogig.repository.DefaultPlatform;
import org.locationtech.geogig.repository.Platform;

import com.google.common.collect.ImmutableList;

import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
Expand Down Expand Up @@ -88,8 +86,8 @@ public RevCommit build() {
int authorOffset = authorTimeZoneOffset == null ? committerOffset : authorTimeZoneOffset;

final ObjectId treeId = this.treeId;
final ImmutableList<ObjectId> parentIds = this.parentIds == null ? ImmutableList.of()
: ImmutableList.copyOf(this.parentIds);
final List<ObjectId> parentIds = this.parentIds == null ? new ArrayList<>()
: this.parentIds;

final RevPerson author = RevPerson.builder().build(this.author, authorEmail, authorTs,
authorOffset);
Expand All @@ -107,7 +105,7 @@ public RevCommit build(@NonNull ObjectId treeId, @NonNull List<ObjectId> parents
final ObjectId commitId = HashObjectFunnels.hashCommit(treeId, parents, author, committer,
message);

return RevObjectFactory.defaultInstance().createCommit(commitId, treeId,
ImmutableList.copyOf(parents), author, committer, message);
return RevObjectFactory.defaultInstance().createCommit(commitId, treeId, parents, author,
committer, message);
}
}
Expand Up @@ -9,13 +9,12 @@
*/
package org.locationtech.geogig.model;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.locationtech.jts.geom.Geometry;

import com.google.common.collect.ImmutableList;

/**
* A {@code RevFeature} is an immutable data structure that contains the attribute value instances
* of a GIS feature, in the order defined by the {@link RevFeatureType} it was created for, although
Expand Down Expand Up @@ -53,7 +52,7 @@ public interface RevFeature extends RevObject, ValueArray {
/**
* @return a list of values, with {@link Optional#empty()} representing a null value
*/
public ImmutableList<Optional<Object>> getValues();
public List<Optional<Object>> getValues();

public static RevFeatureBuilder builder() {
return new RevFeatureBuilder();
Expand Down
Expand Up @@ -9,12 +9,12 @@
*/
package org.locationtech.geogig.model;

import java.util.List;

import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name;
import org.opengis.feature.type.PropertyDescriptor;

import com.google.common.collect.ImmutableList;

/**
* {@code RevFeatureType} is an immutable data structure that describes the schema for a set of
* {@link RevFeature features}, generally being referred to by the {@link Node#getMetadataId()
Expand Down Expand Up @@ -67,7 +67,7 @@ public interface RevFeatureType extends RevObject {
*
* @return the {@link PropertyDescriptor}s of the feature type
*/
public abstract ImmutableList<PropertyDescriptor> descriptors();
public abstract List<PropertyDescriptor> descriptors();

/**
* @return the name of the feature type
Expand Down
Expand Up @@ -9,10 +9,11 @@
*/
package org.locationtech.geogig.model;

import static com.google.common.base.Objects.equal;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand All @@ -22,9 +23,7 @@
import org.locationtech.jts.geom.Envelope;
import org.opengis.feature.type.PropertyDescriptor;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;

import lombok.NonNull;
Expand Down Expand Up @@ -124,9 +123,9 @@ public static Iterator<Node> children(@NonNull RevTree tree,
if (tree.featuresSize() == 0) {
return tree.trees().iterator();
}
ImmutableList<Node> trees = tree.trees();
ImmutableList<Node> features = tree.features();
return Iterators.mergeSorted(ImmutableList.of(trees.iterator(), features.iterator()),
List<Node> trees = tree.trees();
List<Node> features = tree.features();
return Iterators.mergeSorted(Arrays.asList(trees.iterator(), features.iterator()),
comparator);
}

Expand Down Expand Up @@ -261,13 +260,14 @@ private static byte hexToByte(char c) {
}

public static boolean equals(@NonNull RevPerson p1, @NonNull RevPerson person) {
return equal(p1.getName(), person.getName()) && equal(p1.getEmail(), person.getEmail())
return Objects.equals(p1.getName(), person.getName())
&& Objects.equals(p1.getEmail(), person.getEmail())
&& p1.getTimestamp() == person.getTimestamp()
&& p1.getTimeZoneOffset() == person.getTimeZoneOffset();
}

public static int hashCode(@NonNull RevPerson p) {
return Objects.hashCode(p.getName(), p.getEmail(), p.getTimestamp(), p.getTimeZoneOffset());
return Objects.hash(p.getName(), p.getEmail(), p.getTimestamp(), p.getTimeZoneOffset());
}

public static String toString(@NonNull RevPerson p) {
Expand Down
14 changes: 7 additions & 7 deletions src/api/src/main/java/org/locationtech/geogig/model/RevTree.java
Expand Up @@ -11,6 +11,7 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.SortedMap;
import java.util.SortedSet;
Expand All @@ -20,7 +21,6 @@
import org.locationtech.geogig.storage.ObjectStore;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

/**
Expand Down Expand Up @@ -93,8 +93,8 @@ public ObjectId getId() {
}

@Override
public ImmutableList<Node> trees() {
return ImmutableList.of();
public List<Node> trees() {
return Collections.emptyList();
}

@Override
Expand All @@ -113,8 +113,8 @@ public boolean isEmpty() {
}

@Override
public ImmutableList<Node> features() {
return ImmutableList.of();
public List<Node> features() {
return Collections.emptyList();
}

@Override
Expand Down Expand Up @@ -194,7 +194,7 @@ public default boolean isEmpty() {
*
* @apiNote the returned list does not contain {@code null} objects
*/
public ImmutableList<Node> trees();
public List<Node> trees();

/**
* @return the number of {@link Node}s in the {@link #trees} property
Expand Down Expand Up @@ -237,7 +237,7 @@ public default void forEachTree(Consumer<Node> consumer) {
*
* @apiNote the returned list does not contain {@code null} objects
*/
public ImmutableList<Node> features();
public List<Node> features();

/**
* @return the number of {@link Node}s in the {@link #features} property
Expand Down
Expand Up @@ -9,6 +9,8 @@
*/
package org.locationtech.geogig.model.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

Expand Down Expand Up @@ -43,13 +45,13 @@ class RevFeatureImpl extends AbstractRevObject implements RevFeature {
this.values = values;
}

public @Override ImmutableList<Optional<Object>> getValues() {
public @Override List<Optional<Object>> getValues() {
final int size = size();
Builder<Optional<Object>> builder = ImmutableList.builder();
List<Optional<Object>> retvalues = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
builder.add(Optional.ofNullable(ValueArray.safeCopy(values[i])));
retvalues.add(Optional.ofNullable(ValueArray.safeCopy(values[i])));
}
return builder.build();
return retvalues;
}

public @Override int size() {
Expand Down
Expand Up @@ -9,6 +9,8 @@
*/
package org.locationtech.geogig.model.impl;

import java.util.List;

import org.locationtech.geogig.model.ObjectId;
import org.locationtech.geogig.model.RevFeatureType;
import org.locationtech.geogig.model.RevObjects;
Expand Down Expand Up @@ -50,7 +52,7 @@ class RevFeatureTypeImpl extends AbstractRevObject implements RevFeatureType {
/**
* @return the list of {@link PropertyDescriptor}s of the feature type
*/
public @Override ImmutableList<PropertyDescriptor> descriptors() {
public @Override List<PropertyDescriptor> descriptors() {
return ImmutableList.copyOf(featureType.getDescriptors());
}

Expand Down
Expand Up @@ -11,6 +11,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand All @@ -22,7 +23,6 @@
import org.locationtech.geogig.model.RevObjects;
import org.locationtech.geogig.model.RevTree;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedMap.Builder;

Expand All @@ -43,12 +43,14 @@ public LeafTree(final ObjectId id, final long size, final @Nullable Node[] featu
this.trees = trees;
}

public @Override ImmutableList<Node> features() {
return features == null ? ImmutableList.of() : ImmutableList.copyOf(features);
public @Override List<Node> features() {
return features == null ? Collections.emptyList()
: Collections.unmodifiableList(Arrays.asList(features));
}

public @Override ImmutableList<Node> trees() {
return trees == null ? ImmutableList.of() : ImmutableList.copyOf(trees);
public @Override List<Node> trees() {
return trees == null ? Collections.emptyList()
: Collections.unmodifiableList(Arrays.asList(trees));
}

public @Override int numTrees() {
Expand Down Expand Up @@ -154,12 +156,12 @@ private RevTreeImpl(ObjectId id, long size) {
return size;
}

public @Override ImmutableList<Node> features() {
return ImmutableList.of();
public @Override List<Node> features() {
return Collections.emptyList();
}

public @Override ImmutableList<Node> trees() {
return ImmutableList.of();
public @Override List<Node> trees() {
return Collections.emptyList();
}

public @Override ImmutableSortedMap<Integer, Bucket> buckets() {
Expand Down
Expand Up @@ -12,6 +12,7 @@
import static com.google.common.base.Objects.equal;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -24,7 +25,6 @@

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -97,7 +97,7 @@ public void init(DAG from) {

public DAG(TreeId id) {
this.id = id;
this.children = ImmutableMap.of();
this.children = Collections.emptyMap();
this.originalTreeId = RevTree.EMPTY_TREE_ID;
this.state = STATE.INITIALIZED;
}
Expand All @@ -117,7 +117,7 @@ public DAG(TreeId id, ObjectId originalTreeId) {
this.children = new HashMap<>();
this.originalTreeId = originalTreeId;
this.state = STATE.INITIALIZED;
this.children = ImmutableMap.of();
this.children = Collections.emptyMap();
this.buckets = ImmutableSet.of();
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public STATE getState() {
public void clearChildren() {
if (!children.isEmpty()) {
setMutated();
this.children = ImmutableMap.of();
this.children = Collections.emptyMap();
}
}

Expand Down

0 comments on commit 121f70c

Please sign in to comment.