changeset 447:2f8dd5417a07

Yak shaving: internal collections should implement proper equals/hashCode.
author shade
date Fri, 28 Feb 2014 23:37:30 +0400
parents 2ebe23110222
children 2aa7d697d7fc
files jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultiset.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultiset.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java
diffstat 6 files changed, 113 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultimap.java	Fri Feb 28 23:37:30 2014 +0400
@@ -100,4 +100,26 @@
             putAll(k, other.get(k));
         }
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        HashMultimap that = (HashMultimap) o;
+
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return map.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return map.toString();
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultiset.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashMultiset.java	Fri Feb 28 23:37:30 2014 +0400
@@ -79,4 +79,24 @@
     public Collection<T> keys() {
         return Collections.unmodifiableCollection(map.keySet());
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        HashMultiset that = (HashMultiset) o;
+
+        if (size != that.size) return false;
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = map.hashCode();
+        result = 31 * result + size;
+        return result;
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/HashsetMultimap.java	Fri Feb 28 23:37:30 2014 +0400
@@ -101,4 +101,21 @@
             putAll(k, other.get(k));
         }
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        HashsetMultimap that = (HashsetMultimap) o;
+
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return map.hashCode();
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultimap.java	Fri Feb 28 23:37:30 2014 +0400
@@ -100,4 +100,21 @@
             putAll(k, other.get(k));
         }
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TreeMultimap that = (TreeMultimap) o;
+
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return map.hashCode();
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultiset.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreeMultiset.java	Fri Feb 28 23:37:30 2014 +0400
@@ -79,4 +79,24 @@
     public Collection<T> keys() {
         return Collections.unmodifiableCollection(map.keySet());
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TreeMultiset that = (TreeMultiset) o;
+
+        if (size != that.size) return false;
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = map.hashCode();
+        result = 31 * result + size;
+        return result;
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Fri Feb 28 21:34:43 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/TreesetMultimap.java	Fri Feb 28 23:37:30 2014 +0400
@@ -101,4 +101,21 @@
             putAll(k, other.get(k));
         }
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TreesetMultimap that = (TreesetMultimap) o;
+
+        if (!map.equals(that.map)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return map.hashCode();
+    }
 }