tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pie...@apache.org
Subject [1/3] incubator-tinkerpop git commit: added optional to GraphTraversal
Date Fri, 25 Mar 2016 17:18:25 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-968 [created] edc9d6823


added optional to GraphTraversal


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

Branch: refs/heads/TINKERPOP-968
Commit: 427c3327988d83970d3191c552357d4805d01e61
Parents: 0008665
Author: pieter <pieter.martin@gmail.com>
Authored: Fri Mar 25 17:26:45 2016 +0200
Committer: pieter <pieter.martin@gmail.com>
Committed: Fri Mar 25 17:26:45 2016 +0200

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc       |  25 +++
 .../traversal/dsl/graph/GraphTraversal.java     |   4 +
 .../gremlin/process/traversal/dsl/graph/__.java |   7 +
 .../step/branch/GroovyOptionalTest.groovy       |  55 +++++++
 .../process/GroovyProcessComputerSuite.java     |   2 +
 .../process/GroovyProcessStandardSuite.java     |   2 +
 .../gremlin/process/ProcessComputerSuite.java   |   3 +
 .../gremlin/process/ProcessStandardSuite.java   |   3 +
 .../traversal/step/branch/OptionalTest.java     | 154 +++++++++++++++++++
 9 files changed, 255 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index cea9052..1dac96e 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -1127,6 +1127,31 @@ g.V().repeat(both()).times(3).values('age').min()
 IMPORTANT: `min(local)` determines the min of the current, local object (not the objects
in the traversal stream).
 This works for `Collection` and `Number`-type objects. For any other object, a min of `Double.NaN`
is returned.
 
+[[optional-step]]
+Optional Step
+~~~~~~~~~~~~~
+
+The `optional()`-step returns the result of the specified traversal if it yields a result
else it returns the calling
+element, i.e. the `identity()`.
+
+[gremlin-groovy,modern]
+----
+g.V(2).optional(out('knows')) <1>
+g.V(2).optional(__.in('knows')) <2>
+----
+
+<1> vadas does not have an `out` "know" edge so vadas is returned.
+<2> vadas does have an `in` "knows" edge so marko is returned.
+
+`optional` is particularly useful for lifting entire graphs when used in conjunction with
`path` or `tree`.
+
+[gremlin-groovy,modern]
+----
+g.V().hasLabel('person').optional(out("knows").optional(out("created"))).path() <1>
+----
+
+<1> Returns the paths of everybody followed by who they know followed by what they
created.
+
 [[or-step]]
 Or Step
 ~~~~~~~

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 2ed3dd7..a0a8473 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1106,6 +1106,10 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
         return this.choose(__.filter(new PredicateTraverser<>(choosePredicate)), trueChoice,
falseChoice);
     }
 
