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/06/16 14:14:39 UTC

incubator-tinkerpop git commit: Pop.first and Pop.last to not confuse with graph theory terms of head/tail which are backwards from computer science terminology.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master bfe43257c -> 66e564e72


Pop.first and Pop.last to not confuse with graph theory terms of head/tail which are backwards from computer science terminology.


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

Branch: refs/heads/master
Commit: 66e564e729bd7c75d769362675922f9c064a2cdf
Parents: bfe4325
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 16 06:14:17 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 16 06:14:34 2015 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                |  1 +
 .../tinkerpop/gremlin/process/traversal/Path.java |  4 ++--
 .../tinkerpop/gremlin/process/traversal/Pop.java  |  8 ++++----
 .../process/traversal/step/filter/WhereStep.java  |  2 +-
 .../traversal/step/filter/exp/XMatchStep.java     |  4 ++--
 .../traversal/step/util/ImmutablePath.java        | 18 +++++++++---------
 .../traversal/step/util/ImmutablePathImpl.java    |  6 +++---
 .../process/traversal/step/util/MutablePath.java  |  3 +--
 .../gremlin/process/traversal/PathTest.java       | 16 ++++++++--------
 9 files changed, 31 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index fa4a8a6..f3c3711 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ TinkerPop 3.0.0.GA (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 * Added `Path.getSingle(pop,label)` and `Path.getList(label)` as default helpers in `Path`.
+* Added `Pop.first` and `Pop.last` as enums for getting single items from a collection.
 * Changed `GremlinServer.start()` to return a `CompletableFuture` that contains the constructed `ServerGremlinExecutor`.
 * Restructured `IoTest` breaking it up into smaller and more logically grouped test cases.
 * Gremlin Server `Settings` now has sensible defaults thus allowing the server to be started with no additional configuration.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java
index e70f467..9318b9c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java
@@ -119,7 +119,7 @@ public interface Path extends Cloneable {
     /**
      * Get the object most/least recently associated with the particular label of the path.
      *
-     * @param pop   head for least recent, tail for most recent
+     * @param pop   first for least recent, last for most recent
      * @param label the label of the path
      * @param <A>   the type of the object associated with the label
      * @return the object associated with the label of the path
@@ -128,7 +128,7 @@ public interface Path extends Cloneable {
     public default <A> A getSingle(final Pop pop, final String label) throws IllegalArgumentException {
         final Object object = this.get(label);
         if (object instanceof List) {
-            return Pop.head == pop ? ((List<A>) object).get(((List) object).size() - 1) : ((List<A>) object).get(0);
+            return Pop.last == pop ? ((List<A>) object).get(((List) object).size() - 1) : ((List<A>) object).get(0);
         } else
             return (A) object;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Pop.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Pop.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Pop.java
index b9201ef..7edf656 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Pop.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Pop.java
@@ -27,11 +27,11 @@ package org.apache.tinkerpop.gremlin.process.traversal;
 public enum Pop {
 
     /**
-     * The end/terminal of a Path (or ordered collection)
+     * The first item in an ordered collection (i.e. <code>collection[0]</code>)
      */
-    head,
+    first,
     /**
-     * The start/initial of a Path (or ordered collection)
+     * The last item in an ordered collection (i.e. <code>collection[collection.size()-1]</code>)
      */
-    tail
+    last
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
index f78d2ea..df017f0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
@@ -76,7 +76,7 @@ public final class WhereStep<S> extends FilterStep<S> implements TraversalParent
         } else if (startStep instanceof StartStep && !startStep.getLabels().isEmpty()) {
             if (startStep.getLabels().size() > 1)
                 throw new IllegalArgumentException("The start step of a where()-traversal predicate can only have one label: " + startStep);
-            TraversalHelper.replaceStep(whereTraversal.getStartStep(), new SelectOneStep<>(whereTraversal, this.scope, Pop.head, startStep.getLabels().iterator().next()), whereTraversal);
+            TraversalHelper.replaceStep(whereTraversal.getStartStep(), new SelectOneStep<>(whereTraversal, this.scope, Pop.last, startStep.getLabels().iterator().next()), whereTraversal);
         }
         //// END STEP to IsStep(ScopeP)
         final Step<?, ?> endStep = whereTraversal.getEndStep();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
index 6e3f78e..d3606ef 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
@@ -93,7 +93,7 @@ public final class XMatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
                 throw new IllegalArgumentException("The start step of a match()-traversal can only have one label: " + startStep);
             final String label = startStep.getLabels().iterator().next();
             this.matchStartLabels.add(label);
-            TraversalHelper.replaceStep(conjunctionTraversal.getStartStep(), new SelectOneStep<>(conjunctionTraversal, Scope.global, Pop.head, label), conjunctionTraversal);
+            TraversalHelper.replaceStep(conjunctionTraversal.getStartStep(), new SelectOneStep<>(conjunctionTraversal, Scope.global, Pop.last, label), conjunctionTraversal);
         }
         // END STEP to XMatchStep
         final Step<?, ?> endStep = conjunctionTraversal.getEndStep();
@@ -287,7 +287,7 @@ public final class XMatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
                 }
                 // path check
                 final Path path = start.path();
