EnumeratedIdentitySet implements Set<T> { @Override public boolean retainAll(Collection<?> collection) { return set.keySet().retainAll(collection); } EnumeratedIdentitySet(Collection<? extends T> collection);  EnumeratedIdentitySet(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<T> iterator(); @Override Object[] toArray(); @Override T1[] toArray(T1[] a); @Override boolean add(T t); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> collection); @Override boolean retainAll(Collection<?> collection); @Override boolean removeAll(Collection<?> collection); @Override void clear(); List<T> insertionOrderedList();  }
@Test public void retainAll() { Set<Element> set = new EnumeratedIdentitySet<>(); set.addAll(elements.subList(0, 5)); boolean changed = set.retainAll(toIdentitySet(elements.subList(3, 10))); assertTrue(changed); assertTrue(containsAllSame(set, elements.subList(3, 5))); changed = set.retainAll(toIdentitySet(elements)); assertFalse(changed); }