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 2017/03/16 15:34:28 UTC
tinkerpop git commit: PathFilterStep now support by() modulation.
Removed unneeded CyclicPathStepTest and SimplePathStepTest.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1387 936344f33 -> 8ec49c433
PathFilterStep now support by() modulation. Removed unneeded CyclicPathStepTest and SimplePathStepTest.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/8ec49c43
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/8ec49c43
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/8ec49c43
Branch: refs/heads/TINKERPOP-1387
Commit: 8ec49c433ae472116853df12247fa903e41f958d
Parents: 936344f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Mar 16 09:34:25 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Mar 16 09:34:25 2017 -0600
----------------------------------------------------------------------
.../traversal/step/filter/PathFilterStep.java | 71 +++++++++++++++++++-
.../step/filter/CyclicPathStepTest.java | 37 ----------
.../step/filter/PathFilterStepTest.java | 8 ++-
.../step/filter/SimplePathStepTest.java | 37 ----------
4 files changed, 75 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ec49c43/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
index bbc8168..e8e0607 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
@@ -19,32 +19,52 @@
package org.apache.tinkerpop.gremlin.process.traversal.step.filter;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
import org.apache.tinkerpop.gremlin.process.traversal.step.FromToModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.MutablePath;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
-public final class PathFilterStep<S> extends FilterStep<S> implements FromToModulating {
+public final class PathFilterStep<S> extends FilterStep<S> implements FromToModulating, ByModulating, TraversalParent, PathProcessor {
protected String fromLabel;
protected String toLabel;
private boolean isSimple;
+ private TraversalRing<Object, Object> traversalRing;
+ private Set<String> keepLabels;
public PathFilterStep(final Traversal.Admin traversal, final boolean isSimple) {
super(traversal);
+ this.traversalRing = new TraversalRing<>();
this.isSimple = isSimple;
}
@Override
protected boolean filter(final Traverser.Admin<S> traverser) {
- return traverser.path().getSubPath(this.fromLabel, this.toLabel).isSimple() == this.isSimple;
+ final Path path = traverser.path().getSubPath(this.fromLabel, this.toLabel);
+ this.traversalRing.reset();
+ if (this.traversalRing.isEmpty())
+ return path.isSimple() == this.isSimple;
+ else {
+ final Path byPath = MutablePath.make();
+ path.forEach((object, labels) -> byPath.extend(TraversalUtil.applyNullable(object, this.traversalRing.next()), labels));
+ return byPath.isSimple() == this.isSimple;
+
+ }
}
@Override
@@ -62,14 +82,59 @@ public final class PathFilterStep<S> extends FilterStep<S> implements FromToModu
@Override
public String toString() {
- return StringFactory.stepString(this, this.isSimple ? "simple" : "cyclic", this.fromLabel, this.toLabel);
+ return StringFactory.stepString(this, this.isSimple ? "simple" : "cyclic", this.fromLabel, this.toLabel, this.traversalRing);
+ }
+
+ @Override
+ public PathFilterStep<S> clone() {
+ final PathFilterStep<S> clone = (PathFilterStep<S>) super.clone();
+ clone.traversalRing = this.traversalRing.clone();
+ return clone;
+ }
+
+ @Override
+ public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) {
+ super.setTraversal(parentTraversal);
+ this.traversalRing.getTraversals().forEach(this::integrateChild);
+ }
+
+ @Override
+ public List<Traversal.Admin<Object, Object>> getLocalChildren() {
+ return this.traversalRing.getTraversals();
+ }
+
+ @Override
+ public void modulateBy(final Traversal.Admin<?, ?> pathTraversal) {
+ this.traversalRing.addTraversal(this.integrateChild(pathTraversal));
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ this.traversalRing.reset();
}
@Override
public int hashCode() {
return super.hashCode() ^
+ this.traversalRing.hashCode() ^
Boolean.hashCode(this.isSimple) ^
(null == this.fromLabel ? "null".hashCode() : this.fromLabel.hashCode()) ^
(null == this.toLabel ? "null".hashCode() : this.toLabel.hashCode());
}
+
+ @Override
+ public void setKeepLabels(final Set<String> labels) {
+ this.keepLabels = labels;
+ }
+
+ @Override
+ protected Traverser.Admin<S> processNextStart() {
+ return PathProcessor.processTraverserPathLabels(super.processNextStart(), this.keepLabels);
+ }
+
+ @Override
+ public Set<String> getKeepLabels() {
+ return this.keepLabels;
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ec49c43/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStepTest.java
deleted file mode 100644
index c187d3f..0000000
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStepTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.traversal.step.filter;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-public class CyclicPathStepTest extends StepTest {
-
- @Override
- protected List<Traversal> getTraversals() {
- return Collections.singletonList(__.cyclicPath());
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ec49c43/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
index ff994e8..531cfed 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
@@ -38,10 +38,16 @@ public class PathFilterStepTest extends StepTest {
__.simplePath().from("a").to("b"),
__.simplePath().from("a"),
__.simplePath().to("b"),
+ __.simplePath().from("a").by("name").by("age"),
+ __.simplePath().from("a").to("b").by("name").by("age"),
+ __.simplePath().by("name").by("age"),
__.cyclicPath().from("a"),
__.cyclicPath().to("b"),
__.cyclicPath().from("a").to("b"),
- __.cyclicPath()
+ __.cyclicPath(),
+ __.cyclicPath().from("a").by("name").by("age"),
+ __.cyclicPath().from("a").to("b").by("name").by("age"),
+ __.cyclicPath().by("name").by("age")
);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8ec49c43/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStepTest.java
deleted file mode 100644
index 170ad47..0000000
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStepTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.process.traversal.step.filter;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-public class SimplePathStepTest extends StepTest {
-
- @Override
- protected List<Traversal> getTraversals() {
- return Collections.singletonList(__.simplePath());
- }
-}