-                if (!path.hasLabel(this.matchKey) || start.get().equals(path.getSingle(Pop.head, this.matchKey))) {
+                if (!path.hasLabel(this.matchKey) || start.get().equals(path.getSingle(Pop.first, this.matchKey))) {
                     if (this.traverserStepIdSetByChild) start.setStepId(XMatchStep.this.getId());
                     return start;
                 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
index 881a4b9..dc42162 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
@@ -32,7 +32,7 @@ import java.util.Set;
  */
 public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Cloneable {
 
-    private ImmutablePathImpl previousPath = HeadPath.instance();
+    private ImmutablePathImpl previousPath = TailPath.instance();
     private Object currentObject;
     private Set<String> currentLabels = new LinkedHashSet<>();
 
@@ -41,7 +41,7 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
     }
 
     public static Path make() {
-        return HeadPath.instance();
+        return TailPath.instance();
     }
 
     @SuppressWarnings("CloneDoesntCallSuperClone,CloneDoesntDeclareCloneNotSupportedException")
@@ -51,7 +51,7 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
     }
 
     private ImmutablePath(final Object currentObject, final Set<String> currentLabels) {
-        this(HeadPath.instance(), currentObject, currentLabels);
+        this(TailPath.instance(), currentObject, currentLabels);
     }
 
     private ImmutablePath(final ImmutablePathImpl previousPath, final Object currentObject, final Set<String> currentLabels) {
@@ -145,10 +145,10 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
         return this.objects().toString();
     }
 
-    private static class HeadPath implements Path, ImmutablePathImpl {
-        private static final HeadPath INSTANCE = new HeadPath();
+    private static class TailPath implements Path, ImmutablePathImpl {
+        private static final TailPath INSTANCE = new TailPath();
 
-        private HeadPath() {
+        private TailPath() {
 
         }
 
@@ -216,17 +216,17 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
         }
 
         @Override
-        public HeadPath clone() {
+        public TailPath clone() {
             return this;
         }
 
-        public static HeadPath instance() {
+        public static TailPath instance() {
             return INSTANCE;
         }
 
         @Override
         public boolean equals(final Object object) {
-            return object instanceof HeadPath;
+            return object instanceof TailPath;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathImpl.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathImpl.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathImpl.java
index 74be069..3cd3b16 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathImpl.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathImpl.java
@@ -31,7 +31,7 @@ interface ImmutablePathImpl extends Path {
     @Override
     public default <A> A getSingle(final Pop pop, final String label) {
         // Delegate to the non-throwing, optimized head/tail calculations.
-        final A single = Pop.tail == pop ? this.getSingleTail(label) : this.getSingleHead(label);
+        final A single = Pop.first == pop ? this.getSingleTail(label) : this.getSingleHead(label);
         // Throw if we didn't find the label.
         if (null == single)
             throw Path.Exceptions.stepWithProvidedLabelDoesNotExist(label);
@@ -45,7 +45,7 @@ interface ImmutablePathImpl extends Path {
      * @param <A>   the type of the object associated with the label
      * @return the object associated with the label of the path or null if the path does not contain the label
      */
-    public <A> A getSingleHead(String label);
+    public <A> A getSingleHead(final String label);
 
     /**
      * Get the object most recently associated with the particular label of the path.
@@ -54,5 +54,5 @@ interface ImmutablePathImpl extends Path {
      * @param <A>   the type of the object associated with the label
      * @return the object associated with the label of the path or null if the path does not contain the label
      */
-    public <A> A getSingleTail(String label);
+    public <A> A getSingleTail(final String label);
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
index ff0428b..817e2db 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
@@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -84,7 +83,7 @@ public class MutablePath implements Path, Serializable {
     @Override
     public <A> A getSingle(final Pop pop, final String label) {
         // Override default to avoid building temporary list, and to stop looking when we find the label.
-        if (Pop.head == pop) {
+        if (Pop.last == pop) {
             for (int i = this.labels.size() - 1; i >= 0; i--) {
                 if (labels.get(i).contains(label))
                     return (A) objects.get(i);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/66e564e7/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/PathTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/PathTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/PathTest.java
index 4498b42..825b6ec 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/PathTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/PathTest.java
@@ -175,15 +175,15 @@ public class PathTest extends AbstractGremlinProcessTest {
             path = path.extend("stephen", "a", "c");
             path = path.extend("matthias", "c", "d");
             assertEquals(3, path.size());
-            assertEquals("marko", path.getSingle(Pop.tail, "a"));
-            assertEquals("marko", path.getSingle(Pop.tail, "b"));
-            assertEquals("stephen", path.getSingle(Pop.tail, "c"));
-            assertEquals("matthias", path.getSingle(Pop.tail, "d"));
+            assertEquals("marko", path.getSingle(Pop.first, "a"));
+            assertEquals("marko", path.getSingle(Pop.first, "b"));
+            assertEquals("stephen", path.getSingle(Pop.first, "c"));
+            assertEquals("matthias", path.getSingle(Pop.first, "d"));
             ///
-            assertEquals("marko", path.getSingle(Pop.head, "b"));
-            assertEquals("stephen", path.getSingle(Pop.head, "a"));
-            assertEquals("matthias", path.getSingle(Pop.head, "c"));
-            assertEquals("matthias", path.getSingle(Pop.head, "d"));
+            assertEquals("marko", path.getSingle(Pop.last, "b"));
+            assertEquals("stephen", path.getSingle(Pop.last, "a"));
+            assertEquals("matthias", path.getSingle(Pop.last, "c"));
+            assertEquals("matthias", path.getSingle(Pop.last, "d"));
         });
     }