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 00:08:28 UTC

[27/31] incubator-tinkerpop git commit: Simplifying XMatchStep even more. This is looking really good.

Simplifying XMatchStep even more. This is looking really good.


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

Branch: refs/heads/master
Commit: a1dbb1b37468d687eeb73b6c968513e28bb15c00
Parents: 59d2804
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jun 15 13:41:45 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jun 15 13:41:45 2015 -0600

----------------------------------------------------------------------
 .../traversal/step/filter/exp/XMatchStep.java   | 24 +++++++-------------
 1 file changed, 8 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a1dbb1b3/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 a65de9c..a0ae8eb 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
@@ -67,18 +67,18 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
         super(traversal);
         this.conjunction = conjunction;
         this.conjunctionTraversals = (List) Stream.of(conjunctionTraversals).map(Traversal::asAdmin).map(this::integrateChild).collect(Collectors.toList());
-        this.conjunctionTraversals.forEach(this::addSelectOneStartStep);
+        this.conjunctionTraversals.forEach(this::addSelectOneStartStep); // recursively convert to SelectOneStep, XMatchStep, or XMatchEndStep
     }
 
     private void addSelectOneStartStep(final Traversal.Admin<?, ?> conjunctionTraversal) {
-        // CONJUNCTION STEPS to XMatchSteps
-        for (final Step<?, ?> conjunction : TraversalHelper.getStepsOfAssignableClass(ConjunctionStep.class, conjunctionTraversal)) {
-            final XMatchStep xMatchStep = new XMatchStep(conjunctionTraversal, conjunction instanceof AndStep ? XMatchStep.Conjunction.AND : XMatchStep.Conjunction.OR, ((ConjunctionStep<?>) conjunction).getLocalChildren().toArray(new Traversal[((ConjunctionStep<?>) conjunction).getLocalChildren().size()]));
-            TraversalHelper.replaceStep(conjunction, xMatchStep, conjunctionTraversal);
-        }
-        // START STEP to SelectOneStep
+        // START STEP to SelectOneStep OR XMatchStep
         final Step<?, ?> startStep = conjunctionTraversal.getStartStep();
-        if (startStep instanceof StartStep && !startStep.getLabels().isEmpty()) {
+        if (startStep instanceof ConjunctionStep) {
+            final XMatchStep xMatchStep = new XMatchStep(conjunctionTraversal,
+                    startStep instanceof AndStep ? XMatchStep.Conjunction.AND : XMatchStep.Conjunction.OR,
+                    ((ConjunctionStep<?>) startStep).getLocalChildren().toArray(new Traversal[((ConjunctionStep<?>) startStep).getLocalChildren().size()]));
+            TraversalHelper.replaceStep(startStep, xMatchStep, conjunctionTraversal);
+        } else if (startStep instanceof StartStep && !startStep.getLabels().isEmpty()) {
             if (startStep.getLabels().size() > 1)
                 throw new IllegalArgumentException("The start step of a match()-traversal can only have one label: " + startStep);
             TraversalHelper.replaceStep(conjunctionTraversal.getStartStep(), new SelectOneStep<>(conjunctionTraversal, Scope.global, Pop.head, startStep.getLabels().iterator().next()), conjunctionTraversal);
@@ -94,14 +94,6 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
             if (null != label) xMatchEndStep.addLabel(label);
             conjunctionTraversal.asAdmin().addStep(xMatchEndStep);
         }
-        // TODO: is this needed?
-        conjunctionTraversal.getSteps().stream()
-                .filter(step -> step instanceof TraversalParent)
-                .filter(step -> !(step instanceof XMatchStep))
-                .forEach(step -> {
-                    ((TraversalParent) step).getGlobalChildren().forEach(this::addSelectOneStartStep);
-                    ((TraversalParent) step).getLocalChildren().forEach(this::addSelectOneStartStep);
-                });
     }
 
     public Set<String> getMatchStartLabels() {