/** Maps with same contents are equal */ public void testEquals() { ConcurrentNavigableMap map1 = map5(); ConcurrentNavigableMap map2 = map5(); assertEquals(map1, map2); assertEquals(map2, map1); map1.clear(); assertFalse(map1.equals(map2)); assertFalse(map2.equals(map1)); }
/** A deserialized map equals original */ public void testSerialization() throws Exception { ConcurrentNavigableMap q = map5(); ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); out.writeObject(q); out.close(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); ConcurrentNavigableMap r = (ConcurrentNavigableMap) in.readObject(); assertEquals(q.size(), r.size()); assertTrue(q.equals(r)); assertTrue(r.equals(q)); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; PojoBar other = (PojoBar) obj; if (concurrentHashMap == null) { if (other.concurrentHashMap != null) return false; } else if (!concurrentHashMap.equals(other.concurrentHashMap)) return false; if (concurrentMap == null) { if (other.concurrentMap != null) return false; } else if (!concurrentMap.equals(other.concurrentMap)) return false; if (concurrentNavigableMap == null) { if (other.concurrentNavigableMap != null) return false; } else if (!concurrentNavigableMap.equals(other.concurrentNavigableMap)) return false; if (concurrentSkipListMap == null) { if (other.concurrentSkipListMap != null) return false; } else if (!concurrentSkipListMap.equals(other.concurrentSkipListMap)) return false; if (hashMap == null) { if (other.hashMap != null) return false; } else if (!hashMap.equals(other.hashMap)) return false; if (hashtable == null) { if (other.hashtable != null) return false; } else if (!hashtable.equals(other.hashtable)) return false; if (identityHashMap == null) { if (other.identityHashMap != null) return false; } else if (!identityHashMap.equals(other.identityHashMap)) return false; if (linkedHashMap == null) { if (other.linkedHashMap != null) return false; } else if (!linkedHashMap.equals(other.linkedHashMap)) return false; if (map == null) { if (other.map != null) return false; } else if (!map.equals(other.map)) return false; if (navigableMap == null) { if (other.navigableMap != null) return false; } else if (!navigableMap.equals(other.navigableMap)) return false; if (sortedMap == null) { if (other.sortedMap != null) return false; } else if (!sortedMap.equals(other.sortedMap)) return false; if (treeMap == null) { if (other.treeMap != null) return false; } else if (!treeMap.equals(other.treeMap)) return false; if (weakHashMap == null) { if (other.weakHashMap != null) return false; } else if (!weakHashMap.equals(other.weakHashMap)) return false; return true; }