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/04/24 22:49:37 UTC

[6/8] incubator-tinkerpop git commit: where(a,neq(b))

where(a,neq(b))


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

Branch: refs/heads/master
Commit: eb78cfdef00dca5cbdbd9c651e1d926148f1233a
Parents: 83fec55
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 24 14:37:56 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 24 14:37:56 2015 -0600

----------------------------------------------------------------------
 docs/src/the-traversal.asciidoc                 | 28 ++++++++++----------
 .../traversal/dsl/graph/GraphTraversal.java     |  8 ++----
 .../gremlin/process/traversal/dsl/graph/__.java |  8 ++----
 .../traversal/step/filter/WhereStep.java        | 11 ++++----
 .../traversal/step/filter/WhereTest.java        |  6 ++---
 .../process/traversal/step/map/MatchTest.java   |  4 +--
 6 files changed, 29 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index 270d4dd..0a0d60b 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -313,7 +313,7 @@ The `choose()`-step (*branch*) routes the current traverser to a particular trav
 [gremlin-groovy,modern]
 ----
 g.V().hasLabel('person').
-      choose(values('age').is(lte, 30),
+      choose(values('age').is(lte(30)),
         __.in(),
         __.out()).values('name') <1>
 g.V().hasLabel('person').
@@ -519,7 +519,7 @@ image::has-step.png[width=670]
 It is possible to filter vertices, edges, and vertex properties based on their properties using `has()`-step (*filter*). There are numerous variations on `has()` including:
 
   * `has(key,value)`: Remove the traverser if its element does not have the provided key/value property.
-  * `has(key,bi-predicate,object)`: Remove the traverser if its element does not have a key value that satisfies the bi-predicate.
+  * `has(key,predicate)`: Remove the traverser if its element does not have a key value that satisfies the bi-predicate.
   * `hasLabel(labels...)`: Remove the traverser if its element does not have any of the labels.
   * `hasId(ids...)`: Remove the traverser if its element does not have any of the ids.
   * `hasKey(keys...)`: Remove the traverser if its property does not have any of the keys.
@@ -531,11 +531,11 @@ It is possible to filter vertices, edges, and vertex properties based on their p
 [gremlin-groovy,modern]
 ----
 g.V().hasLabel('person')
-g.V().hasLabel('person').out().has('name',within,['vadas','josh'])
+g.V().hasLabel('person').out().has('name',within('vadas','josh'))
 g.V().hasLabel('person').out().has('name',within,['vadas','josh']).
       outE().hasLabel('created')
-g.V().has('age',inside,[20,30]).values('age') <1>
-g.V().has('age',outside,[20,30]).values('age') <2>
+g.V().has('age',inside(20,30)).values('age') <1>
+g.V().has('age',outside(20,30)).values('age') <2>
 ----
 
 <1> Find all vertices whose ages are between 20 (inclusive) and 30 (exclusive).
@@ -547,7 +547,7 @@ It is also possible to filter any arbitrary object based on a anonymous traversa
 ----
 g.V().has(out('created')).values('name') <1>
 g.V().out('knows').has(out('created')).values('name') <2>
-g.V().has(out('created').count().is(gte, 2L)).values('name') <3>
+g.V().has(out('created').count().is(gte(2L))).values('name') <3>
 g.V().has(out('knows').has(out('created'))).values('name') <4>
 ----
 
@@ -591,12 +591,12 @@ It is possible to filter scalar values using `is()`-step (*filter*).
 [gremlin-groovy,modern]
 ----
 g.V().values('age').is(32)
-g.V().values('age').is(lte, 30)
-g.V().values('age').is(inside, [30, 40])
+g.V().values('age').is(lte(30))
+g.V().values('age').is(inside(30, 40))
 g.V().has(__.in('created').count().is(1l)).values('name') <1>
-g.V().has(__.in('created').count().is(gte, 2l)).values('name') <2>
+g.V().has(__.in('created').count().is(gte(2l))).values('name') <2>
 g.V().has(__.in('created').values('age').
-                           mean().is(inside, [30d, 35d])).values('name') <3>
+                           mean().is(inside(30d, 35d))).values('name') <3>
 ----
 
 <1> Find projects having exactly one contributor.
@@ -741,7 +741,7 @@ Match is typically used in conjunction with both `select()` (demonstrated previo
 g.V().match('a',
         __.as('a').out('created').as('b'),
         __.as('b').in('created').as('c')).
-          where('a', neq, 'c').select('a','c').by('name')
+          where('a', neq('c')).select('a','c').by('name')
 ----
 
 The `where()`-step can take either a `BiPredicate` (first example below) or a `Traversal` (second example below). Using `MatchWhereStrategy`, `where()`-clauses can be automatically folded into `match()` and thus, subject to `match()`-steps budget-match algorithm.
@@ -820,7 +820,7 @@ The `or()`-step ensures that at least one of the provided traversals yield a res
 ----
 g.V().or(
    __.outE('created'),
-   __.inE('created').count().is(gt,1l)).
+   __.inE('created').count().is(gt(1l))).
      values('name')
 ----
 
