Skip to content

Commit

Permalink
Move Rev*Impl to geogig-api
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Roldan <gabriel.roldan@gmail.com>
  • Loading branch information
groldan committed Dec 2, 2018
1 parent 8d080ea commit 86985d5
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 85 deletions.
9 changes: 2 additions & 7 deletions src/api/src/main/java/org/locationtech/geogig/model/Node.java
Expand Up @@ -18,10 +18,10 @@

import org.eclipse.jdt.annotation.Nullable;
import org.locationtech.geogig.model.RevObject.TYPE;
import org.locationtech.jts.geom.Envelope;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import org.locationtech.jts.geom.Envelope;

/**
* An identifier->object id mapping for an object
Expand All @@ -41,11 +41,6 @@ public abstract class Node implements Bounded, Comparable<Node> {
*/
public abstract String getName();

/**
* @return the id of the {@link RevObject} this Node points to
*/
public abstract ObjectId getObjectId();

public abstract Optional<ObjectId> getMetadataId();

/**
Expand Down Expand Up @@ -111,7 +106,7 @@ public String toString() {
.append(" -> ").append(getObjectId()).append(']').toString();
}

private static abstract class BaseNode extends Node {
private abstract static class BaseNode extends Node {

/*
* The name of the element
Expand Down
32 changes: 17 additions & 15 deletions src/api/src/main/java/org/locationtech/geogig/model/RevObject.java
Expand Up @@ -11,9 +11,10 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Ordering;
import com.google.common.hash.HashFunction;

import lombok.NonNull;

/**
* Base interface for the closed set of revision objects that are stored in a GeoGig repository.
* <p>
Expand All @@ -39,17 +40,7 @@
*
* @since 1.0
*/
public interface RevObject {
/**
* A "natural order" {@link Ordering comparator} for revobject instances based on the
* {@link ObjectId}
*/
public static final Ordering<RevObject> NATURAL_ORDER = new Ordering<RevObject>() {
@Override
public int compare(RevObject o1, RevObject o2) {
return o1.getId().compareTo(o2.getId());
}
};
public interface RevObject extends Comparable<RevObject> {

/**
* {@code RevObject} types enumeration.
Expand All @@ -58,7 +49,7 @@ public int compare(RevObject o1, RevObject o2) {
* method must return the enum value corresponding to it's kind of object in the closed set of
* revision objects that comprise GeoGig's repository's object model
*/
public static enum TYPE {
public enum TYPE {
/**
* Enum value for objects of type {@link RevCommit}
*/
Expand Down Expand Up @@ -190,11 +181,22 @@ public static TYPE valueOf(final Class<? extends RevObject> binding) {
public ObjectId getId();

/**
* Equality is based on id, since to revision objects that hashed out to the same
* {@link ObjectId} are guaranteed to be equal (as far as SHA-1 collision probabilities go).
*
* @implNote Given any two objects of the same type with the same exact contents shall hash out
* to the same {@link ObjectId}, {@link #equals(Object) equality} checks can merely
* compare the two {@link ObjectId}s for equality.
*
*/
@Override
public boolean equals(Object o);
public @Override boolean equals(Object o);

/**
* Comparison is made according the to natural order of {@link RevObject#getId()}.
* <p>
* {@inheritDoc}
*/
public default @Override int compareTo(@NonNull RevObject other) {
return getId().compareTo(other.getId());
}
}
Expand Up @@ -42,6 +42,9 @@ public static RevObjectFactory defaultInstance() {
return RevObjects.lookupDefaultFactory();
}

public RevPerson createPerson(String name, String email, long timeStamp,
int timeZoneOffset);

public @NonNull RevCommit createCommit(@NonNull ObjectId id, @NonNull ObjectId treeId,
@NonNull List<ObjectId> parents, @NonNull RevPerson author,
@NonNull RevPerson committer, @NonNull String message);
Expand All @@ -61,4 +64,5 @@ public static RevObjectFactory defaultInstance() {
public @NonNull RevFeature createFeature(@NonNull ObjectId id, @NonNull List<Object> values);

public @NonNull RevFeature createFeature(@NonNull ObjectId id, @NonNull Object... values);

}
Expand Up @@ -18,16 +18,15 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;

import lombok.extern.slf4j.Slf4j;
import lombok.experimental.UtilityClass;

/**
* A set of utility methods to work with revision objects
*
*
* @since 1.0
*/
@Slf4j
public class RevObjects {
public @UtilityClass class RevObjects {

/**
* An identifier for a null coordinate reference system.
Expand Down
Expand Up @@ -18,8 +18,6 @@
import org.locationtech.geogig.model.RevTag;
import org.locationtech.geogig.model.RevTree;

import com.google.common.base.Preconditions;

import lombok.NonNull;

/**
Expand Down Expand Up @@ -54,12 +52,6 @@ public final ObjectId getId() {
return ObjectId.create(h1, h2, h3);
}

/**
* Equality is based on id, since to revision objects that hashed out to the same
* {@link ObjectId} are guaranteed to be equal (as far as SHA-1 collision probabilities go)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public final @Override boolean equals(Object o) {
return (o instanceof RevObject) && getId().equals(((RevObject) o).getId());
}
Expand Down
@@ -0,0 +1,87 @@
/* Copyright (c) 2014-2016 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Gabriel Roldan (Boundless) - initial implementation
*/
package org.locationtech.geogig.model.impl;

import org.locationtech.geogig.model.ObjectId;
import org.locationtech.geogig.model.RevFeatureType;
import org.opengis.feature.type.FeatureType;
import org.opengis.feature.type.Name;
import org.opengis.feature.type.PropertyDescriptor;

import com.google.common.collect.ImmutableList;

import lombok.NonNull;

/**
* A binary representation of the state of a Feature Type.
*/
class RevFeatureTypeImpl extends AbstractRevObject implements RevFeatureType {

private final FeatureType featureType;

/**
* Constructs a new {@code RevFeatureType} from the given {@link ObjectId} and
* {@link FeatureType}.
*
* @param id the object id to use for this feature type
* @param featureType the feature type to use
*/
RevFeatureTypeImpl(@NonNull ObjectId id, @NonNull FeatureType featureType) {
super(id);
this.featureType = featureType;
}

@Override
public TYPE getType() {
return TYPE.FEATURETYPE;
}

@Override
public FeatureType type() {
return featureType;
}

/**
* @return the list of {@link PropertyDescriptor}s of the feature type
*/
@Override
public ImmutableList<PropertyDescriptor> descriptors() {
return ImmutableList.copyOf(featureType.getDescriptors());
}

/**
* @return the name of the feature type
*/
@Override
public Name getName() {
return type().getName();
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FeatureType[");
builder.append(getId().toString());
builder.append("; ");
boolean first = true;
for (PropertyDescriptor desc : descriptors()) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(desc.getName().getLocalPart());
builder.append(": ");
builder.append(desc.getType().getBinding().getSimpleName());
}
builder.append(']');
return builder.toString();
}
}
Expand Up @@ -13,6 +13,7 @@
import java.util.ServiceLoader;
import java.util.SortedMap;

import org.eclipse.jdt.annotation.Nullable;
import org.locationtech.geogig.model.Bucket;
import org.locationtech.geogig.model.Node;
import org.locationtech.geogig.model.ObjectId;
Expand Down Expand Up @@ -46,6 +47,11 @@ public class RevObjectFactoryImpl implements RevObjectFactory {
return 0;
}

public @Override @NonNull RevPerson createPerson(@Nullable String name, @Nullable String email,
long timeStamp, int timeZoneOffset) {
return new RevPersonImpl(name, email, timeStamp, timeZoneOffset);
}

public @Override @NonNull RevCommit createCommit(@NonNull ObjectId id, @NonNull ObjectId treeId,
@NonNull List<ObjectId> parents, @NonNull RevPerson author,
@NonNull RevPerson committer, @NonNull String message) {
Expand Down
Expand Up @@ -11,7 +11,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.SortedMap;
import java.util.function.BiConsumer;
Expand All @@ -21,7 +20,6 @@
import org.locationtech.geogig.model.Bucket;
import org.locationtech.geogig.model.Node;
import org.locationtech.geogig.model.ObjectId;
import org.locationtech.geogig.model.RevObjectFactory;
import org.locationtech.geogig.model.RevTree;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -186,16 +184,6 @@ public ImmutableSortedMap<Integer, Bucket> buckets() {
return ImmutableSortedMap.of();
}

/**
* @deprecated user {@link RevObjectFactory#createTree}
*/
@Deprecated
public static RevTree create(final ObjectId id, final long size, final int childTreeCount,
@Nullable List<Node> trees, @Nullable List<Node> features,
@Nullable SortedMap<Integer, Bucket> buckets) {
return RevTreeBuilder.create(id, size, childTreeCount, trees, features, buckets);
}

@Override
public String toString() {
final int nSubtrees = treesSize();
Expand Down
Expand Up @@ -6,7 +6,9 @@
*
* Contributors:
* Gabriel Roldan - initial implementation
*
*/

/**
* This package encloses the GeoGig revision graph object model, comprised of a set of abstractions
* that denote everything that's stored in a GeoGig repository in order to implement a
* <a href="https://en.wikipedia.org/wiki/Distributed_version_control"> distributed revision control
Expand Down
Expand Up @@ -9,9 +9,11 @@
*/
package org.locationtech.geogig.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.junit.Assert.fail;

import java.util.Collections;

import org.junit.Test;

public class RevObjectTest {
Expand All @@ -35,7 +37,15 @@ public void testTypeValues() {

@Test
public void testNaturalOrder() {
assertEquals(0, RevObject.NATURAL_ORDER.compare(RevTree.EMPTY, RevTree.EMPTY));
assertEquals(0, RevTree.EMPTY.compareTo(RevTree.EMPTY));
ObjectId oId1 = ObjectId.valueOf("abc123000000000000001234567890abcdef0001");
ObjectId oId2 = ObjectId.valueOf("abc123000000000000001234567890abcdef0002");
RevFeature f1 = RevObjectFactory.defaultInstance().createFeature(oId1,
Collections.singletonList("1"));
RevFeature f2 = RevObjectFactory.defaultInstance().createFeature(oId2,
Collections.singletonList("2"));
assertTrue(f1.compareTo(f2) < 0);
assertTrue(f2.compareTo(f1) > 0);
}

@Test
Expand Down
Expand Up @@ -107,37 +107,5 @@ static RevTree build(final long size, final int childTreeCount, @Nullable List<N
return RevObjectFactory.defaultInstance().createTree(id, size, childTreeCount, buckets);
}

/**
* Creates a tree with the given id and contents, no questions asked.
* <p>
* Be careful when using this method instead of {@link #build()}. {@link #build()} will compute
* the appropriate id for the tree given its contents as mandated by {@link HashObject}, whilst
* this method will create the tree as given, even if the id is not the one that would result
* from properly computing it.
*
* @param id
* @param size
* @param childTreeCount
* @param trees
* @param features
* @param buckets
* @return
* @deprecated use {@link RevObjectFactory#createTree} (
* {@link RevObjectFactory#defaultInstance()})
*/
static RevTree create(final ObjectId id, final long size, final int childTreeCount,
@Nullable List<Node> trees, @Nullable List<Node> features,
@Nullable SortedMap<Integer, Bucket> buckets) {

trees = trees == null ? Collections.emptyList() : trees;
features = features == null ? Collections.emptyList() : features;
buckets = buckets == null ? Collections.emptySortedMap() : buckets;

if (buckets.isEmpty()) {
return RevObjectFactory.defaultInstance().createTree(id, size, trees, features);
}
return RevObjectFactory.defaultInstance().createTree(id, size, childTreeCount, buckets);
}

public int getDepth();
}

0 comments on commit 86985d5

Please sign in to comment.