+    public default <E2> GraphTraversal<S, E2> optional(final Traversal<?,
E2> optionalTraversal) {
+        return this.choose(optionalTraversal, optionalTraversal.asAdmin().clone(), __.identity());
+    }
+
     public default <E2> GraphTraversal<S, E2> union(final Traversal<?, E2>...
unionTraversals) {
         return this.asAdmin().addStep(new UnionStep(this.asAdmin(), Arrays.copyOf(unionTraversals,
unionTraversals.length, Traversal.Admin[].class)));
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index befae78..270bb4c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -977,6 +977,13 @@ public class __ {
     }
 
     /**
+     * @see GraphTraversal#optional(Traversal)
+     */
+    public static <A, B> GraphTraversal<A, B> optional(final Traversal<?,
B> optionalTraversal) {
+        return __.<A>start().optional(optionalTraversal);
+    }
+
+    /**
      * @see GraphTraversal#union(Traversal[])
      */
     public static <A, B> GraphTraversal<A, B> union(final Traversal<?, B>...
traversals) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyOptionalTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyOptionalTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyOptionalTest.groovy
new file mode 100644
index 0000000..d3f04cc
--- /dev/null
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyOptionalTest.groovy
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.branch
+
+import org.apache.tinkerpop.gremlin.process.traversal.Path
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal
+import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal
+import org.apache.tinkerpop.gremlin.structure.Vertex
+
+/**
+ * @author Pieter Martin
+ */
+public abstract class GroovyOptionalTest {
+
+    public static class Traversals extends OptionalTest {
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_VX2X_optionalXoutXknowsXX(Object v2Id)
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v2Id).optional(out('knows'))",
"v2Id", v2Id)
+        }
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_VX2X_optionalXinXknowsXX(Object v2Id)
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V(v2Id).optional(__.in('knows'))",
"v2Id", v2Id)
+        }
+
+        @Override
+        public Traversal<Vertex, Path> get_g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path()
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V().hasLabel('person').optional(out('knows').optional(out('created'))).path()")
+        }
+
+        @Override
+        public Traversal<Vertex, Path> get_g_V_optionalXout_optionalXoutXX_path() {
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.optional(out().optional(out())).path")
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
index 496083f..3f89c2b 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyBranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyChooseTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyOptionalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyLocalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyRepeatTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyUnionTest;
@@ -106,6 +107,7 @@ public class GroovyProcessComputerSuite extends ProcessComputerSuite {
             //branch
             GroovyBranchTest.Traversals.class,
             GroovyChooseTest.Traversals.class,
+            GroovyOptionalTest.Traversals.class,
             GroovyLocalTest.Traversals.class,
             GroovyRepeatTest.Traversals.class,
             GroovyUnionTest.Traversals.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessStandardSuite.java
b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessStandardSuite.java
index 870cb9a..113f70c 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessStandardSuite.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessStandardSuite.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyBranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyChooseTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyOptionalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyLocalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyRepeatTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyUnionTest;
@@ -103,6 +104,7 @@ public class GroovyProcessStandardSuite extends ProcessStandardSuite {
             // branch
             GroovyBranchTest.Traversals.class,
             GroovyChooseTest.Traversals.class,
+            GroovyOptionalTest.Traversals.class,
             GroovyLocalTest.Traversals.class,
             GroovyRepeatTest.Traversals.class,
             GroovyUnionTest.Traversals.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
index 82436c2..ca0c7d3 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVe
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionTest;
@@ -113,6 +114,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             // branch
             BranchTest.Traversals.class,
             ChooseTest.Traversals.class,
+            OptionalTest.Traversals.class,
             LocalTest.Traversals.class,
             RepeatTest.Traversals.class,
             UnionTest.Traversals.class,
@@ -194,6 +196,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             // branch
             BranchTest.class,
             ChooseTest.class,
+            OptionalTest.class,
             LocalTest.class,
             RepeatTest.class,
             UnionTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
index 7850c3f..8277dc5 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionTest;
@@ -105,6 +106,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             // branch
             BranchTest.Traversals.class,
             ChooseTest.Traversals.class,
+            OptionalTest.Traversals.class,
             LocalTest.Traversals.class,
             RepeatTest.Traversals.class,
             UnionTest.Traversals.class,
@@ -185,6 +187,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             // branch
             BranchTest.class,
             ChooseTest.class,
+            OptionalTest.class,
             LocalTest.class,
             RepeatTest.class,
             UnionTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/427c3327/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
new file mode 100644
index 0000000..3240d5c
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/OptionalTest.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.step.branch;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.IgnoreEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Pieter Martin
+ */
+@RunWith(GremlinProcessRunner.class)
+public abstract class OptionalTest extends AbstractGremlinProcessTest {
+
+    public abstract Traversal<Vertex, Vertex> get_g_VX2X_optionalXoutXknowsXX(Object
v2Id);
+
+    public abstract Traversal<Vertex, Vertex> get_g_VX2X_optionalXinXknowsXX(Object
v2Id);
+
+    public abstract Traversal<Vertex, Path> get_g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path();
+
+    public abstract Traversal<Vertex, Path> get_g_V_optionalXout_optionalXoutXX_path();
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_VX2X_optionalXoutXknowsXX() {
+        final Traversal<Vertex, Vertex> traversal = get_g_VX2X_optionalXoutXknowsXX(convertToVertexId(this.graph,
"vadas"));
+        printTraversalForm(traversal);
+        assertTrue(traversal.hasNext());
+        assertEquals(convertToVertex(this.graph, "vadas"), traversal.next());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_VX2X_optionalXinXknowsXX() {
+        final Traversal<Vertex, Vertex> traversal = get_g_VX2X_optionalXinXknowsXX(convertToVertexId(this.graph,
"vadas"));
+        printTraversalForm(traversal);
+        assertTrue(traversal.hasNext());
+        assertEquals(convertToVertex(this.graph, "marko"), traversal.next());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    @IgnoreEngine(TraversalEngine.Type.COMPUTER)
+    public void g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path() {
+        final Traversal<Vertex, Path> traversal = get_g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path();
+        printTraversalForm(traversal);
+        List<Path> paths = traversal.toList();
+        assertEquals(6, paths.size());
+        List<Predicate<Path>> pathsToAssert = Arrays.asList(
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "vadas")),
+                p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph,
"ripple")),
+                p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph,
"lop")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"vadas")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"josh")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"peter"))
+        );
+        for (Predicate<Path> pathPredicate : pathsToAssert) {
+            Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
+            assertTrue(path.isPresent());
+            assertTrue(paths.remove(path.get()));
+        }
+        assertTrue(paths.isEmpty());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    @IgnoreEngine(TraversalEngine.Type.COMPUTER)
+    public void g_V_optionalXout_optionalXoutXX_path() {
+        final Traversal<Vertex, Path> traversal = get_g_V_optionalXout_optionalXoutXX_path();
+        printTraversalForm(traversal);
+        List<Path> paths = traversal.toList();
+        assertEquals(10, paths.size());
+        List<Predicate<Path>> pathsToAssert = Arrays.asList(
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "lop")),
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "vadas")),
+                p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph,
"lop")),
+                p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph,
"marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph,
"ripple")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"vadas")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"lop")),
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"josh")) && p.get(1).equals(convertToVertex(this.graph, "lop")),
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"josh")) && p.get(1).equals(convertToVertex(this.graph, "ripple")),
+                p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph,
"ripple")),
+                p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph,
"peter")) && p.get(1).equals(convertToVertex(this.graph, "lop"))
+        );
+        for (Predicate<Path> pathPredicate : pathsToAssert) {
+            Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
+            assertTrue(path.isPresent());
+            assertTrue(paths.remove(path.get()));
+        }
+        assertTrue(paths.isEmpty());
+    }
+
+    public static class Traversals extends OptionalTest {
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_VX2X_optionalXoutXknowsXX(Object v2Id)
{
+            return this.g.V(v2Id).optional(out("knows"));
+        }
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_VX2X_optionalXinXknowsXX(Object v2Id)
{
+            return this.g.V(v2Id).optional(in("knows"));
+        }
+
+        @Override
+        public Traversal<Vertex, Path> get_g_V_hasLabelXpersonX_optionalXoutXknowsX_optionalXoutXcreatedXXX_path()
{
+            return this.g.V().hasLabel("person").optional(out("knows").optional(out("created"))).path();
+        }
+
+        @Override
+        public Traversal<Vertex, Path> get_g_V_optionalXout_optionalXoutXX_path() {
+            return this.g.V().optional(
+                    out().optional(
+                            out()
+                    )
+            ).path();
+        }
+
+    }
+}


Mime
View raw message