tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [07/11] tinkerpop git commit: Changed from supplying the step label on increment to initialising a looping construct with the stepLabel.
Date Tue, 17 Jul 2018 17:14:25 GMT
Changed from supplying the step label on increment to initialising a looping construct with
the stepLabel.

Added initialiseLoops method and removed stepLabel parameter from incrLoops.
Modified Looping Traversers and Base Traversers with the new methods.
Added NestedLoop test that requires loop to be set up before the increment is called.


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

Branch: refs/heads/master
Commit: 0b46fcd75c538acc6c5df83c446e9455fdd6775d
Parents: 8a26b3a
Author: GCHQResearcher1337 <39384472+GCHQResearcher1337@users.noreply.github.com>
Authored: Fri Jul 6 15:43:06 2018 +0100
Committer: GCHQResearcher1337 <39384472+GCHQResearcher1337@users.noreply.github.com>
Committed: Fri Jul 6 15:57:44 2018 +0100

----------------------------------------------------------------------
 .../gremlin/process/traversal/Traverser.java    | 12 ++++++---
 .../traversal/step/branch/RepeatStep.java       |  9 ++++---
 .../B_LP_NL_O_P_S_SE_SL_Traverser.java          | 27 +++++++++-----------
 .../traverser/B_LP_NL_O_S_SE_SL_Traverser.java  | 27 +++++++++-----------
 .../traverser/B_NL_O_S_SE_SL_Traverser.java     | 27 +++++++++-----------
 .../traverser/B_O_S_SE_SL_Traverser.java        |  2 +-
 .../LP_NL_O_OB_P_S_SE_SL_Traverser.java         | 27 +++++++++-----------
 .../traverser/LP_NL_O_OB_S_SE_SL_Traverser.java | 25 ++++++++----------
 .../traverser/NL_O_OB_S_SE_SL_Traverser.java    | 27 +++++++++-----------
 .../traverser/O_OB_S_SE_SL_Traverser.java       |  2 +-
 .../traversal/traverser/ProjectedTraverser.java |  9 +++++--
 .../traverser/util/AbstractTraverser.java       |  8 +++++-
 .../traverser/util/EmptyTraverser.java          |  7 ++++-
 .../traverser/util/LabelledCounter.java         |  5 ++++
 gremlin-test/features/branch/Repeat.feature     | 12 +++++++++
 .../traversal/step/branch/RepeatTest.java       | 20 +++++++++++++++
 16 files changed, 143 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
index 93ebe7d..5fed40b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
@@ -213,14 +213,18 @@ public interface Traverser<T> extends Serializable, Comparable<Traverser<T>>,
Cl
         public void set(final T t);
 
         /**
-         * Increment the number of times the traverser has gone through a looping section
of traversal.
+         * Initialise a loop by setting up the looping construct.
          * The step label is important to create a stack of loop counters when within a nested
context.
          * If the provided label is not the same as the current label on the stack, add a
new loop counter.
-         * If the provided label is the same as the current label on the stack, increment
the loop counter.
          *
-         * @param stepLabel the label of the step that is doing the incrementing
+         * @param stepLabel the label of the step that is being set-up.
+         */
+        public void initialiseLoops(final String stepLabel);
+
+        /**
+         * Increment the number of times the traverser has gone through a looping section
of traversal.
          */
