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:10 UTC

[09/31] incubator-tinkerpop git commit: no more IsOrAllowStep -- now just a ComputerAware.EndStep -- XMatchEndStep.

no more IsOrAllowStep -- now just a ComputerAware.EndStep -- XMatchEndStep.


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

Branch: refs/heads/master
Commit: 34cf6dbaf7caa699f0932a5f79a502e5d9f5b5eb
Parents: c39be2b
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jun 11 16:37:33 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jun 11 16:37:33 2015 -0600

----------------------------------------------------------------------
 .../step/filter/exp/IsOrAllowStep.java          | 55 --------------------
 .../traversal/step/filter/exp/XMatchStep.java   | 38 ++++++++++++--
 .../traversal/step/util/ComputerAwareStep.java  |  6 ++-
 .../tinkergraph/structure/TinkerGraphTest.java  |  8 ++-
 4 files changed, 45 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/34cf6dba/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/IsOrAllowStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/IsOrAllowStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/IsOrAllowStep.java
deleted file mode 100644
index 9202f86..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/IsOrAllowStep.java
+++ /dev/null
@@ -1,55 +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.exp;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Path;
-import org.apache.tinkerpop.gremlin.process.traversal.Pop;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
-
-import java.util.Optional;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class IsOrAllowStep<S> extends FilterStep<S> {
-
-    private final String key;
-
-    public IsOrAllowStep(final Traversal.Admin traversal, final String key) {
-        super(traversal);
-        this.key = key;
-    }
-
-    @Override
-    protected boolean filter(final Traverser.Admin<S> traverser) {
-        final Optional<S> optional = traverser.getSideEffects().get(this.key);
-        if (optional.isPresent())
-            return traverser.get().equals(optional.get());
-        else {
-            final Path path = traverser.path();
-            return !path.hasLabel(this.key) || traverser.get().equals(path.getSingle(Pop.head, this.key));
-        }
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/34cf6dba/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 be0d94b..6d940e5 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
@@ -78,10 +78,9 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
                     throw new IllegalArgumentException("The end step of a match()-traversal can only have one label: " + endStep);
                 final String label = endStep.getLabels().iterator().next();
                 endStep.removeLabel(label);
-                final Step<?, ?> isOrAllowStep = new IsOrAllowStep<>(andTraversal.asAdmin(), label);      // TODO: perhaps just have a XMatchEndStep private static?
-                isOrAllowStep.addLabel(label);
-                andTraversal.asAdmin().addStep(isOrAllowStep);
-                andTraversal.asAdmin().addStep(new EndStep(andTraversal.asAdmin(), true));
+                final Step<?, ?> step = new XMatchEndStep(andTraversal.asAdmin(), label);
+                step.addLabel(label);
+                andTraversal.asAdmin().addStep(step);
             }
             this.andTraversals.add(this.integrateChild(andTraversal.asAdmin()));
         }
@@ -166,6 +165,37 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
 
     //////////////////////////////
 
+    public class XMatchEndStep extends EndStep {
+
+        private final String matchKey;
+
+        public XMatchEndStep(final Traversal.Admin traversal, final String key) {
+            super(traversal);
+            this.matchKey = key;
+        }
+
+        @Override
+        protected Traverser<S> processNextStart() throws NoSuchElementException {
+            while (true) {
+                final Traverser.Admin<S> start = this.starts.next();
+                final Optional<S> optional = start.getSideEffects().get(this.matchKey);
+                if (optional.isPresent() && start.get().equals(optional.get())) {
+                    if (this.traverserStepIdSetByChild) start.setStepId(XMatchStep.this.getId());
+                    return start;
+                } else {
+                    final Path path = start.path();
+                    if (!path.hasLabel(this.matchKey) || start.get().equals(path.getSingle(Pop.head, this.matchKey))) {
+                        if (this.traverserStepIdSetByChild) start.setStepId(XMatchStep.this.getId());
+                        return start;
+                    }
+                }
+            }
+        }
+    }
+
+
+    //////////////////////////////
+
     public interface MatchAlgorithm extends Function<Traverser.Admin<Object>, Optional<Traversal.Admin<Object, Object>>> {
         public void initialize(final List<Traversal.Admin<Object, Object>> traversals);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/34cf6dba/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ComputerAwareStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ComputerAwareStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ComputerAwareStep.java
index a4bb6d5..0dee51b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ComputerAwareStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ComputerAwareStep.java
@@ -68,13 +68,17 @@ public abstract class ComputerAwareStep<S, E> extends AbstractStep<S, E> impleme
 
     public class EndStep extends AbstractStep<S, S> implements EngineDependent {
 
-        private final boolean returnHome;
+        protected final boolean returnHome;
 
         public EndStep(final Traversal.Admin traversal, final boolean returnHome) {
             super(traversal);
             this.returnHome = returnHome;
         }
 
+        public EndStep(final Traversal.Admin traversal) {
+            this(traversal, false);
+        }
+
         @Override
         protected Traverser<S> processNextStart() throws NoSuchElementException {
             final Traverser.Admin<S> start = this.starts.next();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/34cf6dba/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 0871251..8dd202f 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -155,11 +155,15 @@ public class TinkerGraphTest {
     @Test
     @Ignore
     public void testPlay5() throws Exception {
-        GraphTraversalSource g = TinkerFactory.createModern().traversal(GraphTraversalSource.computer());
+        GraphTraversalSource g = TinkerFactory.createModern().traversal(GraphTraversalSource.standard());
         g.V().as("a").xmatch(
                 as("a").out("knows").as("b"),
                 as("a").out("created").as("c"),
-                as("b").out("created").as("c")).select(Pop.head,"a","b","c").forEachRemaining(System.out::println);
+                as("b").out("created").as("c"),
+                as("c").in("created").as("d"),
+                as("d").where(neq("a")).where(neq("b")),
+                as("b").out("created").has("name","ripple")
+                ).select(Pop.head,"a","b","c","d").by("name").forEachRemaining(System.out::println);
     }
 
     @Test