You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/11 19:26:19 UTC

[03/50] [abbrv] incubator-tinkerpop git commit: got rid of Graph.V() and Graph.E().... more test cleanup required.

got rid of Graph.V() and Graph.E().... more test cleanup required.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/2e214fb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/2e214fb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/2e214fb5

Branch: refs/heads/master
Commit: 2e214fb55e40f613b2534a4a06d1d15be22ced4d
Parents: 03ea120
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Mar 9 14:57:22 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Mar 9 14:57:22 2015 -0600

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/Graph.java      | 23 ----------------
 .../structure/io/graphml/GraphMLWriter.java     | 28 +++++++++++++++-----
 .../structure/io/graphson/GraphSONGraph.java    |  4 +--
 .../gremlin/structure/strategy/IdStrategy.java  |  8 +++---
 .../structure/strategy/StrategyGraph.java       | 19 -------------
 .../structure/util/batch/BatchGraph.java        | 15 +++--------
 .../structure/util/empty/EmptyGraph.java        | 10 -------
 .../tinkerpop/gremlin/structure/IoTest.java     |  6 ++---
 8 files changed, 35 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 92e8db5..5ac6a27 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -133,29 +133,6 @@ public interface Graph extends AutoCloseable {
     }
 
     /**
-     * Starts a {@link GraphTraversal} over the vertices in the graph.
-     * If vertexIds are provided, then the traversal starts at those vertices, else all vertices in the graph.
-     *
-     * @param vertexIds the ids of the vertices to get (if none are provided, get all vertices)
-     * @return a graph traversal over the vertices of the graph
-     */
-    public default GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
-        return this.traversal().V(vertexIds);
-    }
-
-    /**
-     * Starts a {@link GraphTraversal} over the edges in the graph.
-     * If edgeIds are provided, then the traversal starts at those edges, else all edges in the graph.
-     *
-     * @param edgeIds the ids of the edges to get (if none are provided, get all edges)
-     * @return a graph traversal over the edges of the graph
-     */
-    public default GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
-        return this.traversal().E(edgeIds);
-    }
-
-
-    /**
      * Declare the {@link GraphComputer} to use for OLAP operations on the graph.
      * If the graph does not support graph computer then an {@link java.lang.UnsupportedOperationException} is thrown.
      *

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
index 1d61008..036ac1d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphml/GraphMLWriter.java
@@ -19,7 +19,11 @@
 package org.apache.tinkerpop.gremlin.structure.io.graphml;
 
 import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.structure.*;
+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.Vertex;
 import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
 import org.apache.tinkerpop.gremlin.structure.util.Comparators;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -30,7 +34,14 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
 
 /**
  * GraphMLWriter writes a Graph to a GraphML OutputStream. Note that this format is lossy, in the sense that data
@@ -267,8 +278,9 @@ public class GraphMLWriter implements GraphWriter {
         final Iterable<Vertex> vertices;
         if (normalize) {
             vertices = new ArrayList<>();
-            for (Vertex v : graph.V().toList()) {
-                ((Collection<Vertex>) vertices).add(v);
+            final Iterator<Vertex> vertexIterator = graph.vertices();
+            while (vertexIterator.hasNext()) {
+                ((Collection<Vertex>) vertices).add(vertexIterator.next());
             }
             Collections.sort((List<Vertex>) vertices, Comparators.ELEMENT_COMPARATOR);
         } else
@@ -314,7 +326,9 @@ public class GraphMLWriter implements GraphWriter {
 
     private static Map<String, String> determineVertexTypes(final Graph graph) {
         final Map<String, String> vertexKeyTypes = new HashMap<>();
-        for (Vertex vertex : graph.V().toList()) {
+        final Iterator<Vertex> vertices = graph.vertices();
+        while (vertices.hasNext()) {
+            final Vertex vertex = vertices.next();
             for (String key : vertex.keys()) {
                 if (!vertexKeyTypes.containsKey(key)) {
                     vertexKeyTypes.put(key, GraphMLWriter.getStringType(vertex.property(key).value()));
@@ -327,7 +341,9 @@ public class GraphMLWriter implements GraphWriter {
 
     private static Map<String, String> determineEdgeTypes(final Graph graph) {
         final Map<String, String> edgeKeyTypes = new HashMap<>();
-        for (Edge edge : graph.E().toList()) {
+        final Iterator<Edge> edges = graph.edges();
+        while (edges.hasNext()) {
+            final Edge edge = edges.next();
             for (String key : edge.keys()) {
                 if (!edgeKeyTypes.containsKey(key))
                     edgeKeyTypes.put(key, GraphMLWriter.getStringType(edge.property(key).value()));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONGraph.java
index 24d5e68..4756c92 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONGraph.java
@@ -72,14 +72,14 @@ class GraphSONGraph {
 
             jsonGenerator.writeArrayFieldStart(GraphSONTokens.VERTICES);
             if (normalize)
-                g.V().order().by(Comparators.VERTEX_COMPARATOR).forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
+                g.traversal().V().order().by(Comparators.VERTEX_COMPARATOR).forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
             else
                 g.vertices().forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
             jsonGenerator.writeEndArray();
 
             jsonGenerator.writeArrayFieldStart(GraphSONTokens.EDGES);
             if (normalize)
-                g.E().order().by(Comparators.EDGE_COMPARATOR).forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
+                g.traversal().E().order().by(Comparators.EDGE_COMPARATOR).forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
             else
                 g.vertices().forEachRemaining(FunctionUtils.wrapConsumer(jsonGenerator::writeObject));
             jsonGenerator.writeEndArray();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategy.java
index 1d3379e..7f4d2b0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/IdStrategy.java
@@ -98,22 +98,22 @@ public final class IdStrategy implements GraphStrategy {
 
     @Override
     public UnaryOperator<Function<Object[], Iterator<Edge>>> getGraphIteratorsEdgeIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
-        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
+        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().traversal().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
     }
 
     @Override
     public UnaryOperator<Function<Object[], Iterator<Vertex>>> getGraphIteratorsVertexIteratorStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
-        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
+        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().traversal().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
     }
 
     @Override
     public UnaryOperator<Function<Object[], GraphTraversal<Edge, Edge>>> getGraphEStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
-        return supportsEdgeId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
+        return supportsEdgeId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().traversal().E().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
     }
 
     @Override
     public UnaryOperator<Function<Object[], GraphTraversal<Vertex, Vertex>>> getGraphVStrategy(final StrategyContext<StrategyGraph> ctx, final GraphStrategy composingStrategy) {
-        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
+        return supportsVertexId ? (f) -> (ids) -> ctx.getStrategyGraph().getBaseGraph().traversal().V().has(idKey, Contains.within, Arrays.asList(ids)) : UnaryOperator.identity();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/StrategyGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/StrategyGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/StrategyGraph.java
index fbdd841..6056242 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/StrategyGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/strategy/StrategyGraph.java
@@ -99,25 +99,6 @@ public class StrategyGraph implements Graph, StrategyWrapped, WrappedGraph<Graph
     }
 
     @Override
-    public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
-        return this.compose(s -> s.getGraphVStrategy(this.graphContext, this.strategy), this.baseGraph::V).apply(vertexIds).map(vertex -> new StrategyVertex(vertex.get(), this));
-       /* final GraphTraversal<Vertex, Vertex> traversal = new DefaultGraphTraversal<>(this.getClass());
-        return traversal.asAdmin().addStep(new StrategyGraphStep<>(traversal, this, Vertex.class, this.compose(
-                s -> s.getGraphVStrategy(this.graphContext, strategy),
-                this.baseGraph::V).apply(vertexIds))); */
-    }
-
-    @Override
-    public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
-        return this.compose(s -> s.getGraphEStrategy(this.graphContext, this.strategy), this.baseGraph::E).apply(edgeIds).map(edge -> new StrategyEdge(edge.get(), this));
-        /*final GraphTraversal<Edge, Edge> traversal = new DefaultGraphTraversal<>(this.getClass());
-        return traversal.asAdmin().addStep(new StrategyGraphStep<>(traversal, this, Edge.class, this.compose(
-                s -> s.getGraphEStrategy(this.graphContext, strategy),
-                this.baseGraph::E).apply(edgeIds)));*/
-    }
-
-
-    @Override
     public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) {
         return this.baseGraph.compute(graphComputerClass);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/batch/BatchGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
index d6b0159..e1552b4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/batch/BatchGraph.java
@@ -23,7 +23,6 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.process.T;
 import org.apache.tinkerpop.gremlin.process.Traversal;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversal;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
@@ -54,7 +53,6 @@ import java.util.function.Function;
  * That is, BatchGraph only supports the following methods:
  * - {@link #addVertex(Object...)} for adding vertices
  * - {@link Vertex#addEdge(String, org.apache.tinkerpop.gremlin.structure.Vertex, Object...)} for adding edges
- * - {@link #V(Object...)} to be used when adding edges
  * - Property getter, setter and removal methods for vertices and edges.
  * <br />
  * An important limitation of BatchGraph is that edge properties can only be set immediately after the edge has been added.
@@ -153,7 +151,7 @@ public class BatchGraph<G extends Graph> implements Graph {
         if (internal instanceof Vertex) {
             return (Vertex) internal;
         } else if (internal != null) { //its an internal id
-            final Vertex v = baseGraph.V(internal).next();
+            final Vertex v = baseGraph.traversal().V(internal).next();
             cache.set(v, externalID);
             return v;
         } else return null;
@@ -186,7 +184,7 @@ public class BatchGraph<G extends Graph> implements Graph {
         if (!incrementalLoading)
             currentVertex = kvs.isPresent() ? baseGraph.addVertex(kvs.get()) : baseGraph.addVertex();
         else {
-            final Traversal<Vertex, Vertex> traversal = baseGraph.V().has(vertexIdKey, id);
+            final Traversal<Vertex, Vertex> traversal = baseGraph.traversal().V().has(vertexIdKey, id);
             if (traversal.hasNext()) {
                 final Vertex v = traversal.next();
                 if (traversal.hasNext())
@@ -205,11 +203,6 @@ public class BatchGraph<G extends Graph> implements Graph {
     }
 
     @Override
-    public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
-        throw retrievalNotSupported();
-    }
-
-    @Override
     public Iterator<Vertex> vertices(final Object... vertexIds) {
         if (vertexIds.length > 1)
             throw new IllegalArgumentException("BatchGraph only allows a single vertex id at one time");
@@ -220,7 +213,7 @@ public class BatchGraph<G extends Graph> implements Graph {
             if (null == vertex) {
                 if (!this.incrementalLoading) return Collections.emptyIterator();
                 else {
-                    final Iterator<Vertex> iterator = this.baseGraph.V().has(this.vertexIdKey, vertexIds[0]);
+                    final Iterator<Vertex> iterator = this.baseGraph.traversal().V().has(this.vertexIdKey, vertexIds[0]);
                     if (!iterator.hasNext()) return Collections.emptyIterator();
                     vertex = iterator.next();
                     if (iterator.hasNext())
@@ -387,7 +380,7 @@ public class BatchGraph<G extends Graph> implements Graph {
                         Optional.ofNullable(keyValues) : ElementHelper.remove(T.id, keysVals);
 
                 if (id.isPresent()) {
-                    final Traversal<Edge, Edge> traversal = baseGraph.E().has(edgeIdKey, id.get());
+                    final Traversal<Edge, Edge> traversal = baseGraph.traversal().E().has(edgeIdKey, id.get());
                     if (traversal.hasNext()) {
                         final Edge e = traversal.next();
                         // let the user decide how to handle conflict

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
index ffdb9c5..a2b163a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/empty/EmptyGraph.java
@@ -47,16 +47,6 @@ public final class EmptyGraph implements Graph {
     }
 
     @Override
-    public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
-        return EmptyGraphTraversal.instance();
-    }
-
-    @Override
-    public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
-        return EmptyGraphTraversal.instance();
-    }
-
-    @Override
     public Vertex addVertex(final Object... keyValues) {
         throw Exceptions.vertexAdditionsNotSupported();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/2e214fb5/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index 4e92e8c..c015bb7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -128,7 +128,7 @@ public class IoTest extends AbstractGremlinTest {
             reader.readGraph(stream, g);
         }
 
-        final Vertex v = g.V().next();
+        final Vertex v = g.vertices().next();
         assertEquals(123.45d, v.value("d"), 0.000001d);
         assertEquals("some-string", v.<String>value("s"));
         assertEquals(29, v.<Integer>value("i").intValue());
@@ -244,7 +244,7 @@ public class IoTest extends AbstractGremlinTest {
             r.readGraph(in, g2);
         }
 
-        final Vertex v2 = g2.V("1").next();
+        final Vertex v2 = g2.vertices("1").next();
         assertEquals("\u00E9", v2.property("text").value());
 
         // need to manually close the "g2" instance
@@ -291,7 +291,7 @@ public class IoTest extends AbstractGremlinTest {
                 reader.readGraph(is, g2);
             }
 
-            final Vertex v2 = g2.V().next();
+            final Vertex v2 = g2.vertices().next();
             final CustomId customId = (CustomId) v2.id();
             assertEquals(id, customId.getElementId());
             assertEquals("vertex", customId.getCluster());