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

[4/8] incubator-tinkerpop git commit: P now has toString(), hashCode(), and equals() implemented.

P now has toString(), hashCode(), and equals() implemented.


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

Branch: refs/heads/master
Commit: 4be24b6109b832c073f0c863c0d6d752d3e15f90
Parents: 1cdcf1f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 24 14:07:41 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 24 14:07:41 2015 -0600

----------------------------------------------------------------------
 .../org/apache/tinkerpop/gremlin/structure/P.java | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4be24b61/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 43fcd5a..f0e162e 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
@@ -48,10 +48,28 @@ public class P<V> implements Predicate<V>, Serializable {
         return this.value;
     }
 
+    @Override
     public boolean test(final V testValue) {
         return this.biPredicate.test(testValue, this.value);
     }
 
+    @Override
+    public int hashCode() {
+        return this.biPredicate.hashCode() + this.value.hashCode();
+    }
+
+    @Override
+    public boolean equals(final Object other) {
+        return other instanceof P && (
+                (P) other).getBiPredicate().equals(this.biPredicate) &&
+                ((((P) other).getValue() == null && this.getValue() == null) || ((P) other).getValue().equals(this.getValue()));
+    }
+
+    @Override
+    public String toString() {
+        return this.biPredicate.toString() + "(" + this.value + ")";
+    }
+
     //////////////// statics
 
     public static <V> P<V> eq(final V value) {