@Test public void keySet() { String x = new String("x"); String xx = new String("x"); assertNull(mMap.put(x, "x")); assertNull(mMap.put(xx, "x2")); assertEquals(2, mMap.size()); Set<String> km = mMap.keySet(); assertEquals(2, km.size()); assertTrue(km.contains(x)); assertTrue(km.contains(xx)); assertEquals("x", mMap.remove(x)); assertEquals(1, km.size()); assertTrue(km.remove(xx)); assertEquals(0, km.size()); assertEquals(0, mMap.size()); }
@Override public Set<K> keySet() { Set<IdentityObject<K>> set = mInternalMap.keySet(); return new Set<K>() { @Override public int size() { return set.size(); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public boolean contains(Object o) { return set.contains(new IdentityObject<>(o)); } @Override public Iterator<K> iterator() { return set.stream().map(IdentityObject::get).iterator(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public boolean add(K k) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "add")); } @Override public boolean remove(Object o) { return set.remove(new IdentityObject<>(o)); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "containsAll")); } @Override public boolean addAll(Collection<? extends K> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "addAll")); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "retainAll")); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "removeAll")); } @Override public void clear() { set.clear(); } }; }
ConcurrentIdentityHashMap implements ConcurrentMap<K, V> { @Override public Set<K> keySet() { Set<IdentityObject<K>> set = mInternalMap.keySet(); return new Set<K>() { @Override public int size() { return set.size(); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public boolean contains(Object o) { return set.contains(new IdentityObject<>(o)); } @Override public Iterator<K> iterator() { return set.stream().map(IdentityObject::get).iterator(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public boolean add(K k) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "add")); } @Override public boolean remove(Object o) { return set.remove(new IdentityObject<>(o)); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "containsAll")); } @Override public boolean addAll(Collection<? extends K> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "addAll")); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "retainAll")); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "removeAll")); } @Override public void clear() { set.clear(); } }; } }
ConcurrentIdentityHashMap implements ConcurrentMap<K, V> { @Override public Set<K> keySet() { Set<IdentityObject<K>> set = mInternalMap.keySet(); return new Set<K>() { @Override public int size() { return set.size(); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public boolean contains(Object o) { return set.contains(new IdentityObject<>(o)); } @Override public Iterator<K> iterator() { return set.stream().map(IdentityObject::get).iterator(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public boolean add(K k) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "add")); } @Override public boolean remove(Object o) { return set.remove(new IdentityObject<>(o)); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "containsAll")); } @Override public boolean addAll(Collection<? extends K> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "addAll")); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "retainAll")); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "removeAll")); } @Override public void clear() { set.clear(); } }; } ConcurrentIdentityHashMap();  ConcurrentIdentityHashMap(int initialCapacity);  ConcurrentIdentityHashMap(int initialCapacity, float loadFactor);  ConcurrentIdentityHashMap(int initialCapacity,
      float loadFactor, int concurrencyLevel); }
ConcurrentIdentityHashMap implements ConcurrentMap<K, V> { @Override public Set<K> keySet() { Set<IdentityObject<K>> set = mInternalMap.keySet(); return new Set<K>() { @Override public int size() { return set.size(); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public boolean contains(Object o) { return set.contains(new IdentityObject<>(o)); } @Override public Iterator<K> iterator() { return set.stream().map(IdentityObject::get).iterator(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public boolean add(K k) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "add")); } @Override public boolean remove(Object o) { return set.remove(new IdentityObject<>(o)); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "containsAll")); } @Override public boolean addAll(Collection<? extends K> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "addAll")); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "retainAll")); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "removeAll")); } @Override public void clear() { set.clear(); } }; } ConcurrentIdentityHashMap();  ConcurrentIdentityHashMap(int initialCapacity);  ConcurrentIdentityHashMap(int initialCapacity, float loadFactor);  ConcurrentIdentityHashMap(int initialCapacity,
      float loadFactor, int concurrencyLevel); @Override boolean containsKey(Object k); @Override V put(K k, V v); @Override V putIfAbsent(K k, V v); @Override boolean remove(Object k, Object v); @Override V remove(Object k); @Override boolean replace(K k, V v1, V v2); @Override V replace(K k, V v); @Override V get(Object k); @Override Collection<V> values(); @Override void clear(); @Override Set<Map.Entry<K, V>> entrySet(); @Override void putAll(Map<? extends K, ? extends V> map); @Override boolean isEmpty(); @Override int size(); @Override boolean containsValue(Object value); @Override Set<K> keySet(); }
ConcurrentIdentityHashMap implements ConcurrentMap<K, V> { @Override public Set<K> keySet() { Set<IdentityObject<K>> set = mInternalMap.keySet(); return new Set<K>() { @Override public int size() { return set.size(); } @Override public boolean isEmpty() { return set.isEmpty(); } @Override public boolean contains(Object o) { return set.contains(new IdentityObject<>(o)); } @Override public Iterator<K> iterator() { return set.stream().map(IdentityObject::get).iterator(); } @Override public Object[] toArray() { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public <T> T[] toArray(T[] a) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "toArray")); } @Override public boolean add(K k) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "add")); } @Override public boolean remove(Object o) { return set.remove(new IdentityObject<>(o)); } @Override public boolean containsAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "containsAll")); } @Override public boolean addAll(Collection<? extends K> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "addAll")); } @Override public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "retainAll")); } @Override public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(String.format(UNSUPPORTED_OP_FMT, "removeAll")); } @Override public void clear() { set.clear(); } }; } ConcurrentIdentityHashMap();  ConcurrentIdentityHashMap(int initialCapacity);  ConcurrentIdentityHashMap(int initialCapacity, float loadFactor);  ConcurrentIdentityHashMap(int initialCapacity,
      float loadFactor, int concurrencyLevel); @Override boolean containsKey(Object k); @Override V put(K k, V v); @Override V putIfAbsent(K k, V v); @Override boolean remove(Object k, Object v); @Override V remove(Object k); @Override boolean replace(K k, V v1, V v2); @Override V replace(K k, V v); @Override V get(Object k); @Override Collection<V> values(); @Override void clear(); @Override Set<Map.Entry<K, V>> entrySet(); @Override void putAll(Map<? extends K, ? extends V> map); @Override boolean isEmpty(); @Override int size(); @Override boolean containsValue(Object value); @Override Set<K> keySet();  }