public final class Iterables extends Object
Iterable interface (and also for removeIf
from Collection).| Modifier and Type | Method and Description |
|---|---|
static <T> void |
forEach(Iterable<? extends T> it,
Consumer<? super T> action)
Performs the given action for each element of the passed
Iterable
until all elements have been processed or the action throws an
exception. |
static <T> boolean |
removeIf(Iterable<? extends T> it,
Predicate<? super T> filter)
Removes all of the elements of the passed
Iterable that satisfy
the given predicate. |
static <T> Spliterator<T> |
spliterator(Iterable<? extends T> it)
Creates a
Spliterator over the elements described by this
Iterable. |
public static <T> void forEach(Iterable<? extends T> it, Consumer<? super T> action)
Iterable
until all elements have been processed or the action throws an
exception. Unless otherwise specified by the implementing class,
actions are performed in the order of iteration (if an iteration order
is specified). Exceptions thrown by the action are relayed to the
caller.
Implementation Requirements:
The default implementation behaves as if:
for (T t : this)
action.accept(t);
T - the type of elements of the Iterableit - the Iterable to call forEach onaction - The action to be performed for each elementNullPointerException - if one of the specified it or
action arguments is nullpublic static <T> boolean removeIf(Iterable<? extends T> it, Predicate<? super T> filter)
Iterable that satisfy
the given predicate. Errors or runtime exceptions thrown during iteration
or by the predicate are relayed to the caller.
Implementation Requirements:
The default implementation traverses all elements of the Iterable
using its Iterable.iterator(). Each matching element is removed
using Iterator.remove(). If the Iterable's iterator does not
support removal then an UnsupportedOperationException will be
thrown on the first matching element.
T - the type of elements of the Iterableit - the Iterable to call removeIf onfilter - a predicate which returns true for elements to be
removedtrue if any elements were removedNullPointerException - if one of the specified it or
filter arguments is nullUnsupportedOperationException - if elements cannot be removed
from the passed Iterable. Implementations may throw this exception
if a matching element cannot be removed or if, in general, removal
is not supported.public static <T> Spliterator<T> spliterator(Iterable<? extends T> it)
Spliterator over the elements described by this
Iterable.
Implementation notes:
If the passed Iterable is an instance of Collection
the implementation delegates to
Spliterators.spliterator(java.util.Collection) so it is
effectively the same as calling
Spliterators.spliterator((Collection<T>) it);
Implementation notes:
If the passed Iterable is not an instance of
Collection this implementation creates an
early-binding
spliterator from the iterable's Iterator. The spliterator
inherits the fail-fast properties of the iterable's iterator.
The spliterator returned for non-Collection sources has poor
splitting capabilities, is unsized, and does not report any spliterator
characteristics. Implementing classes could nearly always provide
a better implementation.
T - the type of elements of the Iterable.it - the Iterable for which the Spliterator should be created.Spliterator over the elements described by the
passed Iterable.Copyright © 2015. All rights reserved.