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/02/17 13:43:45 UTC

incubator-tinkerpop git commit: GraphTraversalSource, for all its withXXX-methods, simply calls TraversalSource.super.withXXX. Now that we have TraversalSource.getStrategies(), its super easy.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1154 86284f2c8 -> 969472f06


GraphTraversalSource, for all its withXXX-methods, simply calls TraversalSource.super.withXXX. Now that we have TraversalSource.getStrategies(), its super easy.


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

Branch: refs/heads/TINKERPOP-1154
Commit: 969472f065f8d4a6792a512f9c3bbcc9d2c3ceb6
Parents: 86284f2
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Feb 17 05:43:40 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Feb 17 05:43:40 2016 -0700

----------------------------------------------------------------------
 .../process/traversal/TraversalSource.java      | 59 +++++++++++++-------
 .../dsl/graph/GraphTraversalSource.java         | 24 ++------
 2 files changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/969472f0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
index 8d8470c..b52dbbe 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
@@ -19,7 +19,10 @@
 package org.apache.tinkerpop.gremlin.process.traversal;
 
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ComputerVerificationStrategy;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
 
@@ -62,13 +65,40 @@ public interface TraversalSource extends Cloneable {
     /////////////////////////////
 
     /**
+     * Add an arbitrary collection of {@link TraversalStrategy} instances to the traversal source.
+     *
+     * @param traversalStrategies a colleciton of traversal strategies to add
+     * @return a new traversal source with updated strategies
+     */
+    public default TraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
+        final TraversalSource clone = this.clone();
+        clone.getStrategies().addStrategies(traversalStrategies);
+        return clone;
+    }
+
+    /**
+     * Remove an arbitrary collection of {@link TraversalStrategy} classes from the traversal source.
+     *
+     * @param traversalStrategyClasses a collection of traversal strategy classes to remove
+     * @return a new traversal source with updated strategies
+     */
+    @SuppressWarnings({"unchecked", "varargs"})
+    public default TraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
+        final TraversalSource clone = this.clone();
+        clone.getStrategies().removeStrategies(traversalStrategyClasses);
+        return clone;
+    }
+
+    /**
      * Add a {@link Function} that will generate a {@link GraphComputer} from the {@link Graph} that will be used to execute the traversal.
      * This adds a {@link VertexProgramStrategy} to the strategies.
      *
      * @param graphComputerFunction a function to generate a graph computer from the graph
      * @return a new traversal source with updated strategies
      */
-    public TraversalSource withComputer(final Function<Graph, GraphComputer> graphComputerFunction);
+    public default TraversalSource withComputer(final Function<Graph, GraphComputer> graphComputerFunction) {
+        return this.withStrategies(new VertexProgramStrategy(graphComputerFunction), ComputerVerificationStrategy.instance());
+    }
 
     /**
      * Add a {@link GraphComputer} class used to execute the traversal.
@@ -92,23 +122,6 @@ public interface TraversalSource extends Cloneable {
     }
 
     /**
-     * Add an arbitrary collection of {@link TraversalStrategy} instances to the traversal source.
-     *
-     * @param traversalStrategies a colleciton of traversal strategies to add
-     * @return a new traversal source with updated strategies
-     */
-    public TraversalSource withStrategies(final TraversalStrategy... traversalStrategies);
-
-    /**
-     * Remove an arbitrary collection of {@link TraversalStrategy} classes from the traversal source.
-     *
-     * @param traversalStrategyClasses a collection of traversal strategy classes to remove
-     * @return a new traversal source with updated strategies
-     */
-    @SuppressWarnings({"unchecked", "varargs"})
-    public TraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses);
-
-    /**
      * Add a sideEffect to be used throughout the life of a spawned {@link Traversal}.
      * This adds a {@link org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy} to the strategies.
      *
@@ -116,7 +129,11 @@ public interface TraversalSource extends Cloneable {
      * @param initialValue a supplier that produces the initial value of the sideEffect
      * @return a new traversal source with updated strategies
      */
-    public TraversalSource withSideEffect(final String key, final Supplier initialValue);
+    public default TraversalSource withSideEffect(final String key, final Supplier initialValue) {
+        final TraversalSource clone = this.clone();
+        SideEffectStrategy.addSideEffect(clone.getStrategies(), key, initialValue);
+        return clone;
+    }
 
     /**
      * Add a sideEffect to be used throughout the life of a spawned {@link Traversal}.
@@ -139,7 +156,9 @@ public interface TraversalSource extends Cloneable {
      * @param mergeOperator the sack merge operator
      * @return a new traversal source with updated strategies
      */
-    public <A> TraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator);
+    public default <A> TraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) {
+        return this.withStrategies(SackStrategy.<A>build().initialValue(initialValue).splitOperator(splitOperator).mergeOperator(mergeOperator).create());
+    }
 
     /**
      * Add a sack to be used throughout the life of a spawned {@link Traversal}.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/969472f0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
index e0aa13c..ebe5d79 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
@@ -28,10 +28,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.engine.StandardTraversalEn
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.RequirementsStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.VertexProgramStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ComputerVerificationStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -98,9 +94,7 @@ public class GraphTraversalSource implements TraversalSource {
 
     @Override
     public GraphTraversalSource withComputer(final Function<Graph, GraphComputer> graphComputerFunction) {
-        final GraphTraversalSource clone = this.clone();
-        clone.strategies.addStrategies(new VertexProgramStrategy(graphComputerFunction), ComputerVerificationStrategy.instance());
-        return clone;
+        return (GraphTraversalSource) TraversalSource.super.withComputer(graphComputerFunction);
     }
 
     @Override
@@ -115,24 +109,18 @@ public class GraphTraversalSource implements TraversalSource {
 
     @Override
     public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
-        final GraphTraversalSource clone = this.clone();
-        clone.strategies.addStrategies(traversalStrategies);
-        return clone;
+        return (GraphTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
     }
 
     @Override
     @SuppressWarnings({"unchecked", "varargs"})
     public GraphTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
-        final GraphTraversalSource clone = this.clone();
-        clone.strategies.removeStrategies(traversalStrategyClasses);
-        return clone;
+        return (GraphTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyClasses);
     }
 
     @Override
     public GraphTraversalSource withSideEffect(final String key, final Supplier initialValue) {
-        final GraphTraversalSource clone = this.clone();
-        SideEffectStrategy.addSideEffect(clone.strategies, key, initialValue);
-        return clone;
+        return (GraphTraversalSource) TraversalSource.super.withSideEffect(key, initialValue);
     }
 
     @Override
@@ -142,9 +130,7 @@ public class GraphTraversalSource implements TraversalSource {
 
     @Override
     public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) {
-        final GraphTraversalSource clone = this.clone();
-        clone.strategies.addStrategies(SackStrategy.<A>build().initialValue(initialValue).splitOperator(splitOperator).mergeOperator(mergeOperator).create());
-        return clone;
+        return (GraphTraversalSource) TraversalSource.super.withSack(initialValue, splitOperator, mergeOperator);
     }
 
     @Override