/** * Copies the contents of this view into the provided set. * * @param <S> the set type * @param set the set for copying the contents */ public <S extends Set<E>> void copyInto(final S set) { CollectionUtils.addAll(set, this); }
/** * Traverses an iterator of this iterable and adds all elements * to the provided collection. * * @param collection the collection to add the elements * @throws NullPointerException if collection is null */ public void copyInto(final Collection<? super E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null"); } CollectionUtils.addAll(collection, iterable); }
/** * Create a new set operation helper from the two collections. * @param a the first collection * @param b the second collection */ public SetOperationCardinalityHelper(final Iterable<? extends O> a, final Iterable<? extends O> b) { super(a, b); elements = new HashSet<O>(); addAll(elements, a); addAll(elements, b); // the resulting list must contain at least each unique element, but may grow newList = new ArrayList<O>(elements.size()); }
/** * Adds all elements in the {@link Iterable} to the given collection. If the * {@link Iterable} is a {@link Collection} then it is cast and will be * added using {@link Collection#addAll(Collection)} instead of iterating. * * @param <C> the type of object the {@link Collection} contains * @param collection the collection to add to, must not be null * @param iterable the iterable of elements to add, must not be null * @return a boolean indicating whether the collection has changed or not. * @throws NullPointerException if the collection or iterator is null */ public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); }
/** * Adds Iterable values to the collection associated with the specified key. * * @param key the key to store against * @param values the values to add to the collection at the key, may not be null * @return true if this map changed * @throws NullPointerException if values is null */ @Override public boolean putAll(final K key, final Iterable<? extends V> values) { if (values == null) { throw new NullPointerException("Values must not be null."); } if (values instanceof Collection<?>) { Collection<? extends V> valueCollection = (Collection<? extends V>) values; return !valueCollection.isEmpty() && get(key).addAll(valueCollection); } else { Iterator<? extends V> it = values.iterator(); return it.hasNext() && CollectionUtils.addAll(get(key), it); } }
@Override public boolean putAll(final K key, final Iterable<? extends V> values) { if (values == null) { throw new NullPointerException("Values must not be null."); } final Iterable<V> transformedValues = FluentIterable.of(values).transform(valueTransformer); final Iterator<? extends V> it = transformedValues.iterator(); return it.hasNext() && CollectionUtils.addAll(decorated().get(transformKey(key)), it); }
CollectionUtils.addAll(singlePartition, iterable); return Collections.singletonList(singlePartition);