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/05/16 00:52:58 UTC
incubator-tinkerpop git commit: added back hasNot(key) which is
simply where(not(values(key))). Moreover,
Contains.within null no longer exist. It was an ugly hack -- has(key) and
hasNot(key) are just where() conversions.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 5609de750 -> 78d4d4b60
added back hasNot(key) which is simply where(not(values(key))). Moreover, Contains.within null no longer exist. It was an ugly hack -- has(key) and hasNot(key) are just where() conversions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/78d4d4b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/78d4d4b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/78d4d4b6
Branch: refs/heads/master
Commit: 78d4d4b604110a249da98104ba1ad1efe32d2f33
Parents: 5609de7
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri May 15 16:52:51 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri May 15 16:52:51 2015 -0600
----------------------------------------------------------------------
docs/src/the-graph.asciidoc | 2 +-
docs/src/the-traversal.asciidoc | 1 +
.../traversal/dsl/graph/GraphTraversal.java | 9 ++-
.../gremlin/process/traversal/dsl/graph/__.java | 12 ++--
.../traversal/step/util/HasContainer.java | 76 ++++++++------------
.../apache/tinkerpop/gremlin/structure/P.java | 4 +-
.../step/filter/ConjunctionStepTest.java | 4 +-
7 files changed, 44 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/docs/src/the-graph.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-graph.asciidoc b/docs/src/the-graph.asciidoc
index 3c32f97..aeefbea 100644
--- a/docs/src/the-graph.asciidoc
+++ b/docs/src/the-graph.asciidoc
@@ -125,7 +125,7 @@ image::the-crew-graph.png[width=685]
----
g.V().as('a').
properties('location').as('b').
- where(not(values('endTime'))).as('c').
+ hasNot('endTime').as('c').
select().by('name').by(value).by('startTime') // determine the current location of each person
g.V().has('name','gremlin').inE('uses').
order().by('skill',incr).as('a').
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index 661a15e..ca01fc4 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -539,6 +539,7 @@ It is possible to filter vertices, edges, and vertex properties based on their p
* `hasKey(keys...)`: Remove the traverser if its property does not have any of the keys.
* `hasValue(values...)`: Remove the traverser if its property does not have any of the values.
* `has(key)`: Remove the traverser if its element does not have a value for the key.
+ * `hasNot(key)`: Remove the traverser if its element has a value for the key.
* `has(key, traversal)`: Remove the traverser if its object does not yield a result through the traversal off the property value.
[gremlin-groovy,modern]
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/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 9139263..66da1c3 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
@@ -127,7 +127,6 @@ import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
-import org.javatuples.Pair;
import java.util.Arrays;
import java.util.Comparator;
@@ -483,7 +482,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
}
public default GraphTraversal<S, E> has(final String key, final Object value) {
- return this.has(key, value instanceof P ? (P) value : P.eq(value));
+ return this.has(key, value instanceof P ? (P) value : P.eq(value));
}
public default GraphTraversal<S, E> has(final T accessor, final Object value) {
@@ -499,7 +498,11 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
}
public default GraphTraversal<S, E> has(final String key) {
- return this.has(key, P.within());
+ return this.where(__.values(key));
+ }
+
+ public default GraphTraversal<S, E> hasNot(final String key) {
+ return this.where(P.not(__.values(key)));
}
public default GraphTraversal<S, E> hasLabel(final String... labels) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/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 da5c07d..177e2a9 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
@@ -302,14 +302,6 @@ public class __ {
return __.<A>start().dedup(scope);
}
- public static <A> GraphTraversal<A, A> has(final String key, final Traversal hasNextTraversal) {
- return __.<A>start().has(key, hasNextTraversal);
- }
-
- public static <A> GraphTraversal<A, A> hasNot(final String key, final Traversal hasNotNextTraversal) {
- return __.<A>start().hasNot(key, hasNotNextTraversal);
- }
-
public static <A> GraphTraversal<A, A> has(final String key, final P<?> predicate) {
return __.<A>start().has(key, predicate);
}
@@ -338,6 +330,10 @@ public class __ {
return __.<A>start().has(key);
}
+ public static <A> GraphTraversal<A, A> hasNot(final String key) {
+ return __.<A>start().hasNot(key);
+ }
+
public static <A> GraphTraversal<A, A> hasLabel(final String... labels) {
return __.<A>start().hasLabel(labels);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
index b41e280..ea4a93e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
@@ -18,7 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.step.util;
-import org.apache.tinkerpop.gremlin.structure.Contains;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.P;
import org.apache.tinkerpop.gremlin.structure.Property;
@@ -56,68 +55,49 @@ public final class HasContainer implements Serializable {
// separately
if (this.key.equals(T.id.getAccessor()) && value instanceof Collection)
valuesToStringed = IteratorUtils.set(IteratorUtils.map(((Collection<Object>) value).iterator(), Object::toString));
-
- /*if (null == this.value && !(this.predicate instanceof Contains)) {
- throw new IllegalArgumentException("For determining the existence of a property, use the Contains predicate with null-value");
- }*/
}
public boolean test(final Element element) {
- if (null != this.value) {
- // it is OK to evaluate equality of ids via toString() now given that the toString() the test suite
- // enforces the value of id().toString() to be a first class representation of the identifier
- if (this.key.equals(T.id.getAccessor()))
- if (value instanceof Collection)
- return this.predicate.test(element.id().toString(), valuesToStringed);
- else
- return this.predicate.test(element.id().toString(), this.value.toString());
- else if (this.key.equals(T.label.getAccessor()))
- return this.predicate.test(element.label(), this.value);
- else if (element instanceof VertexProperty && this.key.equals(T.value.getAccessor()))
- return this.predicate.test(((VertexProperty) element).value(), this.value);
- else if (element instanceof VertexProperty && this.key.equals(T.key.getAccessor()))
- return this.predicate.test(((VertexProperty) element).key(), this.value);
- else {
- if (element instanceof Vertex) {
- final Iterator<? extends Property> itty = element.properties(this.key);
- while (itty.hasNext()) {
- if (this.predicate.test(itty.next().value(), this.value))
- return true;
- }
- return false;
- } else {
- final Property property = element.property(this.key);
- return property.isPresent() && this.predicate.test(property.value(), this.value);
+ // it is OK to evaluate equality of ids via toString() now given that the toString() the test suite
+ // enforces the value of id().toString() to be a first class representation of the identifier
+ if (this.key.equals(T.id.getAccessor()))
+ if (value instanceof Collection)
+ return this.predicate.test(element.id().toString(), valuesToStringed);
+ else
+ return this.predicate.test(element.id().toString(), this.value.toString());
+ else if (this.key.equals(T.label.getAccessor()))
+ return this.predicate.test(element.label(), this.value);
+ else if (element instanceof VertexProperty && this.key.equals(T.value.getAccessor()))
+ return this.predicate.test(((VertexProperty) element).value(), this.value);
+ else if (element instanceof VertexProperty && this.key.equals(T.key.getAccessor()))
+ return this.predicate.test(((VertexProperty) element).key(), this.value);
+ else {
+ if (element instanceof Vertex) {
+ final Iterator<? extends Property> itty = element.properties(this.key);
+ while (itty.hasNext()) {
+ if (this.predicate.test(itty.next().value(), this.value))
+ return true;
}
+ return false;
+ } else {
+ final Property property = element.property(this.key);
+ return property.isPresent() && this.predicate.test(property.value(), this.value);
}
- } else {
- return Contains.within.equals(this.predicate) ?
- element.property(this.key).isPresent() :
- !element.property(this.key).isPresent();
}
}
- // note that if the user is looking for a label property key (e.g.), then it will look the same as looking for the label of the element.
public String toString() {
- return this.value == null ?
- (this.predicate == Contains.within ?
- '[' + this.key + ']' :
- "[!" + this.key + ']') :
- '[' + this.key + ',' + this.predicate + ',' + this.value + ']';
+ return null == this.value ? '[' + this.key + ',' + this.predicate + ']' : '[' + this.key + ',' + this.predicate + ',' + this.value + ']';
}
////////////
public static boolean testAll(final Element element, final List<HasContainer> hasContainers) {
- if (hasContainers.size() == 0)
- return true;
- else {
- for (final HasContainer hasContainer : hasContainers) {
- if (!hasContainer.test(element))
- return false;
- }
- return true;
+ for (final HasContainer hasContainer : hasContainers) {
+ if (!hasContainer.test(element))
+ return false;
}
+ return true;
}
public static HasContainer[] makeHasContainers(final String key, final P<?> predicate) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
index e24f813..9af3592 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
@@ -153,7 +153,7 @@ public class P<V> implements Predicate<V>, Serializable, Cloneable {
}
public static <V> P<V> within(final V... values) {
- return new P(Contains.within, values.length == 0 ? null : Arrays.asList(values));
+ return P.within(Arrays.asList(values));
}
public static <V> P<V> within(final Collection<V> value) {
@@ -161,7 +161,7 @@ public class P<V> implements Predicate<V>, Serializable, Cloneable {
}
public static <V> P<V> without(final V... values) {
- return new P(Contains.without, values.length == 0 ? null : Arrays.asList(values));
+ return P.without(Arrays.asList(values));
}
public static <V> P<V> without(final Collection<V> value) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/78d4d4b6/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/ConjunctionStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/ConjunctionStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/ConjunctionStepTest.java
index ee3802c..d71b4a0 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/ConjunctionStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/ConjunctionStepTest.java
@@ -36,7 +36,7 @@ public class ConjunctionStepTest {
@Test
public void shouldGetHasContainers() {
- final GraphTraversal.Admin<?, ?> traversal = and(has("name"), has("age", P.gt(30)).or(has("lang", "java"))).asAdmin();
+ final GraphTraversal.Admin<?, ?> traversal = and(has("name", "marko"), has("age", P.gt(30)).or(has("lang", "java"))).asAdmin();
assertTrue(((ConjunctionStep) traversal.getStartStep()).isConjunctionHasTree());
final ConjunctionStep.ConjunctionTree conjunctionTree = (((ConjunctionStep<?>) traversal.getStartStep()).getConjunctionHasTree());
final Iterator<ConjunctionStep.ConjunctionTree.Entry> iterator = conjunctionTree.iterator();
@@ -63,7 +63,7 @@ public class ConjunctionStepTest {
@Test
public void shouldNotGetHasContainers() {
- final GraphTraversal.Admin<?, ?> traversal = and(has("name"), has("age", P.gt(30)).or(has("lang", "java"), out().has("name", "josh"))).asAdmin();
+ final GraphTraversal.Admin<?, ?> traversal = and(has("name", "marko"), has("age", P.gt(30)).or(has("lang", "java"), out().has("name", "josh"))).asAdmin();
assertFalse(((ConjunctionStep) traversal.getStartStep()).isConjunctionHasTree());
}
}