/**
  * A sensible definition of {@link #retainAll} in terms of {@link #iterator}, using the iterator's
  * {@code remove} method. If you override {@link #iterator}, you may wish to override {@link
  * #retainAll} to forward to this implementation.
  *
  * @since 7.0
  */
 protected boolean standardRetainAll(Collection<?> collection) {
   return Iterators.retainAll(iterator(), collection);
 }
Exemple #2
0
 @Override
 public boolean retainAll(Collection<?> c) {
   synchronized (mutex) {
     return Iterators.retainAll(delegate().iterator(), c);
   }
 }
Exemple #3
0
 /**
  * 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}
  */
 public static boolean retainAll(Iterable<?> removeFrom, Collection<?> elementsToRetain) {
   return (removeFrom instanceof Collection)
       ? ((Collection<?>) removeFrom).retainAll(checkNotNull(elementsToRetain))
       : Iterators.retainAll(removeFrom.iterator(), elementsToRetain);
 }