EnumeratedIdentitySet implements Set<T> { static <T> List<T> removeNulls(T[] list) { int insertionSpot = 0; for (int i = 0; i < list.length; i++) { T element = list[i]; if (element != null) { list[insertionSpot] = element; insertionSpot++; } } return Arrays.asList(list).subList(0, insertionSpot); } 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 removeNulls() { Element[] singletonArray = { null, elements.get(0), null }; assertTrue(containsAllSame(EnumeratedIdentitySet.removeNulls(singletonArray), Arrays.asList(elements.get(0)))); Element[] elementsWithNull = new Element[20]; Iterator<Element> iterator = elements.iterator(); copyElementsTo(iterator, elementsWithNull, 2, 1); copyElementsTo(iterator, elementsWithNull, 4, 8); copyElementsTo(iterator, elementsWithNull, 19, 1); assertTrue(containsAllSame(EnumeratedIdentitySet.removeNulls(elementsWithNull), elements)); }