Added tests around use of Pop in select()

Added more javadoc and reference docs CTR


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

Branch: refs/heads/master
Commit: 0a08bf929fdad19cbef4b21e993ce041254d8589
Parents: 123abf9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Feb 17 11:27:09 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Feb 17 11:27:09 2017 -0500

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc       |  9 +++++++
 .../traversal/dsl/graph/GraphTraversal.java     | 22 +++++++++++++++
 .../traversal/step/map/GroovySelectTest.groovy  | 10 +++++++
 .../process/traversal/step/map/SelectTest.java  | 28 ++++++++++++++++++++
 4 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a08bf92/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc 
b/docs/src/reference/the-traversal.asciidoc
index 2002028..8ba51df 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -1960,6 +1960,15 @@ 
g.V().hasLabel('song').out('sungBy').groupCount().by('name').select(values).unfo
 
 WARNING: Note that `by()`-modulation is not supported with `select(keys)` and 
`select(values)`.
 
+There is also an option to supply a `Pop` operation to `select()` to 
manipulate `List` objects in the `Traverser`:
+
+[gremlin-groovy,modern]
+----
+g.V(1).as("a").repeat(out().as("a")).times(2).select(first, "a")
+g.V(1).as("a").repeat(out().as("a")).times(2).select(last, "a")
+g.V(1).as("a").repeat(out().as("a")).times(2).select(all, "a")
+----
+
 [[using-where-with-select]]
 Using Where with Select
 ^^^^^^^^^^^^^^^^^^^^^^^

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a08bf92/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 0c04e83..095391d 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
@@ -595,6 +595,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, 
E> {
      * Map the {@link Traverser} to its {@link Path} history via {@link 
Traverser#path}.
      *
      * @return the traversal with an appended {@link PathStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#path-step";>Reference
 Documentation - Path Step</a>
      */
     public default GraphTraversal<S, Path> path() {
         this.asAdmin().getBytecode().addStep(Symbols.path);
@@ -607,6 +608,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, 
E> {
      * @param matchTraversals the traversal that maintain variables which must 
hold for the life of the traverser
      * @param <E2>            the type of the obejcts bound in the variables
      * @return the traversal with an appended {@link MatchStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#match-step";>Reference
 Documentation - Match Step</a>
      */
     public default <E2> GraphTraversal<S, Map<String, E2>> match(final 
Traversal<?, ?>... matchTraversals) {
         this.asAdmin().getBytecode().addStep(Symbols.match, matchTraversals);
@@ -618,6 +620,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, 
E> {
      *
      * @param <E2> the sack value type
      * @return the traversal with an appended {@link SackStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#sack-step";>Reference
 Documentation - Sack Step</a>
      */
     public default <E2> GraphTraversal<S, E2> sack() {
         this.asAdmin().getBytecode().addStep(Symbols.sack);
@@ -646,6 +649,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, 
E> {
      * @param otherSelectKeys the third+ keys to project
      * @param <E2>            the type of the objects projected
      * @return the traversal with an appended {@link SelectStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#select-step";>Reference
 Documentation - Select Step</a>
      */
     public default <E2> GraphTraversal<S, Map<String, E2>> select(final Pop 
pop, final String selectKey1, final String selectKey2, String... 
otherSelectKeys) {
         final String[] selectKeys = new String[otherSelectKeys.length + 2];
@@ -664,6 +668,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, 
E> {
      * @param otherSelectKeys the third+ keys to project
      * @param <E2>            the type of the objects projected
      * @return the traversal with an appended {@link SelectStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#select-step";>Reference
 Documentation - Select Step</a>
      */
     public default <E2> GraphTraversal<S, Map<String, E2>> select(final String 
selectKey1, final String selectKey2, String... otherSelectKeys) {
         final String[] selectKeys = new String[otherSelectKeys.length + 2];
@@ -674,11 +679,28 @@ public interface GraphTraversal<S, E> extends 
Traversal<S, E> {
         return this.asAdmin().addStep(new SelectStep<>(this.asAdmin(), null, 
selectKeys));
     }
 
+    /**
+     * Map the {@link Traverser} to the object specified by the {@code 
selectKey} and apply the {@link Pop} operation
+     * to it.
+     *
+     * @param selectKey the key to project
+     * @return the traversal with an appended {@link SelectStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#select-step";>Reference
 Documentation - Select Step</a>
+     */
     public default <E2> GraphTraversal<S, E2> select(final Pop pop, final 
String selectKey) {
         this.asAdmin().getBytecode().addStep(Symbols.select, pop, selectKey);
         return this.asAdmin().addStep(new SelectOneStep<>(this.asAdmin(), pop, 
selectKey));
     }
 
+    /**
+     * Map the {@link Traverser} to the object specified by the {@code 
selectKey}. Note that unlike other uses of
+     * {@code select} where there are multiple keys, this use of {@code 
select} with a single key does not produce a
+     * {@code Map}.
+     *
+     * @param selectKey the key to project
+     * @return the traversal with an appended {@link SelectStep}.
+     * @see <a target="_blank" 
href="http://tinkerpop.apache.org/docs/${project.version}/reference/#select-step";>Reference
 Documentation - Select Step</a>
+     */
     public default <E2> GraphTraversal<S, E2> select(final String selectKey) {
         this.asAdmin().getBytecode().addStep(Symbols.select, selectKey);
         return this.asAdmin().addStep(new SelectOneStep<>(this.asAdmin(), 
null, selectKey));

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a08bf92/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
----------------------------------------------------------------------
diff --git 
a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
 
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
index 789c36f..89fc691 100644
--- 
a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
+++ 
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovySelectTest.groovy
@@ -33,6 +33,16 @@ public abstract class GroovySelectTest {
     public static class Traversals extends SelectTest {
 
         @Override
+        public Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXfirst_aX(final Object v1Id) {
+            new ScriptTraversal<>(g, "gremlin-groovy", 
"g.V(v1Id).as('a').repeat(__.out().as('a')).times(2).select(Pop.first, 'a')", 
"v1Id", v1Id)
+        }
+
+        @Override
+        public Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXlast_aX(final Object v1Id) {
+            new ScriptTraversal<>(g, "gremlin-groovy", 
"g.V(v1Id).as('a').repeat(__.out().as('a')).times(2).select(Pop.last, 'a')", 
"v1Id", v1Id)
+        }
+
+        @Override
         public Traversal<Vertex, Map<String, Vertex>> 
get_g_VX1X_asXaX_outXknowsX_asXbX_selectXa_bX(final Object v1Id) {
             new ScriptTraversal<>(g, "gremlin-groovy", 
"g.V(v1Id).as('a').out('knows').as('b').select('a','b')", "v1Id", v1Id)
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a08bf92/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
index 6e418b2..6d07edf 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/SelectTest.java
@@ -117,6 +117,10 @@ public abstract class SelectTest extends 
AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Map<String, Object>> 
get_g_V_valueMap_selectXpop_a_bX(final Pop pop);
 
+    public abstract Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXfirst_aX(final Object v1Id);
+
+    public abstract Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXlast_aX(final Object v1Id);
+
     // when labels don't exist
 
     public abstract Traversal<Vertex, String> 
get_g_V_untilXout_outX_repeatXin_asXaXX_selectXaX_byXtailXlocalX_nameX();
@@ -646,6 +650,20 @@ public abstract class SelectTest extends 
AbstractGremlinProcessTest {
         assertFalse(traversal.hasNext());
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXfirst_aX() {
+        final Traversal<Vertex, Vertex> traversal = 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXfirst_aX(convertToVertexId("marko"));
+        checkResults(Arrays.asList(convertToVertex(graph, "marko"), 
convertToVertex(graph, "marko")), traversal);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXlast_aX() {
+        final Traversal<Vertex, Vertex> traversal = 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXlast_aX(convertToVertexId("marko"));
+        checkResults(Arrays.asList(convertToVertex(graph, "ripple"), 
convertToVertex(graph, "lop")), traversal);
+    }
+
     public static class Traversals extends SelectTest {
         @Override
         public Traversal<Vertex, Map<String, Vertex>> 
get_g_VX1X_asXaX_outXknowsX_asXbX_selectXa_bX(final Object v1Id) {
@@ -846,5 +864,15 @@ public abstract class SelectTest extends 
AbstractGremlinProcessTest {
         public Traversal<Vertex, Map<String, String>> 
get_g_V_asXaX_outXknowsX_asXbX_localXselectXa_bX_byXnameXX() {
             return g.V().as("a").out("knows").as("b").local(__.<Vertex, 
String>select("a", "b").by("name"));
         }
+
+        @Override
+        public Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXfirst_aX(final Object v1Id) {
+            return 
g.V(v1Id).as("a").repeat(__.out().as("a")).times(2).select(Pop.first, "a");
+        }
+
+        @Override
+        public Traversal<Vertex, Vertex> 
get_g_VX1X_asXaX_repeatXout_asXaXX_timesX2X_selectXlast_aX(final Object v1Id) {
+            return 
g.V(v1Id).as("a").repeat(__.out().as("a")).times(2).select(Pop.last, "a");
+        }
     }
 }

Reply via email to