예제 #1
0
 /**
  * Adds all elements in {@code iterable} to {@code collection}.
  *
  * @return {@code true} if {@code collection} was modified as a result of this operation.
  */
 public static <T> boolean addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd) {
   if (elementsToAdd instanceof Collection) {
     Collection<? extends T> c = Collections2.cast(elementsToAdd);
     return addTo.addAll(c);
   }
   return Iterators.addAll(addTo, checkNotNull(elementsToAdd).iterator());
 }
예제 #2
0
 @Override
 public boolean putAll(K key, Iterable<? extends V> values) {
   checkNotNull(values);
   // make sure we only call values.iterator() once
   // and we only call get(key) if values is nonempty
   if (values instanceof Collection) {
     Collection<? extends V> valueCollection = (Collection<? extends V>) values;
     return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
   } else {
     Iterator<? extends V> valueItr = values.iterator();
     return valueItr.hasNext() && Iterators.addAll(get(key), valueItr);
   }
 }
예제 #3
0
 /**
  * A sensible definition of {@link #addAll} in terms of {@link #add}. If you override {@link
  * #add}, you may wish to override {@link #addAll} to forward to this implementation.
  *
  * @since 7.0
  */
 protected boolean standardAddAll(Collection<? extends E> collection) {
   return Iterators.addAll(this, collection.iterator());
 }