LowMemorySet extends AbstractSet<T> implements Set<T> { @Override public boolean remove(Object o) { T old = backing.remove(indexOf(o)); this.trim(); assert old == o; return old != null; } protected  LowMemorySet(List<T> list); static LowMemorySet<T> create(); static LowMemorySet<T> copyOf(Collection<T> c); @Override int size(); @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 removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override @SuppressWarnings("unchecked") boolean addAll(Collection<? extends T> c); @Override void clear(); @Override void forEach(Consumer<? super T> action); @Override Stream<T> stream(); @Override Stream<T> parallelStream(); @Override boolean removeIf(Predicate<? super T> filter);  }
@Test public void testRemove() { LowMemorySet<String> set = LowMemorySet.copyOf(ELEMENTS); assertTrue(set.contains("test")); set.remove("test"); assertFalse(set.contains("test")); assertTrue(set.contains("bob")); set.remove("bob"); assertFalse(set.contains("bob")); assertTrue(ELEMENTS.size() - set.size() == 2); assertTrue(set.contains("road")); assertTrue(set.contains("food")); assertTrue(set.contains("pain")); set.removeAll(ImmutableList.of("road", "food", "pain")); assertFalse(set.contains("road")); assertFalse(set.contains("food")); assertFalse(set.contains("pain")); assertTrue(ELEMENTS.size() - set.size() == 5); }