Ray Milkey

Classes that override compareTo() should also override equals()

Change-Id: Ied1fd508c9ced3799d16d0c1591a42ce690afde6
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.store.ecmap; 16 package org.onosproject.store.ecmap;
17 17
18 +import java.util.Objects;
19 +
18 import org.onosproject.store.Timestamp; 20 import org.onosproject.store.Timestamp;
19 21
20 import static com.google.common.base.Preconditions.checkNotNull; 22 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -66,4 +68,21 @@ public abstract class AbstractEntry<K, V> implements Comparable<AbstractEntry<K, ...@@ -66,4 +68,21 @@ public abstract class AbstractEntry<K, V> implements Comparable<AbstractEntry<K,
66 public int compareTo(AbstractEntry<K, V> o) { 68 public int compareTo(AbstractEntry<K, V> o) {
67 return this.timestamp.compareTo(o.timestamp); 69 return this.timestamp.compareTo(o.timestamp);
68 } 70 }
71 +
72 + @Override
73 + public int hashCode() {
74 + return Objects.hash(timestamp);
75 + }
76 +
77 + @Override
78 + public boolean equals(Object o) {
79 + if (this == o) {
80 + return true;
81 + }
82 + if (o instanceof AbstractEntry) {
83 + final AbstractEntry that = (AbstractEntry) o;
84 + return this.timestamp.equals(that.timestamp);
85 + }
86 + return false;
87 + }
69 } 88 }
......