示例#1
0
 public static <R, I, C extends Collection<R>> C collect(
     Iterable<? extends I> source, C destination, Transformer<R, I> transformer) {
   for (I item : source) {
     destination.add(transformer.transform(item));
   }
   return destination;
 }
 @NotNull
 private static <T, C extends Collection<T>> C copy(
     @NotNull C collection, @NotNull Iterable<? extends T> elements) {
   for (T element : elements) {
     collection.add(element);
   }
   return collection;
 }
 public static <T, C extends Collection<T>> C filter(
     Iterable<? extends T> source, C destination, Spec<? super T> filter) {
   for (T item : source) {
     if (filter.isSatisfiedBy(item)) {
       destination.add(item);
     }
   }
   return destination;
 }
示例#4
0
 /**
  * Adds the value to the collection given by map.get(key). A new collection is created using the
  * supplied CollectionFactory.
  */
 public static <K, V, C extends Collection<V>> void putIntoValueCollection(
     Map<K, C> map, K key, V value, CollectionFactory<V> cf) {
   C c = map.get(key);
   if (c == null) {
     c = ErasureUtils.<C>uncheckedCast(cf.newCollection());
     map.put(key, c);
   }
   c.add(value);
 }