@Test public void testRetainAll() throws Exception { Set<Integer> retainSet = Sets.newHashSet(); fillSet(10, set); assertTrue("The set should have changed.", set.retainAll(retainSet)); assertTrue("The set should have been emptied.", set.isEmpty()); fillSet(10, set); fillSet(10, retainSet); Set<Integer> duplicateSet = new HashSet<>(set); assertFalse("The set should not have changed.", set.retainAll(retainSet)); assertEquals("The set should be the same as the duplicate.", duplicateSet, set); retainSet.remove(9); assertTrue("The set should have changed.", set.retainAll(retainSet)); duplicateSet.remove(9); assertEquals("The set should have had the nine element removed.", duplicateSet, set); }
@Override public boolean retainAll(Collection<?> c) { boolean changed = false; for (byte[] item : items) { E deserialized = serializer.decode(item); if (!c.contains(deserialized)) { changed = items.remove(item) || changed; } } return changed; }
PersistentSet implements Set<E> { @Override public boolean retainAll(Collection<?> c) { boolean changed = false; for (byte[] item : items) { E deserialized = serializer.decode(item); if (!c.contains(deserialized)) { changed = items.remove(item) || changed; } } return changed; } }
PersistentSet implements Set<E> { @Override public boolean retainAll(Collection<?> c) { boolean changed = false; for (byte[] item : items) { E deserialized = serializer.decode(item); if (!c.contains(deserialized)) { changed = items.remove(item) || changed; } } return changed; } PersistentSet(org.onosproject.store.service.Serializer serializer, DB database, String name); }
PersistentSet implements Set<E> { @Override public boolean retainAll(Collection<?> c) { boolean changed = false; for (byte[] item : items) { E deserialized = serializer.decode(item); if (!c.contains(deserialized)) { changed = items.remove(item) || changed; } } return changed; } PersistentSet(org.onosproject.store.service.Serializer serializer, DB database, String name); void readInto(Set<E> items); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean add(E item); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); @Override boolean equals(Object set); @Override int hashCode(); }
PersistentSet implements Set<E> { @Override public boolean retainAll(Collection<?> c) { boolean changed = false; for (byte[] item : items) { E deserialized = serializer.decode(item); if (!c.contains(deserialized)) { changed = items.remove(item) || changed; } } return changed; } PersistentSet(org.onosproject.store.service.Serializer serializer, DB database, String name); void readInto(Set<E> items); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override boolean add(E item); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); @Override boolean equals(Object set); @Override int hashCode();  }