You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/04/21 22:48:38 UTC
[3/5] incubator-tinkerpop git commit: GET, CREATE,
and GET_OR_CREATE working solid. All tests pass now.
GET, CREATE, and GET_OR_CREATE working solid. All tests pass now.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a3381b3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a3381b3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a3381b3d
Branch: refs/heads/master
Commit: a3381b3dd32192cfa398d895da2ec6aa0a04d349
Parents: 3545da8
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Apr 21 12:57:40 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Apr 21 12:57:40 2015 -0600
----------------------------------------------------------------------
.../traverser/util/AbstractPathTraverser.java | 11 +-
.../traverser/util/AbstractTraverser.java | 11 +-
.../traverser/util/EmptyTraverser.java | 5 -
.../gremlin/structure/util/Attachable.java | 181 +++++++++++--------
.../structure/util/detached/DetachedEdge.java | 38 ----
.../util/detached/DetachedElement.java | 2 +-
.../structure/util/detached/DetachedPath.java | 2 +-
.../util/detached/DetachedProperty.java | 26 +--
.../structure/util/detached/DetachedVertex.java | 34 ----
.../util/detached/DetachedVertexProperty.java | 23 +--
.../structure/util/reference/ReferenceEdge.java | 19 --
.../util/reference/ReferenceElement.java | 2 +-
.../structure/util/reference/ReferencePath.java | 2 +-
.../util/reference/ReferenceProperty.java | 25 +--
.../util/reference/ReferenceVertex.java | 19 --
.../util/reference/ReferenceVertexProperty.java | 32 +---
.../gremlin/structure/util/star/StarGraph.java | 2 +-
.../util/detached/DetachedPropertyTest.java | 4 +-
.../detached/DetachedVertexPropertyTest.java | 4 +-
.../reference/ReferenceVertexPropertyTest.java | 4 +-
20 files changed, 134 insertions(+), 312 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractPathTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractPathTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractPathTraverser.java
index 73a52de..060e912 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractPathTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractPathTraverser.java
@@ -147,16 +147,13 @@ public abstract class AbstractPathTraverser<T> implements Traverser<T>, Traverse
}
@Override
- public T attach(final Vertex vertex, final Method method) {
- if (this.t instanceof Attachable && !(((Attachable) this.t).getBase() instanceof Path))
- this.t = ((Attachable<T>) this.t).attach(vertex, method);
+ public T attach(final Vertex hostVertex, final Method method) {
+ // you do not want to attach a path because it will reference graph objects not at the current vertex
+ if (this.t instanceof Attachable && !(((Attachable) this.t).get() instanceof Path))
+ this.t = ((Attachable<T>) this.t).attach(hostVertex, method);
return this.t;
}
- public T getBase() {
- return this.get();
- }
-
/////////////////
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
index 1420905..de94701 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
@@ -26,9 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyPath;
import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversalSideEffects;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.Attachable;
-import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceElement;
import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
-import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceProperty;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -110,9 +108,9 @@ public abstract class AbstractTraverser<T> implements Traverser<T>, Traverser.Ad
@Override
public T attach(final Vertex hostVertex, final Method method) {
- if(this.t instanceof Attachable && !(((Attachable) this.t).getBase() instanceof Path))
- this.t = (T) method.apply((Attachable)this.t,hostVertex);
// you do not want to attach a path because it will reference graph objects not at the current vertex
+ if (this.t instanceof Attachable && !(((Attachable) this.t).get() instanceof Path))
+ this.t = ((Attachable<T>) this.t).attach(hostVertex, method);
return this.t;
}
@@ -133,11 +131,6 @@ public abstract class AbstractTraverser<T> implements Traverser<T>, Traverser.Ad
}
@Override
- public T getBase() {
- return this.t;
- }
-
- @Override
public <S> S sack() {
throw new UnsupportedOperationException("This traverser does not support sacks: " + this.getClass().getCanonicalName());
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
index 7d843fd..0256956 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
@@ -101,11 +101,6 @@ public final class EmptyTraverser<T> implements Traverser<T>, Traverser.Admin<T>
}
@Override
- public T getBase() {
- return null;
- }
-
- @Override
public <S> S sack() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
index 65bd610..7ec5417 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
@@ -38,42 +38,60 @@ import java.util.function.BiFunction;
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public interface Attachable<T> {
+
+ public T get();
+
+ public default T attach(final Vertex hostVertex, final Method method) throws IllegalStateException {
+ return (T) method.apply(this, hostVertex);
+ }
+
+ public default T attach(final Graph hostGraph, final Method method) throws IllegalStateException {
+ return (T) method.apply(this, hostGraph);
+ }
+
public enum Method implements BiFunction<Attachable, Object, Object> {
GET {
@Override
public Object apply(final Attachable attachable, final Object hostVertexOrGraph) {
- final Object base = attachable.getBase();
+ final Object base = attachable.get();
if (base instanceof Vertex) {
final Optional<Vertex> optional = hostVertexOrGraph instanceof Graph ?
Method.getVertex(attachable, (Graph) hostVertexOrGraph) :
Method.getVertex(attachable, (Vertex) hostVertexOrGraph);
- return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+ return optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ?
+ Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) :
+ Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph));
} else if (base instanceof Edge) {
final Optional<Edge> optional = hostVertexOrGraph instanceof Graph ?
Method.getEdge(attachable, (Graph) hostVertexOrGraph) :
Method.getEdge(attachable, (Vertex) hostVertexOrGraph);
- return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+ return optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ?
+ Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) :
+ Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph));
} else if (base instanceof VertexProperty) {
final Optional<VertexProperty> optional = hostVertexOrGraph instanceof Graph ?
Method.getVertexProperty(attachable, (Graph) hostVertexOrGraph) :
Method.getVertexProperty(attachable, (Vertex) hostVertexOrGraph);
- return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
+ return optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ?
+ Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) :
+ Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph));
} else if (base instanceof Property) {
final Optional<Property> optional = hostVertexOrGraph instanceof Graph ?
Method.getProperty(attachable, (Graph) hostVertexOrGraph) :
Method.getProperty(attachable, (Vertex) hostVertexOrGraph);
- return optional.orElseThrow(() -> new IllegalStateException("Can not get the following attachable from " + hostVertexOrGraph + ": " + attachable));
- } else {
- throw new IllegalArgumentException("The attachable must contain an graph object");
- }
+ return optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ?
+ Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) :
+ Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph));
+ } else
+ throw Attachable.Exceptions.providedAttachableMustContainAGraphObject(attachable);
}
},
CREATE {
@Override
public Object apply(final Attachable attachable, final Object hostVertexOrGraph) {
- final Object base = attachable.getBase();
+ final Object base = attachable.get();
if (base instanceof Vertex) {
return hostVertexOrGraph instanceof Graph ?
Method.createVertex(attachable, (Graph) hostVertexOrGraph) :
@@ -90,30 +108,68 @@ public interface Attachable<T> {
return hostVertexOrGraph instanceof Graph ?
Method.createProperty(attachable, (Graph) hostVertexOrGraph) :
Method.createProperty(attachable, (Vertex) hostVertexOrGraph);
- } else {
- throw new IllegalArgumentException("The attachable must contain an graph object");
- }
+ } else
+ throw Attachable.Exceptions.providedAttachableMustContainAGraphObject(attachable);
+ }
+ },
+
+ GET_OR_CREATE {
+ @Override
+ public Object apply(final Attachable attachable, final Object hostVertexOrGraph) {
+ final Object base = attachable.get();
+ if (base instanceof Vertex) {
+ return (hostVertexOrGraph instanceof Graph ?
+ Method.getVertex(attachable, (Graph) hostVertexOrGraph) :
+ Method.getVertex(attachable, (Vertex) hostVertexOrGraph))
+ .orElse(hostVertexOrGraph instanceof Graph ?
+ Method.createVertex(attachable, (Graph) hostVertexOrGraph) :
+ Method.createVertex(attachable, (Vertex) hostVertexOrGraph));
+ } else if (base instanceof Edge) {
+ return (hostVertexOrGraph instanceof Graph ?
+ Method.getEdge(attachable, (Graph) hostVertexOrGraph) :
+ Method.getEdge(attachable, (Vertex) hostVertexOrGraph))
+ .orElse(hostVertexOrGraph instanceof Graph ?
+ Method.createEdge(attachable, (Graph) hostVertexOrGraph) :
+ Method.createEdge(attachable, (Vertex) hostVertexOrGraph));
+ } else if (base instanceof VertexProperty) {
+ return (hostVertexOrGraph instanceof Graph ?
+ Method.getVertexProperty(attachable, (Graph) hostVertexOrGraph) :
+ Method.getVertexProperty(attachable, (Vertex) hostVertexOrGraph))
+ .orElse(hostVertexOrGraph instanceof Graph ?
+ Method.createVertexProperty(attachable, (Graph) hostVertexOrGraph) :
+ Method.createVertexProperty(attachable, (Vertex) hostVertexOrGraph));
+ } else if (base instanceof Property) {
+ return (hostVertexOrGraph instanceof Graph ?
+ Method.getProperty(attachable, (Graph) hostVertexOrGraph) :
+ Method.getProperty(attachable, (Vertex) hostVertexOrGraph))
+ .orElse(hostVertexOrGraph instanceof Graph ?
+ Method.createProperty(attachable, (Graph) hostVertexOrGraph) :
+ Method.createProperty(attachable, (Vertex) hostVertexOrGraph));
+ } else
+ throw Attachable.Exceptions.providedAttachableMustContainAGraphObject(attachable);
}
};
///////////////////
+ ///// GET HELPER METHODS
+
public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) {
- final Iterator<Vertex> vertexIterator = hostGraph.vertices(attachableVertex.getBase().id());
+ final Iterator<Vertex> vertexIterator = hostGraph.vertices(attachableVertex.get().id());
return vertexIterator.hasNext() ? Optional.of(vertexIterator.next()) : Optional.empty();
}
public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Vertex hostVertex) {
- return ElementHelper.areEqual(attachableVertex.getBase(), hostVertex) ? Optional.of(hostVertex) : Optional.empty();
+ return ElementHelper.areEqual(attachableVertex.get(), hostVertex) ? Optional.of(hostVertex) : Optional.empty();
}
public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
- final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.getBase().id());
+ final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id());
return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty();
}
public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
- final Object baseId = attachableEdge.getBase().id();
+ final Object baseId = attachableEdge.get().id();
final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
while (edgeIterator.hasNext()) {
final Edge edge = edgeIterator.next();
@@ -124,7 +180,7 @@ public interface Attachable<T> {
}
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) {
- final VertexProperty baseVertexProperty = attachableVertexProperty.getBase();
+ final VertexProperty baseVertexProperty = attachableVertexProperty.get();
final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id());
if (vertexIterator.hasNext()) {
final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key());
@@ -138,7 +194,7 @@ public interface Attachable<T> {
}
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) {
- final VertexProperty baseVertexProperty = attachableVertexProperty.getBase();
+ final VertexProperty baseVertexProperty = attachableVertexProperty.get();
final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties(baseVertexProperty.key());
while (vertexPropertyIterator.hasNext()) {
final VertexProperty vertexProperty = vertexPropertyIterator.next();
@@ -149,17 +205,19 @@ public interface Attachable<T> {
}
public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) {
- final Property baseProperty = attachableProperty.getBase();
- final Element propertyElement = attachableProperty.getBase().element();
- if (propertyElement instanceof Edge) {
+ final Property baseProperty = attachableProperty.get();
+ final Element propertyElement = attachableProperty.get().element();
+ if (propertyElement instanceof Vertex) {
+ return (Optional) Method.getVertexProperty((Attachable) attachableProperty, hostGraph);
+ } else if (propertyElement instanceof Edge) {
final Iterator<Edge> edgeIterator = hostGraph.edges(propertyElement.id());
- if (edgeIterator.hasNext()) {
+ while (edgeIterator.hasNext()) {
final Property property = edgeIterator.next().property(baseProperty.key());
if (property.isPresent() && property.value().equals(baseProperty.value()))
return Optional.of(property);
}
return Optional.empty();
- } else {
+ } else { // vertex property
final Iterator<Vertex> vertexIterator = hostGraph.vertices(((VertexProperty) propertyElement).element().id());
if (vertexIterator.hasNext()) {
final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties();
@@ -179,17 +237,19 @@ public interface Attachable<T> {
}
public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) {
- final Property baseProperty = attachableProperty.getBase();
- final Element propertyElement = attachableProperty.getBase().element();
- if (propertyElement instanceof Edge) {
+ final Property baseProperty = attachableProperty.get();
+ final Element propertyElement = attachableProperty.get().element();
+ if (propertyElement instanceof Vertex) {
+ return (Optional) Method.getVertexProperty((Attachable) attachableProperty, hostVertex);
+ } else if (propertyElement instanceof Edge) {
final Iterator<Edge> edgeIterator = hostVertex.edges(Direction.OUT);
- if (edgeIterator.hasNext()) {
+ while (edgeIterator.hasNext()) {
final Property property = edgeIterator.next().property(baseProperty.key());
if (property.isPresent() && property.value().equals(baseProperty.value()))
return Optional.of(property);
}
return Optional.empty();
- } else {
+ } else { // vertex property
final Iterator<VertexProperty<Object>> vertexPropertyIterator = hostVertex.properties();
while (vertexPropertyIterator.hasNext()) {
final VertexProperty vertexProperty = vertexPropertyIterator.next();
@@ -205,10 +265,10 @@ public interface Attachable<T> {
}
}
- /////
+ ///// CREATE HELPER METHODS
public static Vertex createVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) {
- final Vertex baseVertex = attachableVertex.getBase();
+ final Vertex baseVertex = attachableVertex.get();
final List<Object> keyValues = new ArrayList<>();
keyValues.add(org.apache.tinkerpop.gremlin.process.traversal.T.id);
keyValues.add(baseVertex.id());
@@ -227,7 +287,7 @@ public interface Attachable<T> {
}
public static Edge createEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
- final Edge baseEdge = attachableEdge.getBase();
+ final Edge baseEdge = attachableEdge.get();
Iterator<Vertex> vertices = hostGraph.vertices(baseEdge.outVertex().id());
final Vertex outV = vertices.hasNext() ? vertices.next() : hostGraph.addVertex(org.apache.tinkerpop.gremlin.process.traversal.T.id, baseEdge.outVertex().id());
vertices = hostGraph.vertices(baseEdge.inVertex().id());
@@ -246,11 +306,11 @@ public interface Attachable<T> {
}
public static Edge createEdge(final Attachable<Edge> attachableEdge, final Vertex hostVertex) {
- return Method.createEdge(attachableEdge, hostVertex.graph());
+ return Method.createEdge(attachableEdge, hostVertex.graph()); // TODO (make local to vertex)
}
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) {
- final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.getBase();
+ final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get();
final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id());
if (vertexIterator.hasNext()) {
final VertexProperty vertexProperty = vertexIterator.next().property(VertexProperty.Cardinality.list, baseVertexProperty.key(), baseVertexProperty.value(), org.apache.tinkerpop.gremlin.process.traversal.T.id, baseVertexProperty.id());
@@ -261,75 +321,38 @@ public interface Attachable<T> {
}
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Vertex hostVertex) {
- final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.getBase();
+ final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get();
final VertexProperty vertexProperty = hostVertex.property(VertexProperty.Cardinality.list, baseVertexProperty.key(), baseVertexProperty.value(), org.apache.tinkerpop.gremlin.process.traversal.T.id, baseVertexProperty.id());
baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value()));
return vertexProperty;
}
public static Property createProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) {
- return null;
+ return null; // TODO: :)
}
public static Property createProperty(final Attachable<Property> attachableProperty, final Vertex hostVertex) {
- return null;
+ return null; // TODO: :)
}
}
- public T getBase();
-
- public T attach(final Vertex hostVertex, final Method method) throws IllegalStateException;
-
- public T attach(final Graph hostGraph, final Method method) throws IllegalStateException;
-
-
public static class Exceptions {
private Exceptions() {
}
- public static IllegalStateException canNotAttachVertexToHostVertex(final Attachable<Vertex> vertex, final Vertex hostVertex) {
- return new IllegalStateException("The provided vertex is not the host vertex: " + vertex + " does not equal " + hostVertex);
- }
-
- public static IllegalStateException canNotAttachVertexToHostGraph(final Attachable<Vertex> vertex, final Graph hostGraph) {
- return new IllegalStateException("The provided vertex could not be found in the host graph: " + vertex + " not in " + hostGraph);
- }
-
- public static IllegalStateException canNotAttachEdgeToHostVertex(final Attachable<Edge> edge, final Vertex hostVertex) {
- return new IllegalStateException("The provided edge is not incident to the host vertex: " + edge + " not incident to " + hostVertex);
- }
-
- public static IllegalStateException canNotAttachEdgeToHostGraph(final Attachable<Edge> edge, final Graph hostGraph) {
- return new IllegalStateException("The provided edge could not be found in the host graph: " + edge + " not in " + hostGraph);
- }
-
- public static IllegalStateException canNotAttachVertexPropertyToHostVertex(final Attachable<VertexProperty> vertexProperty, final Vertex hostVertex) {
- return new IllegalStateException("The provided vertex property is not a property of the host vertex: " + vertexProperty + " not a property of " + hostVertex);
- }
-
- public static IllegalStateException canNotAttachVertexPropertyToHostGraph(final Attachable<VertexProperty> vertexProperty, final Graph hostGraph) {
- return new IllegalStateException("The provided vertex property could not be found in the host graph: " + vertexProperty + " not in " + hostGraph);
+ public static IllegalStateException canNotGetAttachableFromHostVertex(final Attachable<?> attachable, final Vertex hostVertex) {
+ return new IllegalStateException("Can not get the attachable from the host vertex: " + attachable + "-/->" + hostVertex);
}
- public static IllegalStateException canNotAttachPropertyToHostVertex(final Attachable<Property> property, final Vertex hostVertex) {
- return new IllegalStateException("The provided property could not be attached the host vertex: " + property + " not a property in the star of " + hostVertex);
- }
-
- public static IllegalStateException canNotAttachPropertyToHostGraph(final Attachable<Property> property, final Graph hostGraph) {
- return new IllegalStateException("The provided property could not be attached the host graph: " + property + " not in " + hostGraph);
- }
-
- ////
-
- public static IllegalArgumentException illegalMethodOnHostVertex(final Attachable attachable, final Method method, final Vertex hostVertex) {
- return new IllegalArgumentException("The following method on the host vertex is not legal: " + hostVertex + "." + method + "(" + attachable + ")");
+ public static IllegalStateException canNotGetAttachableFromHostGraph(final Attachable<?> attachable, final Graph hostGraph) {
+ return new IllegalStateException("Can not get the attachable from the host vertex: " + attachable + "-/->" + hostGraph);
}
- public static IllegalArgumentException illegalMethodOnHostGraph(final Attachable attachable, final Method method, final Graph hostGraph) {
- return new IllegalArgumentException("The following method on the host graph is not legal: " + hostGraph + "." + method + "(" + attachable + ")");
+ public static IllegalArgumentException providedAttachableMustContainAGraphObject(final Attachable<?> attachable) {
+ return new IllegalArgumentException("The provided attachable must contain a graph object: " + attachable);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
index cffa268..02c2fd0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedEdge.java
@@ -85,50 +85,12 @@ public class DetachedEdge extends DetachedElement<Edge> implements Edge {
}
}
-
@Override
public String toString() {
return StringFactory.edgeString(this);
}
@Override
- public Edge attach(final Vertex hostVertex, final Method method) {
- return (Edge) method.apply(this, hostVertex);
- /*final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT, this.label), edge -> edge.equals(this));
- if (!edges.hasNext())
- throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
- return edges.next();*/
- }
-
- @Override
- public Edge attach(final Graph hostGraph, final Method method) {
- return (Edge) method.apply(this, hostGraph);
- /*final Iterator<Edge> edges = hostGraph.edges(this.id);
- if (!edges.hasNext())
- throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
- return edges.next();*/
- }
-
- /*public static Edge addTo(final Graph graph, final DetachedEdge detachedEdge) {
- Iterator<Vertex> vertices = graph.vertices(detachedEdge.outVertex.id());
- final Vertex outV = vertices.hasNext() ? vertices.next() : graph.addVertex(T.id, detachedEdge.outVertex.id());
- vertices = graph.vertices(detachedEdge.inVertex.id());
- final Vertex inV = vertices.hasNext() ? vertices.next() : graph.addVertex(T.id, detachedEdge.inVertex.id());
- if (ElementHelper.areEqual(outV, inV)) {
- final Iterator<Edge> itty = outV.edges(Direction.OUT, detachedEdge.label());
- while (itty.hasNext()) {
- final Edge e = itty.next();
- if (ElementHelper.areEqual(detachedEdge, e))
- return e;
- }
- }
- final Edge e = outV.addEdge(detachedEdge.label(), inV, T.id, detachedEdge.id());
- if (null != detachedEdge.properties)
- detachedEdge.properties.entrySet().forEach(kv -> kv.getValue().forEach(p -> e.<Object>property(kv.getKey(), p.value())));
- return e;
- }*/
-
- @Override
public Vertex inVertex() {
return this.inVertex;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
index 1da69f3..b748633 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
@@ -97,7 +97,7 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
(Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).flatMap(entry -> entry.getValue().stream()).iterator();
}
- public E getBase() {
+ public E get() {
return (E) this;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
index 9d971d9..8610922 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
@@ -35,7 +35,7 @@ public class DetachedPath extends MutablePath implements Attachable<Path> {
}
- public Path getBase() {
+ public Path get() {
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
index a4d4a0c..6da0e4a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedProperty.java
@@ -32,7 +32,7 @@ import java.io.Serializable;
* @author Stephen Mallette (http://stephen.genoprime.com)
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class DetachedProperty<V> implements Property, Serializable, Attachable<Property> {
+public class DetachedProperty<V> implements Property<V>, Serializable, Attachable<Property<V>> {
private String key;
private V value;
@@ -53,7 +53,7 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
this.element = DetachedFactory.detach(element, false);
}
- public Property getBase() {
+ public Property<V> get() {
return this;
}
@@ -97,26 +97,4 @@ public class DetachedProperty<V> implements Property, Serializable, Attachable<P
public int hashCode() {
return ElementHelper.hashCode(this);
}
-
- @Override
- public Property<V> attach(final Vertex hostVertex, final Method method) {
- return (Property<V>) method.apply(this, hostVertex);
- /*final Element element = (Element) this.element.attach(hostVertex);
- final Property<V> property = element.property(this.key);
- if (property.isPresent() && property.value().equals(this.value))
- return property;
- else
- throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex);*/
- }
-
- @Override
- public Property<V> attach(final Graph hostGraph, final Method method) {
- return (Property<V>) method.apply(this, method);
- /*final Element hostElement = (Element) this.element.attach(hostGraph);
- final Property<V> property = hostElement.property(this.key);
- if (property.isPresent() && property.value().equals(this.value))
- return property;
- else
- throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph); */
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
index f0b9b75..3a13d70 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertex.java
@@ -125,40 +125,6 @@ public class DetachedVertex extends DetachedElement<Vertex> implements Vertex {
}
@Override
- public Vertex attach(final Vertex hostVertex, final Method method) {
- return (Vertex) method.apply(this, hostVertex);
- }
-
- @Override
- public Vertex attach(final Graph hostGraph, final Method method) {
- return (Vertex) method.apply(this, hostGraph);
- }
-
- /*public static Vertex addTo(final Graph graph, final DetachedVertex detachedVertex) {
- final Vertex vertex = graph.addVertex(T.id, detachedVertex.id(), T.label, detachedVertex.label());
- if (null != detachedVertex.properties) {
- detachedVertex.properties.values().forEach(list -> {
- list.forEach(dVertexProperty -> {
- final DetachedVertexProperty<?> detachedVertexProperty = (DetachedVertexProperty) dVertexProperty;
- if (null != detachedVertexProperty.properties) {
- final List<Object> metaProperties = new ArrayList<>();
- detachedVertexProperty.properties().forEachRemaining(detachedMetaProperty -> {
- metaProperties.add(detachedMetaProperty.key());
- metaProperties.add(detachedMetaProperty.value());
- });
- metaProperties.add(T.id);
- metaProperties.add(detachedVertexProperty.id());
- vertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value(), metaProperties.toArray());
- } else {
- vertex.property(VertexProperty.Cardinality.list, detachedVertexProperty.key(), detachedVertexProperty.value(), T.id, detachedVertexProperty.id());
- }
- });
- });
- }
- return vertex;
- } */
-
- @Override
public <V> Iterator<VertexProperty<V>> properties(final String... propertyKeys) {
return (Iterator) super.properties(propertyKeys);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
index 700f0d5..f76cfd8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexProperty.java
@@ -34,7 +34,7 @@ import java.util.Map;
* @author Marko A. Rodriguez (http://markorodriguez.com)
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public class DetachedVertexProperty<V> extends DetachedElement<Property<V>> implements VertexProperty<V> {
+public class DetachedVertexProperty<V> extends DetachedElement<VertexProperty<V>> implements VertexProperty<V> {
protected V value;
protected transient DetachedVertex vertex;
@@ -109,28 +109,7 @@ public class DetachedVertexProperty<V> extends DetachedElement<Property<V>> impl
}
@Override
- public VertexProperty<V> attach(final Vertex hostVertex, final Method method) {
- return (VertexProperty<V>) method.apply(this, hostVertex);
- /*final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(this.label), vp -> ElementHelper.areEqual(this, vp));
- if (!vertexPropertyIterator.hasNext())
- throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex((Attachable) this, hostVertex);
- return vertexPropertyIterator.next(); */
- }
-
- @Override
- public VertexProperty<V> attach(final Graph hostGraph, final Method method) {
- return (VertexProperty<V>) method.apply(this, hostGraph);
- //return this.attach(this.vertex.attach(hostGraph));
- }
-
- @Override
public <U> Iterator<Property<U>> properties(final String... propertyKeys) {
return (Iterator) super.properties(propertyKeys);
}
-
- /*public static <V> VertexProperty<V> addTo(final Vertex vertex, final DetachedVertexProperty<V> detachedVertexProperty) {
- final VertexProperty<V> vertexProperty = vertex.property(VertexProperty.Cardinality.single, detachedVertexProperty.key(), detachedVertexProperty.value()); // TODO: this isn't right, is it? (need to remove views from Spark/Giraph)
- detachedVertexProperty.properties().forEachRemaining(property -> vertexProperty.property(property.key(), property.value()));
- return vertexProperty;
- }*/
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
index 2788d3a..80f3bb3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceEdge.java
@@ -24,7 +24,6 @@ package org.apache.tinkerpop.gremlin.structure.util.reference;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -45,24 +44,6 @@ public class ReferenceEdge extends ReferenceElement<Edge> implements Edge {
}
@Override
- public Edge attach(final Vertex hostVertex, final Method method) {
- return (Edge) method.apply(this, hostVertex);
- /* final Iterator<Edge> edges = IteratorUtils.filter(hostVertex.edges(Direction.OUT), edge -> edge.id().equals(this.id));
- if (!edges.hasNext())
- throw Attachable.Exceptions.canNotAttachEdgeToHostVertex(this, hostVertex);
- return edges.next(); */
- }
-
- @Override
- public Edge attach(final Graph hostGraph, final Method method) {
- return (Edge) method.apply(this, hostGraph);
- /*final Iterator<Edge> edges = hostGraph.edges(this.id);
- if (!edges.hasNext())
- throw Attachable.Exceptions.canNotAttachEdgeToHostGraph(this, hostGraph);
- return edges.next(); */
- }
-
- @Override
public <V> Property<V> property(final String key, final V value) {
throw Element.Exceptions.propertyAdditionNotSupported();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
index 0bcf37c..c7b68b7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceElement.java
@@ -72,7 +72,7 @@ public abstract class ReferenceElement<E extends Element> implements Element, Se
return ElementHelper.areEqual(this, other);
}
- public E getBase() {
+ public E get() {
return (E) this;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
index b52b93d..7b85c17 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferencePath.java
@@ -38,7 +38,7 @@ public class ReferencePath extends MutablePath implements Attachable<Path> {
}
- public Path getBase() {
+ public Path get() {
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
index c034629..d1e8326 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceProperty.java
@@ -35,7 +35,7 @@ import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceProperty<V> implements Attachable<Property>, Serializable, Property<V> {
+public class ReferenceProperty<V> implements Attachable<Property<V>>, Serializable, Property<V> {
private ReferenceElement<?> element;
private String key;
@@ -45,7 +45,7 @@ public class ReferenceProperty<V> implements Attachable<Property>, Serializable,
}
- public Property getBase() {
+ public Property<V> get() {
return this;
}
@@ -56,27 +56,6 @@ public class ReferenceProperty<V> implements Attachable<Property>, Serializable,
}
@Override
- public Property<V> attach(final Vertex hostVertex, final Method method) throws IllegalStateException {
- return (Property<V>) method.apply(this,hostVertex);
- /*final Property<V> property = this.element.attach(hostVertex).property(this.key);
- if (property.isPresent() && property.value().equals(this.value))
- return property;
- else
- throw Attachable.Exceptions.canNotAttachPropertyToHostVertex(this, hostVertex); */
- }
-
- @Override
- public Property<V> attach(final Graph hostGraph, final Method method) throws IllegalStateException {
- return (Property<V>) method.apply(this,hostGraph);
-
- /*final Property<V> property = this.element.attach(hostGraph).property(this.key);
- if (property.isPresent() && property.value().equals(this.value))
- return property;
- else
- throw Attachable.Exceptions.canNotAttachPropertyToHostGraph(this, hostGraph);*/
- }
-
- @Override
public int hashCode() {
return ElementHelper.hashCode(this);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
index 775305d..af9dce1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertex.java
@@ -46,25 +46,6 @@ public class ReferenceVertex extends ReferenceElement<Vertex> implements Vertex
}
@Override
- public Vertex attach(final Vertex hostVertex, final Method method) {
- return (Vertex) method.apply(this, hostVertex);
- /*if (ElementHelper.areEqual(this,hostVertex))
- return hostVertex;
- else
- throw Attachable.Exceptions.canNotAttachVertexToHostVertex(this, hostVertex); */
- }
-
- @Override
- public Vertex attach(final Graph hostGraph, final Method method) {
- return (Vertex) method.apply(this, hostGraph);
- /*final Iterator<Vertex> iterator = hostGraph.vertices(this.id);
- if (iterator.hasNext())
- return iterator.next();
- else
- throw Attachable.Exceptions.canNotAttachVertexToHostGraph(this, hostGraph); */
- }
-
- @Override
public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
throw Vertex.Exceptions.edgeAdditionsNotSupported();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
index 8898e75..326708c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexProperty.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.Collections;
import java.util.Iterator;
@@ -34,49 +35,36 @@ import java.util.NoSuchElementException;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty> implements VertexProperty<V> {
+public class ReferenceVertexProperty<V> extends ReferenceElement<VertexProperty<V>> implements VertexProperty<V> {
private ReferenceVertex vertex;
+ private String key;
+ private V value;
private ReferenceVertexProperty() {
}
- public ReferenceVertexProperty(final VertexProperty vertexProperty) {
+ public ReferenceVertexProperty(final VertexProperty<V> vertexProperty) {
super(vertexProperty);
this.vertex = ReferenceFactory.detach(vertexProperty.element());
- }
-
- @Override
- public VertexProperty<V> attach(final Vertex hostVertex, final Method method) {
- return (VertexProperty<V>) method.apply(this, hostVertex);
- /*if (!hostVertex.equals(this.vertex))
- throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
- final Iterator<VertexProperty<V>> vertexPropertyIterator = IteratorUtils.filter(hostVertex.<V>properties(), vp -> vp.id().equals(this.id));
- if (!vertexPropertyIterator.hasNext())
- throw Attachable.Exceptions.canNotAttachVertexPropertyToHostVertex(this, hostVertex);
- return vertexPropertyIterator.next();*/
- }
-
- @Override
- public VertexProperty<V> attach(final Graph hostGraph, final Method method) {
- return (VertexProperty<V>) method.apply(this, hostGraph);
- // return this.attach(this.vertex.attach(hostGraph));
+ this.key = vertexProperty.key();
+ this.value = vertexProperty.value();
}
@Override
public String toString() {
- return "vp[" + this.id + "]";
+ return StringFactory.propertyString(this);
}
@Override
public String key() {
- return EMPTY_STRING;
+ return this.key;
}
@Override
public V value() throws NoSuchElementException {
- return null;
+ return this.value;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index ccfe7d9..57d5bb9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -247,7 +247,7 @@ public final class StarGraph implements Graph {
super(id, label);
}
- public Vertex getBase() {
+ public Vertex get() {
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
index 674bafc..2fbb5e6 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPropertyTest.java
@@ -72,7 +72,7 @@ public class DetachedPropertyTest extends AbstractGremlinTest {
public void shouldAttachToGraph() {
final Edge e = g.E(convertToEdgeId("josh", "created", "lop")).next();
final Property toDetach = e.properties("weight").next();
- final DetachedProperty detachedProperty = DetachedFactory.detach(toDetach);
+ final DetachedProperty<?> detachedProperty = DetachedFactory.detach(toDetach);
final Property attached = detachedProperty.attach(graph, Attachable.Method.GET);
assertEquals(toDetach, attached);
@@ -84,7 +84,7 @@ public class DetachedPropertyTest extends AbstractGremlinTest {
public void shouldAttachToVertex() {
final Edge e = g.E(convertToEdgeId("josh", "created", "lop")).next();
final Property toDetach = e.property("weight");
- final DetachedProperty detachedProperty = DetachedFactory.detach(toDetach);
+ final DetachedProperty<?> detachedProperty = DetachedFactory.detach(toDetach);
final Property attached = detachedProperty.attach(e.outVertex(), Attachable.Method.GET);
assertEquals(toDetach, attached);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
index a363373..78d1a6b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedVertexPropertyTest.java
@@ -127,7 +127,7 @@ public class DetachedVertexPropertyTest extends AbstractGremlinTest {
public void shouldAttachToGraph() {
final Vertex v = graph.addVertex();
final VertexProperty toDetach = v.property(VertexProperty.Cardinality.single, "test", "this");
- final DetachedVertexProperty detached = DetachedFactory.detach(toDetach, true);
+ final DetachedVertexProperty<?> detached = DetachedFactory.detach(toDetach, true);
final VertexProperty attached = detached.attach(graph, Attachable.Method.GET);
assertEquals(toDetach, attached);
@@ -139,7 +139,7 @@ public class DetachedVertexPropertyTest extends AbstractGremlinTest {
public void shouldAttachToVertex() {
final Vertex v = graph.addVertex();
final VertexProperty toDetach = v.property(VertexProperty.Cardinality.single, "test", "this");
- final DetachedVertexProperty detached = DetachedFactory.detach(toDetach, true);
+ final DetachedVertexProperty<?> detached = DetachedFactory.detach(toDetach, true);
final VertexProperty attached = detached.attach(v, Attachable.Method.GET);
assertEquals(toDetach, attached);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a3381b3d/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
index 4f6e17f..d8d0086 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/reference/ReferenceVertexPropertyTest.java
@@ -80,7 +80,7 @@ public class ReferenceVertexPropertyTest extends AbstractGremlinTest {
public void shouldAttachToGraph() {
final Vertex v = graph.addVertex();
final VertexProperty toReference = v.property(VertexProperty.Cardinality.single, "test", "this");
- final ReferenceVertexProperty rvp = ReferenceFactory.detach(toReference);
+ final ReferenceVertexProperty<?> rvp = ReferenceFactory.detach(toReference);
final VertexProperty referenced = rvp.attach(graph, Attachable.Method.GET);
assertEquals(toReference, referenced);
@@ -92,7 +92,7 @@ public class ReferenceVertexPropertyTest extends AbstractGremlinTest {
public void shouldAttachToVertex() {
final Vertex v = graph.addVertex();
final VertexProperty toReference = v.property(VertexProperty.Cardinality.single, "test", "this");
- final ReferenceVertexProperty rvp = ReferenceFactory.detach(toReference);
+ final ReferenceVertexProperty<?> rvp = ReferenceFactory.detach(toReference);
final VertexProperty referenced = rvp.attach(v, Attachable.Method.GET);
assertEquals(toReference, referenced);