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 2016/11/03 13:04:40 UTC

[2/3] tinkerpop git commit: added TraversalHelper.applyTraversalRecurssively() as recommended by @dkuppitz. Was apply to replace code in both SubgraphStrategy and IncidentToAdjacentStrategy.

added TraversalHelper.applyTraversalRecurssively() as recommended by @dkuppitz. Was apply to replace code in both SubgraphStrategy and IncidentToAdjacentStrategy.


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

Branch: refs/heads/tp32
Commit: 1dcca1b43d7da88d9cfa677fdc89d26d9fe79b6c
Parents: 6a1a074
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Nov 1 14:48:09 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Nov 1 14:48:09 2016 -0600

----------------------------------------------------------------------
 .../strategy/decoration/SubgraphStrategy.java   | 16 +++------------
 .../IncidentToAdjacentStrategy.java             | 21 +++-----------------
 .../process/traversal/util/TraversalHelper.java | 21 ++++++++++++++++++++
 3 files changed, 27 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1dcca1b4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
index a115b1a..8544a20 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
@@ -105,21 +105,11 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
         this.vertexPropertyCriterion = null == vertexPropertyCriterion ? null : vertexPropertyCriterion.asAdmin().clone();
 
         if (null != this.vertexCriterion)
-            this.addLabelMarker(this.vertexCriterion);
+            TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexCriterion);
         if (null != this.edgeCriterion)
-            this.addLabelMarker(this.edgeCriterion);
+            TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.edgeCriterion);
         if (null != this.vertexPropertyCriterion)
-            this.addLabelMarker(this.vertexPropertyCriterion);
-    }
-
-    private final void addLabelMarker(final Traversal.Admin<?, ?> traversal) {
-        traversal.getStartStep().addLabel(MARKER);
-        for (final Step<?, ?> step : traversal.getSteps()) {
-            if (step instanceof TraversalParent) {
-                ((TraversalParent) step).getLocalChildren().forEach(this::addLabelMarker);
-                ((TraversalParent) step).getGlobalChildren().forEach(this::addLabelMarker);
-            }
-        }
+            TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), this.vertexPropertyCriterion);
     }
 
     private static void applyCriterion(final List<Step> stepsToApplyCriterionAfter, final Traversal.Admin traversal,

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1dcca1b4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
index a4b5450..a0adbdc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
@@ -22,7 +22,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
-import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathStep;
@@ -77,13 +76,9 @@ public final class IncidentToAdjacentStrategy extends AbstractTraversalStrategy<
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
         // using a hidden label marker to denote whether the traversal should not be processed by this strategy
-        if (traversal.getParent() instanceof EmptyStep) {
-            if (TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES, traversal)) {
-                addLabelMarker(traversal);
-                traversal.getStartStep().removeLabel(MARKER);
-                return;
-            }
-        } else if (traversal.getStartStep().getLabels().contains(MARKER)) {
+        if (traversal.getParent() instanceof EmptyStep && TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES, traversal))
+            TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER), traversal);
+        if (traversal.getStartStep().getLabels().contains(MARKER)) {
             traversal.getStartStep().removeLabel(MARKER);
             return;
         }
@@ -103,16 +98,6 @@ public final class IncidentToAdjacentStrategy extends AbstractTraversalStrategy<
         }
     }
 
-    private final void addLabelMarker(final Traversal.Admin<?, ?> traversal) {
-        traversal.getStartStep().addLabel(MARKER);
-        for (final Step<?, ?> step : traversal.getSteps()) {
-            if (step instanceof TraversalParent) {
-                ((TraversalParent) step).getLocalChildren().forEach(this::addLabelMarker);
-                ((TraversalParent) step).getGlobalChildren().forEach(this::addLabelMarker);
-            }
-        }
-    }
-
     /**
      * Checks whether a given step is optimizable or not.
      *

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1dcca1b4/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index f4dd829..e6ba9ca 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -55,6 +55,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
+import java.util.function.Consumer;
 import java.util.function.Predicate;
 
 /**
@@ -445,6 +446,26 @@ public final class TraversalHelper {
         return false;
     }
 
+    /**
+     * Apply the provider {@link Consumer} function to the provided {@link Traversal} and all of its children.
+     *
+     * @param consumer  the function to apply to the each traversal in the tree
+     * @param traversal the root traversal to start application
+     */
+    public static void applyTraversalRecursively(final Consumer<Traversal.Admin<?, ?>> consumer, final Traversal.Admin<?, ?> traversal) {
+        consumer.accept(traversal);
+        for (final Step<?, ?> step : traversal.getSteps()) {
+            if (step instanceof TraversalParent) {
+                for (final Traversal.Admin<?, ?> local : ((TraversalParent) step).getLocalChildren()) {
+                    applyTraversalRecursively(consumer, local);
+                }
+                for (final Traversal.Admin<?, ?> global : ((TraversalParent) step).getGlobalChildren()) {
+                    applyTraversalRecursively(consumer, global);
+                }
+            }
+        }
+    }
+
     public static <S> void addToCollection(final Collection<S> collection, final S s, final long bulk) {
         if (collection instanceof BulkSet) {
             ((BulkSet<S>) collection).add(s, bulk);