tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [2/2] tinkerpop git commit: Improved equals() inheritance chain in Traverser implementations. We now have fewer checks and fewer casts. Cool!
Date Fri, 25 Aug 2017 16:22:30 GMT
Improved equals() inheritance chain in Traverser implementations.
We now have fewer checks and fewer casts. Cool!


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

Branch: refs/heads/TINKERPOP-1759
Commit: a2e605788e1474674611dab28b03a2b48f2bcd53
Parents: ebdca00
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Fri Aug 25 08:43:33 2017 -0700
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Fri Aug 25 09:22:03 2017 -0700

----------------------------------------------------------------------
 .../traverser/B_LP_O_P_S_SE_SL_Traverser.java          |  8 +++++---
 .../traversal/traverser/B_LP_O_S_SE_SL_Traverser.java  |  8 +++++---
 .../traversal/traverser/B_O_S_SE_SL_Traverser.java     | 10 ++++++----
 .../process/traversal/traverser/B_O_Traverser.java     |  8 +++++---
 .../traverser/LP_O_OB_P_S_SE_SL_Traverser.java         |  8 +++++---
 .../traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java |  8 +++++---
 .../traversal/traverser/O_OB_S_SE_SL_Traverser.java    | 11 ++++++-----
 .../process/traversal/traverser/O_Traverser.java       | 13 ++++++-------
 8 files changed, 43 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
index 919157c..5507862 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
@@ -83,10 +83,12 @@ public class B_LP_O_P_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
+    protected final boolean equals(final B_LP_O_P_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.path.equals(this.path);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof B_LP_O_P_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((B_LP_O_P_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof B_LP_O_P_S_SE_SL_Traverser && this.equals((B_LP_O_P_S_SE_SL_Traverser)
object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
index 1e50f3d..35f967a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
@@ -115,10 +115,12 @@ public class B_LP_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
+    protected  final boolean equals(final B_LP_O_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.path.equals(this.path);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof B_LP_O_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((B_LP_O_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof B_LP_O_S_SE_SL_Traverser && this.equals((B_LP_O_S_SE_SL_Traverser)
object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
index 2612472..0409cd7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
@@ -113,6 +113,7 @@ public class B_O_S_SE_SL_Traverser<T> extends B_O_Traverser<T>
{
     /////////////////
 
     final boolean carriesUnmergeableSack() {
+        // hmmm... serialization in OLAP destroys the transient sideEffects
         return null != this.sack && (null == this.sideEffects || null == this.sideEffects.getSackMerger());
     }
 
@@ -121,11 +122,12 @@ public class B_O_S_SE_SL_Traverser<T> extends B_O_Traverser<T>
{
         return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.loops);
     }
 
+    protected final boolean equals(final B_O_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.loops == this.loops && !carriesUnmergeableSack();
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof B_O_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((B_O_S_SE_SL_Traverser) object).loops == this.loops &&
-                !carriesUnmergeableSack(); // hmmm... serialization in OLAP destroys the
transient sideEffects
+        return object instanceof B_O_S_SE_SL_Traverser && this.equals((B_O_S_SE_SL_Traverser)
object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
index cef4e96..f4b32f3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
@@ -62,10 +62,12 @@ public class B_O_Traverser<T> extends O_Traverser<T> {
         this.future = stepId;
     }
 
+    protected final boolean equals(final B_O_Traverser other) {
+        return super.equals(other) && other.future.equals(this.future);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof B_O_Traverser &&
-                super.equals(object) &&
-                ((B_O_Traverser) object).future.equals(this.future);
+        return object instanceof B_O_Traverser && this.equals((B_O_Traverser) object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
index b1f4aa7..aa17e57 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
@@ -112,10 +112,12 @@ public class LP_O_OB_P_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         return super.hashCode() ^ this.path.hashCode();
     }
 
+    protected final boolean equals(final LP_O_OB_P_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.path.equals(this.path);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof LP_O_OB_P_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((LP_O_OB_P_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof LP_O_OB_P_S_SE_SL_Traverser && this.equals((LP_O_OB_P_S_SE_SL_Traverser)
object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
index b58560c..1ce6b4d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
@@ -92,10 +92,12 @@ public class LP_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
+    protected final boolean equals(final LP_O_OB_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.path.equals(this.path);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof LP_O_OB_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((LP_O_OB_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof LP_O_OB_S_SE_SL_Traverser && this.equals((LP_O_OB_S_SE_SL_Traverser)
object);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
index b49a661..76f8ad4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
@@ -134,6 +134,7 @@ public class O_OB_S_SE_SL_Traverser<T> extends O_Traverser<T>
{
     /////////////////
 
     final boolean carriesUnmergeableSack() {
+        // hmmm... serialization in OLAP destroys the transient sideEffects
         return null != this.sack && (null == this.sideEffects || null == this.sideEffects.getSackMerger());
     }
 
@@ -142,12 +143,12 @@ public class O_OB_S_SE_SL_Traverser<T> extends O_Traverser<T>
{
         return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.loops);
     }
 
+    protected  final boolean equals(final O_OB_S_SE_SL_Traverser other) {
+        return super.equals(other) && other.loops == this.loops && other.future.equals(this.future)
&&
+                !carriesUnmergeableSack();
+    }
     @Override
     public boolean equals(final Object object) {
-        return object instanceof O_OB_S_SE_SL_Traverser &&
-                super.equals(object) &&
-                ((O_OB_S_SE_SL_Traverser) object).loops == this.loops &&
-                ((O_OB_S_SE_SL_Traverser) object).future.equals(this.future) &&
-                !carriesUnmergeableSack(); // hmmm... serialization in OLAP destroys the
transient sideEffects
+        return object instanceof O_OB_S_SE_SL_Traverser && this.equals((O_OB_S_SE_SL_Traverser)
object);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a2e60578/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
index b4e1e0d..0c8152e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.AbstractTraverser;
 
 import java.util.HashSet;
+import java.util.Objects;
 import java.util.Set;
 
 /**
@@ -69,14 +70,12 @@ public abstract class O_Traverser<T> extends AbstractTraverser<T>
{
         }
     }
 
+    protected final boolean equals(final O_Traverser other) {
+        return super.equals(other) && Objects.equals(this.tags, other.tags);
+    }
+
     @Override
     public boolean equals(final Object object) {
-        return object instanceof O_Traverser &&
-                super.equals(object) &&
-                (this.tags == null
-                        ? ((O_Traverser) object).tags == null
-                        : (((O_Traverser) object).tags != null &&
-                            ((O_Traverser) object).tags.containsAll(this.tags) &&
-                            this.tags.containsAll(((O_Traverser) object).tags)));
+        return object instanceof O_Traverser && this.equals((O_Traverser) object);
     }
 }


Mime
View raw message