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/05 17:00:22 UTC

[1/4] tinkerpop git commit: TINKERPOP-2056 Made use of `NumberHelper` in `Compare` predicates.

Repository: tinkerpop
Updated Branches:
  refs/heads/master 813ab73e6 -> 77c7a4f87


TINKERPOP-2056 Made use of `NumberHelper` in `Compare` predicates.


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

Branch: refs/heads/master
Commit: 99d836b357c6036d7f0c175537f0d1d8720fecdf
Parents: fcbce50
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu Oct 4 07:07:27 2018 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Thu Oct 4 13:00:35 2018 -0700

----------------------------------------------------------------------
 .../gremlin/process/traversal/Compare.java      | 63 ++++++--------------
 .../gremlin/process/traversal/PTest.java        | 10 +++-
 2 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/99d836b3/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
index 7d0d071..4b9063f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal;
 
-import java.math.BigDecimal;
 import java.util.function.BiPredicate;
 
 /**
@@ -28,14 +27,13 @@ import java.util.function.BiPredicate;
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  * @author Stephen Mallette (http://stephen.genoprime.com)
  * @author Matt Frantz (http://github.com/mhfrantz)
+ * @author Daniel Kuppitz (http://gemlin.guru)
  */
 public enum Compare implements BiPredicate<Object, Object> {
+
     /**
-     * Evaluates if the first object is equal to the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#compareTo}.  Otherwise they are evaluated
-     * via {@link Object#equals(Object)}.  Testing against {@link Number#doubleValue()} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is equal to the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -43,8 +41,7 @@ public enum Compare implements BiPredicate<Object, Object> {
         @Override
         public boolean test(final Object first, final Object second) {
             return null == first ? null == second : (first instanceof Number && second instanceof Number
-                    && !first.getClass().equals(second.getClass())
-                    ? big((Number) first).compareTo(big((Number) second)) == 0
+                    ? NumberHelper.compare((Number) first, (Number) second) == 0
                     : first.equals(second));
         }
 
@@ -58,11 +55,8 @@ public enum Compare implements BiPredicate<Object, Object> {
     },
 
     /**
-     * Evaluates if the first object is not equal to the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#equals}.  Otherwise they are evaluated
-     * via {@link Object#equals(Object)}.  Testing against {@link Number#doubleValue()} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is not equal to the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -82,11 +76,8 @@ public enum Compare implements BiPredicate<Object, Object> {
     },
 
     /**
-     * Evaluates if the first object is greater than the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#compareTo}.  Otherwise they are evaluated
-     * via {@link Comparable#compareTo(Object)}.  Testing against {@link BigDecimal#compareTo} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is greater than the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -94,8 +85,8 @@ public enum Compare implements BiPredicate<Object, Object> {
         @Override
         public boolean test(final Object first, final Object second) {
             return null != first && null != second && (
-                    first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
-                            ? big((Number) first).compareTo(big((Number) second)) > 0
+                    first instanceof Number && second instanceof Number
+                            ? NumberHelper.compare((Number) first, (Number) second) > 0
                             : ((Comparable) first).compareTo(second) > 0);
         }
 
@@ -109,11 +100,8 @@ public enum Compare implements BiPredicate<Object, Object> {
     },
 
     /**
-     * Evaluates if the first object is greater-equal to the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#compareTo}.  Otherwise they are evaluated
-     * via {@link Comparable#compareTo(Object)}.  Testing against {@link BigDecimal#compareTo} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is greater-equal to the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -133,11 +121,8 @@ public enum Compare implements BiPredicate<Object, Object> {
     },
 
     /**
-     * Evaluates if the first object is less than the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#compareTo}.  Otherwise they are evaluated
-     * via {@link Comparable#compareTo(Object)}.  Testing against {@link BigDecimal#compareTo} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is less than the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -145,8 +130,8 @@ public enum Compare implements BiPredicate<Object, Object> {
         @Override
         public boolean test(final Object first, final Object second) {
             return null != first && null != second && (
-                    first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
-                            ? big((Number) first).compareTo(big((Number) second)) < 0
+                    first instanceof Number && second instanceof Number
+                            ? NumberHelper.compare((Number) first, (Number) second) < 0
                             : ((Comparable) first).compareTo(second) < 0);
         }
 
@@ -160,11 +145,8 @@ public enum Compare implements BiPredicate<Object, Object> {
     },
 
     /**
-     * Evaluates if the first object is less-equal to the second.  If both are of type {@link Number} but not of the
-     * same class (i.e. double for the first object and long for the second object) both values are converted to
-     * {@link BigDecimal} so that it can be evaluated via {@link BigDecimal#compareTo}.  Otherwise they are evaluated
-     * via {@link Comparable#compareTo(Object)}.  Testing against {@link BigDecimal#compareTo} enables the compare
-     * operations to be a bit more forgiving with respect to comparing different number types.
+     * Evaluates if the first object is less-equal to the second. If both are of type {@link Number}, {@link NumberHelper}
+     * will be used for the comparison, thus enabling the comparison of only values, ignoring the number types.
      *
      * @since 3.0.0-incubating
      */
@@ -188,11 +170,4 @@ public enum Compare implements BiPredicate<Object, Object> {
      */
     @Override
     public abstract Compare negate();
-
-    /**
-     * Convert Number to BigDecimal.
-     */
-    private static BigDecimal big(final Number n) {
-        return new BigDecimal(n.toString());
-    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/99d836b3/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
index 6ec33cc..b65d320 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
@@ -29,6 +29,7 @@ import org.junit.runners.Parameterized;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Random;
 import java.util.function.Predicate;
 
@@ -109,8 +110,13 @@ public class PTest {
         @Test
         public void shouldTest() {
             assertEquals(expected, predicate.test(value));
-            assertEquals(!expected, predicate.clone().negate().test(value));
-            assertEquals(!expected, P.not(predicate).test(value));
+            assertNotEquals(expected, predicate.clone().negate().test(value));
+            assertNotEquals(expected, P.not(predicate.clone()).test(value));
+            if (value instanceof Number && !(predicate.biPredicate instanceof Contains)) {
+                assertEquals(expected, predicate.test(((Number) value).longValue()));
+                assertNotEquals(expected, predicate.clone().negate().test(((Number) value).longValue()));
+                assertNotEquals(expected, P.not(predicate).test(((Number) value).longValue()));
+            }
         }
 
         @Before


[2/4] tinkerpop git commit: Merge branch 'TINKERPOP-2056' into tp32

Posted by dk...@apache.org.
Merge branch 'TINKERPOP-2056' into tp32


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

Branch: refs/heads/master
Commit: 21059b9b6b227d6781a6678b60d5c42f25127f6e
Parents: 4bdb006 99d836b
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Fri Oct 5 09:59:44 2018 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri Oct 5 09:59:44 2018 -0700

----------------------------------------------------------------------
 .../gremlin/process/traversal/Compare.java      | 63 ++++++--------------
 .../gremlin/process/traversal/PTest.java        | 10 +++-
 2 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------



[3/4] tinkerpop git commit: Merge branch 'tp32' into tp33

Posted by dk...@apache.org.
Merge branch 'tp32' into tp33


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

Branch: refs/heads/master
Commit: 02e0b8b33c6698cefa62d03f237f5dbe0b1ab9e3
Parents: d9ccefc 21059b9
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Fri Oct 5 09:59:58 2018 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri Oct 5 09:59:58 2018 -0700

----------------------------------------------------------------------
 .../gremlin/process/traversal/Compare.java      | 63 ++++++--------------
 .../gremlin/process/traversal/PTest.java        | 10 +++-
 2 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------



[4/4] tinkerpop git commit: Merge branch 'tp33'

Posted by dk...@apache.org.
Merge branch 'tp33'


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

Branch: refs/heads/master
Commit: 77c7a4f87e763b0e5e8ffa900b04a624ef16975c
Parents: 813ab73 02e0b8b
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Fri Oct 5 10:00:15 2018 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri Oct 5 10:00:15 2018 -0700

----------------------------------------------------------------------
 .../gremlin/process/traversal/Compare.java      | 63 ++++++--------------
 .../gremlin/process/traversal/PTest.java        | 10 +++-
 2 files changed, 27 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/77c7a4f8/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/PTest.java
----------------------------------------------------------------------