You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2018/10/04 14:19:24 UTC
tinkerpop git commit: TINKERPOP-2058 Use `Compare.eq` in
`Contains.within` to ensure equal filter behaviors.
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-2058 [created] ed7658b06
TINKERPOP-2058 Use `Compare.eq` in `Contains.within` to ensure equal filter behaviors.
If the object to be filtered is a number, `Contains` predicates will now scan the provided collection, comparing
each element using `Compare.eq`. For non-numeric values `Contains.within` will still use `collection.contains()`
in order to make use of search-optimized data types (e.g. `Set`).
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/ed7658b0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/ed7658b0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/ed7658b0
Branch: refs/heads/TINKERPOP-2058
Commit: ed7658b0620f738c7a9877f135ae25290198aa44
Parents: 3a8f580
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu Oct 4 07:15:09 2018 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Thu Oct 4 07:15:09 2018 -0700
----------------------------------------------------------------------
.../gremlin/process/traversal/Contains.java | 16 +++++++++++++---
.../gremlin/process/traversal/ContainsTest.java | 2 +-
2 files changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ed7658b0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
index da46d0b..35a8ca7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
@@ -18,19 +18,27 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
import java.util.Collection;
import java.util.function.BiPredicate;
/**
* {@link Contains} is a {@link BiPredicate} that evaluates whether the first object is contained within (or not
- * within) the second collection object. For example:
+ * within) the second collection object. If the first object is a number, each element in the second collection
+ * will be compared to the first object using {@link Compare}'s {@code eq} predicate. This will ensure, that numbers
+ * are matched by their value only, ignoring the number type. For example:
* <p/>
* <pre>
* gremlin Contains.within [gremlin, blueprints, furnace] == true
* gremlin Contains.without [gremlin, rexster] == false
* rexster Contains.without [gremlin, blueprints, furnace] == true
+ * 123 Contains.within [1, 2, 3] == false
+ * 100 Contains.within [1L, 10L, 100L] == true
* </pre>
*
+ *
+ *
* @author Pierre De Wilde
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
@@ -44,7 +52,9 @@ public enum Contains implements BiPredicate<Object, Collection> {
within {
@Override
public boolean test(final Object first, final Collection second) {
- return second.contains(first);
+ return first instanceof Number
+ ? IteratorUtils.anyMatch(second.iterator(), o -> Compare.eq.test(first, o))
+ : second.contains(first);
}
},
@@ -56,7 +66,7 @@ public enum Contains implements BiPredicate<Object, Collection> {
without {
@Override
public boolean test(final Object first, final Collection second) {
- return !second.contains(first);
+ return !within.test(first, second);
}
};
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/ed7658b0/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/ContainsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/ContainsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/ContainsTest.java
index 6d9ea38..2ea635d 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/ContainsTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/ContainsTest.java
@@ -43,7 +43,7 @@ public class ContainsTest {
{Contains.within, 10, Collections.emptyList(), false},
{Contains.without, 10, Collections.emptyList(), true},
{Contains.within, 100, Arrays.asList(1, 2, 3, 4, 10), false},
- {Contains.without, 10l, Arrays.asList(1, 2, 3, 4, 10), true}, // no forgiveness
+ {Contains.without, 10L, Arrays.asList(1, 2, 3, 4, 10), false},
{Contains.within, "test", Arrays.asList(1, 2, 3, "test", 10), true},
{Contains.without, "testing", Arrays.asList(1, 2, 3, "test", 10), true}
}));