@Override public boolean retainAll(Collection<?> c) { return termFrequencyMap.values().retainAll(c); }
@Override public boolean retainAll(Collection<?> c) { synchronized (mutex) { return delegate().retainAll(c); } }
@Override public boolean retainAll(Collection<?> c) { synchronized (mutex) { return delegate().retainAll(c); } }
@Override public boolean retainAll(Collection<?> c) { return delegate.values().retainAll(c); } };
public void testValuesRetainAllNullFromEmpty() { final Map<K, V> map; try { map = makeEmptyMap(); } catch (UnsupportedOperationException e) { return; } Collection<V> values = map.values(); if (supportsRemove) { try { values.retainAll(null); // Returning successfully is not ideal, but tolerated. } catch (NullPointerException expected) { } } else { try { values.retainAll(null); // We have to tolerate a successful return (Sun bug 4802647) } catch (UnsupportedOperationException | NullPointerException e) { // Expected. } } assertInvariants(map); }
/** * Removes, from an iterable, every element that does not belong to the provided collection. * * <p>This method calls {@link Collection#retainAll} if {@code iterable} is a collection, and * {@link Iterators#retainAll} otherwise. * * @param removeFrom the iterable to (potentially) remove elements from * @param elementsToRetain the elements to retain * @return {@code true} if any element was removed from {@code iterable} */ @CanIgnoreReturnValue public static boolean retainAll(Iterable<?> removeFrom, Collection<?> elementsToRetain) { return (removeFrom instanceof Collection) ? ((Collection<?>) removeFrom).retainAll(checkNotNull(elementsToRetain)) : Iterators.retainAll(removeFrom.iterator(), elementsToRetain); }
@CanIgnoreReturnValue @Override public boolean retainAll(Collection<?> collection) { return delegate().retainAll(collection); }
private void expectThrows(Target target) { try { collection.retainAll(target.toRetain); String message = Platform.format("retainAll(%s) should throw", target); fail(message); } catch (UnsupportedOperationException expected) { } }
private void expectReturnsFalseOrThrows(Target target) { String message = Platform.format("retainAll(%s) should return false or throw", target); try { assertFalse(message, collection.retainAll(target.toRetain)); } catch (UnsupportedOperationException tolerated) { } } }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(ZERO) public void testRetainAll_nullCollectionReferenceEmptySubject() { try { collection.retainAll(null); // Returning successfully is not ideal, but tolerated. } catch (NullPointerException tolerated) { } }
private void expectReturnsFalse(Target target) { String message = Platform.format("retainAll(%s) should return false", target); assertFalse(message, collection.retainAll(target.toRetain)); }
private void expectReturnsTrue(Target target) { String message = Platform.format("retainAll(%s) should return true", target); assertTrue(message, collection.retainAll(target.toRetain)); }
@CanIgnoreReturnValue @Override public boolean retainAll(Collection<?> collection) { return delegate().retainAll(collection); }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = ZERO) public void testRetainAll_nullCollectionReferenceNonEmptySubject() { try { collection.retainAll(null); fail("retainAll(null) should throw NullPointerException"); } catch (NullPointerException expected) { } }
private Collection<String> getIntersectionDataSources() { Collection<String> result = new HashSet<>(); for (RoutingResult each : routingResults) { if (result.isEmpty()) { result.addAll(each.getTableUnits().getDataSourceNames()); } result.retainAll(each.getTableUnits().getDataSourceNames()); } return result; }
public void testValues_empty_remove() { for (LoadingCache<Object, Object> cache : caches()) { Collection<Object> values = cache.asMap().values(); assertFalse(values.remove(null)); assertFalse(values.remove(6)); assertFalse(values.remove(-6)); assertFalse(values.removeAll(asList(null, 0, 15, 1500))); assertFalse(values.retainAll(asList(null, 0, 15, 1500))); checkEmpty(values); checkEmpty(cache); } }
public void testValues_remove() { for (LoadingCache<Object, Object> cache : caches()) { cache.getUnchecked(1); cache.getUnchecked(2); Collection<Object> values = cache.asMap().keySet(); // We don't know whether these are still in the cache, so we can't assert on the return // values of these removes, but the cache should be empty after the removes, regardless. values.remove(1); values.remove(2); assertFalse(values.remove(null)); assertFalse(values.remove(6)); assertFalse(values.remove(-6)); assertFalse(values.removeAll(asList(null, 0, 15, 1500))); assertFalse(values.retainAll(asList(null, 0, 15, 1500))); checkEmpty(values); checkEmpty(cache); } }
@CollectionSize.Require(absent = ZERO) @MapFeature.Require(SUPPORTS_REMOVE) public void testRetainAllPropagatesToMultimap() { multimap().entries().retainAll(Collections.singleton(Helpers.mapEntry(k0(), v0()))); assertEquals(getSubjectGenerator().create(Helpers.mapEntry(k0(), v0())), multimap()); assertEquals(1, multimap().size()); assertTrue(multimap().containsEntry(k0(), v0())); }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(absent = {ZERO, ONE}) public void testRetainAll_duplicatesKept() { E[] array = createSamplesArray(); array[1] = e0(); collection = getSubjectGenerator().create(array); assertFalse( "containsDuplicates.retainAll(superset) should return false", collection.retainAll(MinimalCollection.of(createSamplesArray()))); expectContents(array); }
@SuppressWarnings("unchecked") @CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(SEVERAL) public void testRetainAll_duplicatesRemoved() { E[] array = createSamplesArray(); array[1] = e0(); collection = getSubjectGenerator().create(array); assertTrue( "containsDuplicates.retainAll(subset) should return true", collection.retainAll(MinimalCollection.of(e2()))); expectContents(e2()); }