NodeStore implements Collection<Node>, NodeIterable { @Override public boolean retainAll(final Collection<?> c) { checkCollection(c); if (!c.isEmpty()) { ObjectSet<NodeImpl> set = new ObjectOpenHashSet(c.size()); for (Object o : c) { checkNonNullObject(o); checkNodeExists((NodeImpl) o); set.add((NodeImpl) o); } boolean changed = false; NodeStoreIterator itr = iterator(); while (itr.hasNext()) { NodeImpl e = itr.next(); if (!set.contains(e)) { itr.remove(); changed = true; } } return changed; } else { clear(); } return false; } NodeStore();  NodeStore(final EdgeStore edgeStore, final GraphLock lock, final GraphViewStore viewStore, final GraphVersion graphVersion); NodeImpl get(final int id); NodeImpl get(final Object id); @Override void clear(); @Override int size(); @Override boolean isEmpty(); @Override NodeStoreIterator iterator(); @Override NodeImpl[] toArray(); @Override T[] toArray(T[] array); @Override Collection<Node> toCollection(); @Override boolean add(final Node n); @Override boolean remove(final Object o); @Override boolean contains(final Object o); boolean containsId(final Object id); @Override boolean containsAll(final Collection<?> c); @Override boolean addAll(final Collection<? extends Node> c); @Override boolean removeAll(final Collection<?> c); @Override boolean retainAll(final Collection<?> c); int deepHashCode(); boolean deepEquals(NodeStore obj); @Override void doBreak();  }
@Test public void testRetainAll() { NodeStore nodeStore = new NodeStore(); NodeImpl[] nodes = new NodeImpl[] { new NodeImpl("0"), new NodeImpl("1"), new NodeImpl("2") }; nodeStore.addAll(Arrays.asList(nodes)); NodeImpl[] r = new NodeImpl[] { nodes[0] }; boolean a = nodeStore.retainAll(Arrays.asList(r)); boolean b = nodeStore.retainAll(Arrays.asList(r)); Assert.assertTrue(a); Assert.assertFalse(b); Assert.assertEquals(nodeStore.size(), 1); Assert.assertTrue(nodeStore.contains(nodes[0])); nodeStore.retainAll(new ArrayList()); Assert.assertTrue(nodeStore.isEmpty()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRetainAllSelf() { NodeStore nodeStore = new NodeStore(); nodeStore.retainAll(nodeStore); }