@@ -1181,10 +1181,10 @@ Finally, like <<match-step,`match()`>>-step, it is possible to use `where()`, as
 ----
 g.V().as('a').out('created').in('created').as('b').select().by('name') <1>
 g.V().as('a').out('created').in('created').as('b').
-      select().by('name').where('a',neq,'b') <2>
+      select().by('name').where('a',neq('b')) <2>
 g.V().as('a').out('created').in('created').as('b').
       select(). <3>
-      where('a',neq,'b').
+      where('a',neq('b')).
       where(__.as('a').out('knows').as('b')).
       select().by('name')
 ----

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index b57baae..0f7204c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -447,12 +447,8 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         return this.asAdmin().addStep(new ExceptStep<>(this.asAdmin(), exceptCollection));
     }
 
-    public default <E2> GraphTraversal<S, Map<String, E2>> where(final String firstKey, final String secondKey, final BiPredicate predicate) {
-        return this.asAdmin().addStep(new WhereStep(this.asAdmin(), firstKey, secondKey, predicate));
-    }
-
-    public default <E2> GraphTraversal<S, Map<String, E2>> where(final String firstKey, final BiPredicate predicate, final String secondKey) {
-        return this.where(firstKey, secondKey, predicate);
+    public default <E2> GraphTraversal<S, Map<String, E2>> where(final String firstKey, final P<?> predicate) {
+        return this.asAdmin().addStep(new WhereStep<>(this.asAdmin(), firstKey, predicate));
     }
 
     public default <E2> GraphTraversal<S, Map<String, E2>> where(final Traversal constraint) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index eb512df..c869d48 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -366,12 +366,8 @@ public class __ {
         return __.<A>start().hasValue(values);
     }
 
-    public static <A, E2> GraphTraversal<A, Map<String, E2>> where(final String firstKey, final String secondKey, final BiPredicate predicate) {
-        return __.<A>start().where(firstKey, secondKey, predicate);
-    }
-
-    public static <A, E2> GraphTraversal<A, Map<String, E2>> where(final String firstKey, final BiPredicate predicate, final String secondKey) {
-        return __.<A>start().where(firstKey, predicate, secondKey);
+    public static <A, E2> GraphTraversal<A, Map<String, E2>> where(final String firstKey, final P<?> secondKeyPredicate) {
+        return __.<A>start().where(firstKey, secondKeyPredicate);
     }
 
     public static <A, E2> GraphTraversal<A, Map<String, E2>> where(final Traversal constraint) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
index 14c541a..8414001 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
@@ -21,10 +21,11 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.filter;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.MarkerIdentityStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.MarkerIdentityStep;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.P;
 
 import java.util.Collections;
 import java.util.List;
@@ -43,11 +44,11 @@ public final class WhereStep<E> extends FilterStep<Map<String, E>> implements Tr
     private Traversal.Admin constraint;
 
 
-    public WhereStep(final Traversal.Admin traversal, final String firstKey, final String secondKey, final BiPredicate<E, E> biPredicate) {
+    public WhereStep(final Traversal.Admin traversal, final String firstKey, final P<?> secondKeyPredicate) {
         super(traversal);
         this.firstKey = firstKey;
-        this.secondKey = secondKey;
-        this.biPredicate = biPredicate;
+        this.secondKey = (String) secondKeyPredicate.getValue();
+        this.biPredicate = secondKeyPredicate.getBiPredicate();
         this.constraint = null;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
index da75411..0b5ffef 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTest.java
@@ -24,7 +24,7 @@ import org.apache.tinkerpop.gremlin.process.IgnoreEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.UseEngine;
-import org.apache.tinkerpop.gremlin.structure.Compare;
+import static org.apache.tinkerpop.gremlin.structure.P.*;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
 
@@ -140,12 +140,12 @@ public abstract class WhereTest extends AbstractGremlinProcessTest {
 
         @Override
         public Traversal<Vertex, Map<String, Object>> get_g_V_hasXageX_asXaX_out_in_hasXageX_asXbX_select_whereXa_eq_bX() {
-            return g.V().has("age").as("a").out().in().has("age").as("b").select().where("a", Compare.eq, "b");
+            return g.V().has("age").as("a").out().in().has("age").as("b").select().where("a", eq("b"));
         }
 
         @Override
         public Traversal<Vertex, Map<String, Object>> get_g_V_hasXageX_asXaX_out_in_hasXageX_asXbX_select_whereXa_neq_bX() {
-            return g.V().has("age").as("a").out().in().has("age").as("b").select().where("a", Compare.neq, "b");
+            return g.V().has("age").as("a").out().in().has("age").as("b").select().where("a", eq("b"));
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/eb78cfde/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchTest.java
index 3be7759..4393a8e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchTest.java
@@ -34,7 +34,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.match.IteratorEnu
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.match.MatchStep;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.MapHelper;
-import org.apache.tinkerpop.gremlin.structure.Compare;
+import static org.apache.tinkerpop.gremlin.structure.P.*;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
 
@@ -780,7 +780,7 @@ public abstract class MatchTest extends AbstractGremlinProcessTest {
             return g.V().match("a",
                     as("a").out("created").as("b"),
                     as("b").in("created").as("c"))
-                    .where("a", Compare.neq, "c")
+                    .where("a", neq("c"))
                     .<String>select("a", "c").by("name");
         }