From 09e90a1071e304b5328a6630d08d283143989914 Mon Sep 17 00:00:00 2001 From: yuanbingze Date: Tue, 3 May 2022 16:11:45 +0800 Subject: [PATCH 1/3] fix equals and hashcode issue --- .../com/baidu/hugegraph/auth/RolePermission.java | 4 ++++ .../baidu/hugegraph/backend/cache/RamCache.java | 5 +++++ .../backend/serializer/BinaryBackendEntry.java | 5 +++++ .../backend/serializer/TextBackendEntry.java | 10 ++++++++++ .../hugegraph/structure/HugeEdgeProperty.java | 4 ++++ .../traversal/optimize/HugeCountStep.java | 14 ++++++++++++++ .../traversal/optimize/HugeGraphStep.java | 15 +++++++++++++++ .../traversal/optimize/HugeVertexStep.java | 15 +++++++++++++++ 8 files changed, 72 insertions(+) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RolePermission.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RolePermission.java index 4d52986a52..1c35b7e8fb 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RolePermission.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/auth/RolePermission.java @@ -135,6 +135,10 @@ public boolean equals(Object object) { return Objects.equals(this.roles, other.roles); } + public int hashCode() { + return Objects.hash(this.roles); + } + @Override public String toString() { return this.roles.toString(); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java index 0bfda706db..36c2fc4d5e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java @@ -252,6 +252,11 @@ public boolean equals(Object obj) { LinkNode other = (LinkNode) obj; return this.key().equals(other.key()); } + + public int hashCode() { + return this.key().hashCode(); + } + } private static final class LinkedQueueNonBigLock { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java index e3126dbe89..148b2cd5a6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java @@ -197,6 +197,11 @@ public boolean equals(Object obj) { return this.columns.containsAll(other.columns); } + public int hashCode() { + return this.id().hashCode() ^ + this.columns.size(); + } + protected static final class BinaryId implements Id { private final byte[] bytes; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java index 8e764a29bf..3b16889a0d 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java @@ -358,6 +358,7 @@ public boolean equals(Object obj) { if (this.columns().size() != other.columns().size()) { return false; } + for (Map.Entry e : this.columns.entrySet()) { String key = e.getKey(); String value = e.getValue(); @@ -371,4 +372,13 @@ public boolean equals(Object obj) { } return true; } + + // ConcurrentSkipListMap override equals(); + // ConcurrentSkipListMap extend AbstractMap and AbstractMap implement + // hashCode() + public int hashCode() { + return this.id().hashCode() ^ + this.columns().hashCode(); + + } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdgeProperty.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdgeProperty.java index 00c234b664..c19152bae8 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdgeProperty.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeEdgeProperty.java @@ -63,6 +63,10 @@ public boolean equals(Object obj) { return ElementHelper.areEqual(this, obj); } + public int hashCode() { + return ElementHelper.hashCode(this); + } + public HugeEdgeProperty switchEdgeOwner() { assert this.owner instanceof HugeEdge; return new HugeEdgeProperty(((HugeEdge) this.owner).switchOwner(), diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeCountStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeCountStep.java index c23a22c01d..d13cc17f2c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeCountStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeCountStep.java @@ -46,6 +46,20 @@ public HugeCountStep(final Traversal.Admin traversal, this.originGraphStep = originGraphStep; } + public boolean equals(Object obj) { + if (!(obj instanceof HugeCountStep)) { + return false; + } + + if (!super.equals(obj)) { + return false; + } + + HugeCountStep other = (HugeCountStep) obj; + return Objects.equals(this.originGraphStep, + other.originGraphStep) && this.done == other.done; + } + @Override public int hashCode() { return Objects.hash(super.hashCode(), this.originGraphStep, this.done); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java index 41f5a0742f..6ec98aa439 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeGraphStep.java @@ -198,6 +198,21 @@ public Iterator lastTimeResults() { return this.lastTimeResults; } + public boolean equals(Object obj) { + if (!(obj instanceof HugeGraphStep)) { + return false; + } + + if (!super.equals(obj)) { + return false; + } + + HugeGraphStep other = (HugeGraphStep) obj; + return this.hasContainers.equals(other.hasContainers) && + this.queryInfo.equals(other.queryInfo) && + this.lastTimeResults.equals(other.lastTimeResults); + } + @Override public int hashCode() { return super.hashCode() ^ diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java index 2468c1f406..17d5c645c0 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/optimize/HugeVertexStep.java @@ -231,6 +231,21 @@ public Iterator lastTimeResults() { return this.iterator; } + public boolean equals(Object obj) { + if (!(obj instanceof HugeVertexStep)) { + return false; + } + + if (!super.equals(obj)) { + return false; + } + + HugeVertexStep other = (HugeVertexStep) obj; + return this.hasContainers.equals(other.hasContainers) && + this.queryInfo.equals(other.queryInfo) && + this.iterator.equals(other.iterator); + } + @Override public int hashCode() { return super.hashCode() ^ From fed9ac379e4976db97a0f9e784d25548387346f0 Mon Sep 17 00:00:00 2001 From: seagle Date: Wed, 4 May 2022 11:12:15 +0800 Subject: [PATCH 2/3] remove uless blank line --- .../main/java/com/baidu/hugegraph/backend/cache/RamCache.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java index 36c2fc4d5e..d4c55d4d26 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/RamCache.java @@ -256,7 +256,6 @@ public boolean equals(Object obj) { public int hashCode() { return this.key().hashCode(); } - } private static final class LinkedQueueNonBigLock { From 3c64576b0b7d7954c90f34cf1470a8d8b3f3ac61 Mon Sep 17 00:00:00 2001 From: seagle Date: Thu, 5 May 2022 20:05:41 +0800 Subject: [PATCH 3/3] fix comments and wrap line issue --- .../hugegraph/backend/serializer/BinaryBackendEntry.java | 3 +-- .../hugegraph/backend/serializer/TextBackendEntry.java | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java index 148b2cd5a6..b540296b83 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/BinaryBackendEntry.java @@ -198,8 +198,7 @@ public boolean equals(Object obj) { } public int hashCode() { - return this.id().hashCode() ^ - this.columns.size(); + return this.id().hashCode() ^ this.columns.size(); } protected static final class BinaryId implements Id { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java index 3b16889a0d..8f313d93cf 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/serializer/TextBackendEntry.java @@ -373,12 +373,7 @@ public boolean equals(Object obj) { return true; } - // ConcurrentSkipListMap override equals(); - // ConcurrentSkipListMap extend AbstractMap and AbstractMap implement - // hashCode() public int hashCode() { - return this.id().hashCode() ^ - this.columns().hashCode(); - + return this.id().hashCode() ^ this.columns().hashCode(); } }