-        public void incrLoops(final String stepLabel);
+        public void incrLoops();
 
         /**
          * Set the number of times the traverser has gone through a loop back to 0.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
index bf2c203..ad949f8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
@@ -189,6 +189,7 @@ public final class RepeatStep<S> extends ComputerAwareStep<S,
S> implements Trav
                 return this.repeatTraversal.getEndStep();
             } else {
                 final Traverser.Admin<S> start = this.starts.next();
+                start.initialiseLoops(this.getId());
                 if (doUntil(start, true)) {
                     start.resetLoops();
                     return IteratorUtils.of(start);
@@ -210,12 +211,12 @@ public final class RepeatStep<S> extends ComputerAwareStep<S,
S> implements Trav
 
         final Traverser.Admin<S> start = this.starts.next();
         if (doUntil(start, true)) {
-            start.resetLoops();
             start.setStepId(this.getNextStep().getId());
             start.addLabels(this.labels);
             return IteratorUtils.of(start);
         } else {
             start.setStepId(this.repeatTraversal.getStartStep().getId());
+            start.initialiseLoops(start.getStepId());
             if (doEmit(start, true)) {
                 final Traverser.Admin<S> emitSplit = start.split();
                 emitSplit.resetLoops();
@@ -278,7 +279,7 @@ public final class RepeatStep<S> extends ComputerAwareStep<S,
S> implements Trav
             final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent();
             while (true) {
                 final Traverser.Admin<S> start = this.starts.next();
-                start.incrLoops(this.getId());
+                start.incrLoops();
                 if (repeatStep.doUntil(start, false)) {
                     start.resetLoops();
                     return IteratorUtils.of(start);
@@ -300,7 +301,7 @@ public final class RepeatStep<S> extends ComputerAwareStep<S,
S> implements Trav
         protected Iterator<Traverser.Admin<S>> computerAlgorithm() throws NoSuchElementException
{
             final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent();
             final Traverser.Admin<S> start = this.starts.next();
-            start.incrLoops(repeatStep.getId());
+            start.incrLoops();
             if (repeatStep.doUntil(start, false)) {
                 start.resetLoops();
                 start.setStepId(repeatStep.getNextStep().getId());
@@ -320,4 +321,4 @@ public final class RepeatStep<S> extends ComputerAwareStep<S,
S> implements Trav
         }
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_P_S_SE_SL_Traverser.java
index b837642..380eb9f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_P_S_SE_SL_Traverser.java
@@ -39,26 +39,23 @@ public class B_LP_NL_O_P_S_SE_SL_Traverser<T> extends B_LP_O_P_S_SE_SL_Traverser
 
     @Override
     public int loops() {
-        return this.nestedLoops.size() > 0 ? this.nestedLoops.peek().count() : 0;
+        return this.nestedLoops.peek().count();
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -68,7 +65,7 @@ public class B_LP_NL_O_P_S_SE_SL_Traverser<T> extends B_LP_O_P_S_SE_SL_Traverser
         final B_LP_NL_O_P_S_SE_SL_Traverser<R> clone = (B_LP_NL_O_P_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -77,7 +74,7 @@ public class B_LP_NL_O_P_S_SE_SL_Traverser<T> extends B_LP_O_P_S_SE_SL_Traverser
         final B_LP_NL_O_P_S_SE_SL_Traverser<T> clone = (B_LP_NL_O_P_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_S_SE_SL_Traverser.java
index a4bc1bd..aa3e9b0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_NL_O_S_SE_SL_Traverser.java
@@ -39,26 +39,23 @@ public class B_LP_NL_O_S_SE_SL_Traverser<T> extends B_LP_O_S_SE_SL_Traverser<T>
 
     @Override
     public int loops() {
-        return this.nestedLoops.size() > 0 ? this.nestedLoops.peek().count() : 0;
+        return this.nestedLoops.peek().count();
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -68,7 +65,7 @@ public class B_LP_NL_O_S_SE_SL_Traverser<T> extends B_LP_O_S_SE_SL_Traverser<T>
         final B_LP_NL_O_S_SE_SL_Traverser<R> clone = (B_LP_NL_O_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -77,7 +74,7 @@ public class B_LP_NL_O_S_SE_SL_Traverser<T> extends B_LP_O_S_SE_SL_Traverser<T>
         final B_LP_NL_O_S_SE_SL_Traverser<T> clone = (B_LP_NL_O_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_NL_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_NL_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_NL_O_S_SE_SL_Traverser.java
index 369448e..8d5d7dd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_NL_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_NL_O_S_SE_SL_Traverser.java
@@ -39,26 +39,23 @@ public class B_NL_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
 
     @Override
     public int loops() {
-        return this.nestedLoops.size() > 0 ? this.nestedLoops.peek().count() : 0;
+        return this.nestedLoops.peek().count();
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -68,7 +65,7 @@ public class B_NL_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         final B_NL_O_S_SE_SL_Traverser<R> clone = (B_NL_O_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -77,7 +74,7 @@ public class B_NL_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         final B_NL_O_S_SE_SL_Traverser<T> clone = (B_NL_O_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
index 0409cd7..d184b7e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
@@ -64,7 +64,7 @@ public class B_O_S_SE_SL_Traverser<T> extends B_O_Traverser<T>
{
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
+    public void incrLoops() {
         this.loops++;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_P_S_SE_SL_Traverser.java
index 2409e4a..7fcaa2a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_P_S_SE_SL_Traverser.java
@@ -40,26 +40,23 @@ public class LP_NL_O_OB_P_S_SE_SL_Traverser<T> extends LP_O_OB_P_S_SE_SL_Travers
 
     @Override
     public int loops() {
-        return this.nestedLoops.size() > 0 ? this.nestedLoops.peek().count() : 0;
+        return this.nestedLoops.peek().count();
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -69,7 +66,7 @@ public class LP_NL_O_OB_P_S_SE_SL_Traverser<T> extends LP_O_OB_P_S_SE_SL_Travers
         final LP_NL_O_OB_P_S_SE_SL_Traverser<R> clone = (LP_NL_O_OB_P_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -78,7 +75,7 @@ public class LP_NL_O_OB_P_S_SE_SL_Traverser<T> extends LP_O_OB_P_S_SE_SL_Travers
         final LP_NL_O_OB_P_S_SE_SL_Traverser<T> clone = (LP_NL_O_OB_P_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_S_SE_SL_Traverser.java
index 65fda97..92eb991 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_NL_O_OB_S_SE_SL_Traverser.java
@@ -44,22 +44,19 @@ public class LP_NL_O_OB_S_SE_SL_Traverser<T> extends LP_O_OB_S_SE_SL_Traverser<T
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -69,7 +66,7 @@ public class LP_NL_O_OB_S_SE_SL_Traverser<T> extends LP_O_OB_S_SE_SL_Traverser<T
         final LP_NL_O_OB_S_SE_SL_Traverser<R> clone = (LP_NL_O_OB_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -78,7 +75,7 @@ public class LP_NL_O_OB_S_SE_SL_Traverser<T> extends LP_O_OB_S_SE_SL_Traverser<T
         final LP_NL_O_OB_S_SE_SL_Traverser<T> clone = (LP_NL_O_OB_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_O_OB_S_SE_SL_Traverser.java
index 3975758..31e93fe 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/NL_O_OB_S_SE_SL_Traverser.java
@@ -40,26 +40,23 @@ public class NL_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
 
     @Override
     public int loops() {
-        return this.nestedLoops.size() > 0 ? this.nestedLoops.peek().count() : 0;
+        return this.nestedLoops.peek().count();
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        // If we encounter a new step label then grow the stack otherwise increment the loop
count
-        if (this.nestedLoops.size() == 0 || !this.nestedLoops.peek().hasLabel(stepLabel))
{
-            this.nestedLoops.add(new LabelledCounter(stepLabel, (short)1));
-        }
-        else {
-            this.nestedLoops.peek().increment();
-        }
+    public void initialiseLoops(final String stepLabel) {
+        if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel))
+            this.nestedLoops.push(new LabelledCounter(stepLabel, (short)0));
+    }
+
+    @Override
+    public void incrLoops() {
+        this.nestedLoops.peek().increment();
     }
 
     @Override
     public void resetLoops() {
-        // Protect against reset without increment during RepeatStep setup
-        if (this.nestedLoops.size() > 0) {
-            this.nestedLoops.pop();
-        }
+        this.nestedLoops.pop();
     }
 
     /////////////////
@@ -69,7 +66,7 @@ public class NL_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         final NL_O_OB_S_SE_SL_Traverser<R> clone = (NL_O_OB_S_SE_SL_Traverser<R>)
super.split(r, step);
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 
@@ -78,7 +75,7 @@ public class NL_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         final NL_O_OB_S_SE_SL_Traverser<T> clone = (NL_O_OB_S_SE_SL_Traverser<T>)
super.split();
         clone.nestedLoops = new Stack<>();
         for(LabelledCounter lc : this.nestedLoops)
-            clone.nestedLoops.add((LabelledCounter) lc.clone());
+            clone.nestedLoops.push((LabelledCounter) lc.clone());
         return clone;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
index d81a564..e35716d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
@@ -74,7 +74,7 @@ public class O_OB_S_SE_SL_Traverser<T> extends O_Traverser<T>
{
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
+    public void incrLoops() {
         this.loops++;
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/ProjectedTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/ProjectedTraverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/ProjectedTraverser.java
index 602f88f..b624eef 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/ProjectedTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/ProjectedTraverser.java
@@ -91,8 +91,13 @@ public final class ProjectedTraverser<T, P> implements Traverser.Admin<T>
{
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
-        this.baseTraverser.incrLoops(stepLabel);
+    public void initialiseLoops(final String stepLabel) {
+        this.baseTraverser.initialiseLoops(stepLabel);
+    }
+
+    @Override
+    public void incrLoops() {
+        this.baseTraverser.incrLoops();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/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 50a206b..9d52fea 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
@@ -98,8 +98,14 @@ public abstract class AbstractTraverser<T> implements Traverser<T>,
Traverser.Ad
         this.t = t;
     }
 
+
+    @Override
+    public void initialiseLoops(final String stepLabel) {
+
+    }
+
     @Override
-    public void incrLoops(final String stepLabel) {
+    public void incrLoops() {
 
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/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 7c99cb5..4f4ca0a 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
@@ -70,7 +70,12 @@ public final class EmptyTraverser<T> implements Traverser<T>,
Traverser.Admin<T>
     }
 
     @Override
-    public void incrLoops(final String stepLabel) {
+    public void initialiseLoops(final String stepLabel) {
+
+    }
+
+    @Override
+    public void incrLoops() {
 
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/LabelledCounter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/LabelledCounter.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/LabelledCounter.java
index a5214d2..0e2130a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/LabelledCounter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/LabelledCounter.java
@@ -58,6 +58,11 @@ public class LabelledCounter implements Serializable, Cloneable {
     }
 
     @Override
+    public String toString(){
+        return "Step Label: " + label + " Counter: " + count.toString();
+    }
+
+    @Override
     public boolean equals(final Object o) {
         if (this == o) return true;
         if (!(o instanceof LabelledCounter)) return false;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-test/features/branch/Repeat.feature
----------------------------------------------------------------------
diff --git a/gremlin-test/features/branch/Repeat.feature b/gremlin-test/features/branch/Repeat.feature
index c38fa1b..695ca1f 100644
--- a/gremlin-test/features/branch/Repeat.feature
+++ b/gremlin-test/features/branch/Repeat.feature
@@ -306,3 +306,15 @@ Scenario: g_VX3X_repeatXbothX_createdXX_untilXloops_is_40XXemit_repeatXin_knowsX
         | josh |
         | lop |
         | ripple |
+
+Scenario: g_VX1X_repeatXrepeatXunionXout_uses_out_traversesXX_whereXloops_isX0X_timesX1X_timeX2X_name
+    Given the crew graph
+    And using the parameter v1Id defined as "v[marko].id"
+    And the traversal of
+      """
+      g.V(v1Id).repeat(__.repeat(__.union(__.out("uses"), __.out("traverses")).where(__.loops().is(0))).times(1)).times(2).values("name")
+      """
+    When iterated to list
+      Then the result should be unordered
+        | result |
+        | tinkergraph |

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0b46fcd7/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java
index 80c9332..b454c8c 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatTest.java
@@ -37,6 +37,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.CREW;
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.SINK;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
@@ -111,6 +112,8 @@ public abstract class RepeatTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, String> get_g_VX3X_repeatXbothX_createdXX_untilXloops_is_40XXemit_repeatXin_knowsXX_emit_loopsXisX1Xdedup_values(final
Object v3Id);
 
+    public abstract Traversal<Vertex, String> get_g_VX1X_repeatXrepeatXunionXout_uses_out_traversesXX_whereXloops_isX0X_timesX1X_timeX2X_name(final
Object v1Id);
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_repeatXoutX_timesX2X_emit_path() {
@@ -397,6 +400,18 @@ public abstract class RepeatTest extends AbstractGremlinProcessTest {
         assertFalse(traversal.hasNext());
     }
 
+    @Test
+    @LoadGraphWith(CREW)
+    public void g_VX1X_repeatXrepeatXunionXout_uses_out_traversesXX_whereXloops_isX0X_timesX1X_timeX2X_name()
{
+        final Traversal<Vertex, String> traversal = get_g_VX1X_repeatXrepeatXunionXout_uses_out_traversesXX_whereXloops_isX0X_timesX1X_timeX2X_name(convertToVertexId("marko"));
+
+        printTraversalForm(traversal);
+        assertTrue(traversal.hasNext());
+        String name = traversal.next();
+        assertEquals(name, "tinkergraph");
+
+        assertFalse(traversal.hasNext());
+    }
 
     public static class Traversals extends RepeatTest {
 
@@ -500,5 +515,10 @@ public abstract class RepeatTest extends AbstractGremlinProcessTest {
         public Traversal<Vertex, String> get_g_VX3X_repeatXbothX_createdXX_untilXloops_is_40XXemit_repeatXin_knowsXX_emit_loopsXisX1Xdedup_values(final
Object v3Id) {
             return g.V(v3Id).repeat( __.both("created")).until(loops().is(40)).emit(__.repeat(__.in("knows")).emit(loops().is(1))).dedup().values("name");
         }
+
+        @Override
+        public Traversal<Vertex, String> get_g_VX1X_repeatXrepeatXunionXout_uses_out_traversesXX_whereXloops_isX0X_timesX1X_timeX2X_name(final
Object v1Id) {
+            return g.V(v1Id).repeat(__.repeat(__.union(out("uses"), out("traverses")).where(__.loops().is(0))).times(1)).times(2).values("name");
+        }
     }
 }


Mime
View raw message