/** * Removes from this set all elements that are not within a given set of elements. * * @param collect the set of elements to be retained. * @return true if at least one element has been retained. * @throws DataAccessLayerException in case of data access failure. */ public boolean retainAll(final Collection<? extends E> collect) throws DataAccessLayerException { if (collect == null || collect.isEmpty()) { return false; } boolean changed = false; final Set<E> keys = new HashSet<E>(_map.keySet()); for (final E key : keys) { if (!collect.contains(key)) { changed = changed | remove(key); } } return changed; }
/** * Removes from this set all elements that are not within a given set of elements. * * @param collect the set of elements to be retained. * @return true if at least one element has been retained. * @throws DataAccessLayerException in case of data access failure. */ public boolean retainAll(final Collection<? extends E> collect) throws DataAccessLayerException { if (collect == null || collect.isEmpty()) { return false; } boolean changed = false; final Set<E> keys = new HashSet<E>(_map.keySet()); for (final E key : keys) { if (!collect.contains(key)) { changed = changed | remove(key); } } return changed; }
@Test public void removeTest() throws DataAccessLayerException { for (String key : TESTDATA2) { assertTrue(!CLASS_UNDER_TEST.remove(key)); } assertTrue(CLASS_UNDER_TEST.size() == TESTDATA1.size()); for (String key : TESTDATA1) { assertTrue(CLASS_UNDER_TEST.remove(key)); } assertTrue(CLASS_UNDER_TEST.isEmpty()); }