Tabnine Logo
Collection.retainAll
Code IndexAdd Tabnine to your IDE (free)

How to use
retainAll
method
in
java.util.Collection

Best Java code snippets using java.util.Collection.retainAll (Showing top 20 results out of 3,366)

origin: hankcs/HanLP

@Override
public boolean retainAll(Collection<?> c)
{
  return termFrequencyMap.values().retainAll(c);
}
origin: google/guava

@Override
public boolean retainAll(Collection<?> c) {
 synchronized (mutex) {
  return delegate().retainAll(c);
 }
}
origin: prestodb/presto

@Override
public boolean retainAll(Collection<?> c) {
 synchronized (mutex) {
  return delegate().retainAll(c);
 }
}
origin: google/guava

 @Override
 public boolean retainAll(Collection<?> c) {
  return delegate.values().retainAll(c);
 }
};
origin: google/guava

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);
}
origin: google/guava

/**
 * 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);
}
origin: google/guava

@CanIgnoreReturnValue
@Override
public boolean retainAll(Collection<?> collection) {
 return delegate().retainAll(collection);
}
origin: google/guava

private void expectThrows(Target target) {
 try {
  collection.retainAll(target.toRetain);
  String message = Platform.format("retainAll(%s) should throw", target);
  fail(message);
 } catch (UnsupportedOperationException expected) {
 }
}
origin: google/guava

 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) {
  }
 }
}
origin: google/guava

@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) {
 }
}
origin: google/guava

private void expectReturnsFalse(Target target) {
 String message = Platform.format("retainAll(%s) should return false", target);
 assertFalse(message, collection.retainAll(target.toRetain));
}
origin: google/guava

private void expectReturnsTrue(Target target) {
 String message = Platform.format("retainAll(%s) should return true", target);
 assertTrue(message, collection.retainAll(target.toRetain));
}
origin: prestodb/presto

@CanIgnoreReturnValue
@Override
public boolean retainAll(Collection<?> collection) {
 return delegate().retainAll(collection);
}
origin: google/guava

@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) {
 }
}
origin: apache/incubator-shardingsphere

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;
}

origin: google/guava

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);
 }
}
origin: google/guava

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);
 }
}
origin: google/guava

@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()));
}
origin: google/guava

@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);
}
origin: google/guava

@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());
}
java.utilCollectionretainAll

Javadoc

Removes all objects from this Collection that are not also found in the Collection passed (optional). After this method returns this Collectionwill only contain elements that also can be found in the Collectionpassed to this method.

Popular methods of Collection

  • size
    Returns the number of elements in this collection. If this collection contains more than Integer.MAX
  • iterator
    Returns an iterator over the elements in this collection. There are no guarantees concerning the ord
  • add
  • isEmpty
    Returns true if this collection contains no elements.
  • contains
  • toArray
  • stream
  • addAll
  • forEach
  • remove
  • clear
  • removeAll
  • clear,
  • removeAll,
  • containsAll,
  • equals,
  • hashCode,
  • removeIf,
  • parallelStream,
  • spliterator,
  • <init>

Popular in Java

  • Creating JSON documents from java classes using gson
  • onRequestPermissionsResult (Fragment)
  • setContentView (Activity)
  • getApplicationContext (Context)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now