Skip to content

Commit

Permalink
RedissonMap equals, hashcode methods implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed Jul 22, 2015
1 parent 67fe978 commit 10e83ba
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/org/redisson/RedissonMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,47 @@ public Future<V> addAndGetAsync(K key, Number value) {
getName(), key, new BigDecimal(value.toString()).toPlainString());
}

@Override
public boolean equals(Object o) {
if (o == this)
return true;

if (!(o instanceof Map))
return false;
Map<?,?> m = (Map<?,?>) o;
if (m.size() != size())
return false;

try {
Iterator<Entry<K,V>> i = entrySet().iterator();
while (i.hasNext()) {
Entry<K,V> e = i.next();
K key = e.getKey();
V value = e.getValue();
if (value == null) {
if (!(m.get(key)==null && m.containsKey(key)))
return false;
} else {
if (!value.equals(m.get(key)))
return false;
}
}
} catch (ClassCastException unused) {
return false;
} catch (NullPointerException unused) {
return false;
}

return true;
}

@Override
public int hashCode() {
int h = 0;
Iterator<Entry<K,V>> i = entrySet().iterator();
while (i.hasNext())
h += i.next().hashCode();
return h;
}

}

0 comments on commit 10e83ba

Please sign in to comment.