added support for Path.getSubPath(). Added FromToModulating for from() and 
to()-based step modulations. Added support for path().from().to(). Added 
respective test cases. Going to add simplePath().from().to().by() and 
cyclicPath().from().to().by() to this ticket as well and then PR this mo fo ya 
know.


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

Branch: refs/heads/TINKERPOP-1625
Commit: 9265ddf6d1e5bded0ef6b3a0229ea1ce405e5259
Parents: 60a3fb3
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Thu Mar 16 08:40:39 2017 -0600
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Thu Mar 16 08:40:39 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   3 +
 .../gremlin/process/traversal/Path.java         |  35 ++
 .../traversal/dsl/graph/GraphTraversal.java     | 398 +++++++++----------
 .../traversal/step/FromToModulating.java        |  49 +++
 .../process/traversal/step/map/AddEdgeStep.java |  19 +-
 .../process/traversal/step/map/PathStep.java    |  29 +-
 .../gremlin/process/traversal/PathTest.java     |  65 ++-
 .../traversal/step/map/GroovyPathTest.groovy    |   5 +
 .../process/traversal/step/map/PathTest.java    |  20 +
 9 files changed, 407 insertions(+), 216 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9265ddf6/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6861d57..1eaf3ad 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,9 @@ 
image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.5 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added `path().from().to()` to `GraphTraversal` so sub-paths can be isolated 
from the current path.
+* Added `FromToModulating` interface for use with `to()`- and `from()`-based 
step modulators.
+* Added `Path.getSubPath()` which supports isolating a sub-path from `Path` 
via to/from-labels.
 * Fixed an `NullPointerException` in `GraphMLReader` that occurred when an 
`<edge>` didn't have an ID field and the base graph supported ID assignment.
 * Split `ComputerVerificationStrategy` into two strategies: 
`ComputerVerificationStrategy` and `ComputerFinalizationStrategy`.
 * Removed `HasTest.g_V_hasId_compilationEquality` from process test suite as 
it makes too many assumptions about provider compilation.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9265ddf6/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 b2916d9..df46800 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
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal;
 
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.javatuples.Pair;
 
@@ -238,10 +239,44 @@ public interface Path extends Cloneable, Iterable<Object> 
{
                 isPresent();
     }
 
+    public default Path getSubPath(final String fromLabel, final String 
toLabel) {
+        if (null == fromLabel && null == toLabel)
+            return this;
+        else {
+            Path subPath = MutablePath.make();
+            boolean record = false;
+            int size = this.size();
+            for (int i = 0; i < size; i++) {
+                final Set<String> labels = this.labels().get(i);
+                if (labels.contains(fromLabel) || null == fromLabel)
+                    record = true;
+                if (record)
+                    subPath = subPath.extend(this.get(i), labels);
+                if (labels.contains(toLabel)) {
+                    if (!record)
+                        throw 
Path.Exceptions.couldNotLocalPathFromLabel(fromLabel);
+                    return subPath;
+                }
+            }
+            if (null == toLabel)
+                return subPath;
+            else
+                throw Path.Exceptions.couldNotLocalPathToLabel(toLabel);
+        }
+    }
+
     public static class Exceptions {
 
         public static IllegalArgumentException 
stepWithProvidedLabelDoesNotExist(final String label) {
             return new IllegalArgumentException("The step with label " + label 
+ " does not exist");
         }
+
+        public static IllegalArgumentException 
couldNotLocalPathFromLabel(final String fromLabel) {
+            return new IllegalArgumentException("Could not local path 
from-label: " + fromLabel);
+        }
+
+        public static IllegalArgumentException couldNotLocalPathToLabel(final 
String toLabel) {
+            return new IllegalArgumentException("Could not local path 
to-label: " + toLabel);
+        }
     }
 }

Reply via email to