From 6a82fba75f39f53b58c52ed3971d90a9bce7bd37 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Fri, 24 Jul 2015 17:07:19 -0700 Subject: [PATCH] Add missing hashCode() implementation Summary: Whenever a Java class implements equals(), it has to implement hashCode(), otherwise there might be weird behavior when inserting instances of the class in a hash map for example. This adds two missing hashCode() implementations and extends tests to test the hashCode() implementations. Test Plan: make jtest Reviewers: rven, igor, sdong, yhchiang Reviewed By: yhchiang Subscribers: anthony, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D43017 --- Makefile | 2 +- java/src/main/java/org/rocksdb/AbstractSlice.java | 5 +++++ .../src/main/java/org/rocksdb/WBWIRocksIterator.java | 12 ++++++++++++ java/src/test/java/org/rocksdb/SliceTest.java | 1 + .../java/org/rocksdb/WriteBatchWithIndexTest.java | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b09bdd87f..5a09840c3 100644 --- a/Makefile +++ b/Makefile @@ -1037,7 +1037,7 @@ rocksdbjava: $(java_libobjects) jclean: cd java;$(MAKE) clean; -jtest: +jtest: rocksdbjava cd java;$(MAKE) sample;$(MAKE) test; jdb_bench: diff --git a/java/src/main/java/org/rocksdb/AbstractSlice.java b/java/src/main/java/org/rocksdb/AbstractSlice.java index 20fba41ac..a37bd023e 100644 --- a/java/src/main/java/org/rocksdb/AbstractSlice.java +++ b/java/src/main/java/org/rocksdb/AbstractSlice.java @@ -105,6 +105,11 @@ abstract class AbstractSlice extends RocksObject { return compare0(nativeHandle_, other.nativeHandle_); } + @Override + public int hashCode() { + return toString().hashCode(); + } + /** * If other is a slice object, then * we defer to {@link #compare(AbstractSlice) compare} diff --git a/java/src/main/java/org/rocksdb/WBWIRocksIterator.java b/java/src/main/java/org/rocksdb/WBWIRocksIterator.java index 9d7f8c4e8..f42f5498b 100644 --- a/java/src/main/java/org/rocksdb/WBWIRocksIterator.java +++ b/java/src/main/java/org/rocksdb/WBWIRocksIterator.java @@ -117,6 +117,18 @@ public class WBWIRocksIterator extends AbstractRocksIterator