public class Iterables
extends java.lang.Object
Iterable instances.| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
all(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate) |
static <T> boolean |
any(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate) |
static <T> java.util.List<T> |
asList(java.lang.Iterable<T> iterable)
Create a
List view of the given Iterable, where changes in the underlying Iterable are
reflected in the returned List. |
static <T> boolean |
contains(java.lang.Iterable<? extends T> iterable,
T object) |
static <T> boolean |
containsAll(java.lang.Iterable<? extends T> iterable,
java.lang.Iterable<? extends T> items) |
static <T> boolean |
containsAll(java.lang.Iterable<? extends T> iterable,
T... items) |
static <T> boolean |
containsAny(java.util.Collection<? extends T> collection,
java.lang.Iterable<? extends T> items) |
static <T> boolean |
containsAny(java.lang.Iterable<? extends T> iterable,
java.lang.Iterable<? extends T> items) |
static <T> boolean |
containsAny(java.lang.Iterable<? extends T> iterable,
T... items) |
static <T> java.lang.Iterable<T> |
empty() |
static <T> java.lang.Iterable<T> |
from(java.lang.Object container)
Converts a container of some kind into a possibly once-only
Iterable. |
static <T> boolean |
none(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate) |
static <T> java.lang.Iterable<T> |
of(T... objects) |
static <T> java.lang.Iterable<T> |
of(T object) |
static <T> java.lang.Iterable<T> |
once(java.util.Iterator<T> iterator)
Create a one-pass-only
Iterable from an Iterator of items. |
static <T> void |
removeAll(java.lang.Iterable<T> iterable)
Remove all elements in the given
Iterable using Iterator.remove(). |
static int |
size(java.lang.Iterable<?> iterable) |
static <T> java.util.List<T> |
toList(java.lang.Iterable<T> iterable) |
public static <T> java.lang.Iterable<T> empty()
Iterable.public static <T> java.lang.Iterable<T> of(T object)
Iterable containing the given object.@SafeVarargs public static <T> java.lang.Iterable<T> of(T... objects)
Iterable containing the given objects.public static <T> java.lang.Iterable<T> once(java.util.Iterator<T> iterator)
Iterable from an Iterator of items. Note that Iterables created
from Iterators will be exhausted when the given iterator has been passed over. Further attempts will
register the Iterable as empty. If the iterator is terminated partway through iteration, further
calls to Iterable.iterator() will pick up where the previous iterator left off. If
Iterable.iterator() calls are interleaved, calls to the given iterator will be interleaved.public static <T> java.lang.Iterable<T> from(java.lang.Object container)
Iterable.container - the non-null container to turn into an Iterable, can be one of Iterable, Iterator, Stream, Array, Pair or Map.Entry.java.lang.ClassCastException - if the container is not one of Iterable, Iterator, Stream,
Array, Pair or Map.Entrypublic static <T> boolean all(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate)
Sequence satisfy the given predicate, false otherwise.public static <T> boolean none(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate)
Sequence satisfy the given predicate, false otherwise.public static <T> boolean any(java.lang.Iterable<T> iterable,
java.util.function.Predicate<? super T> predicate)
Sequence satisfies the given predicate, false otherwise.public static <T> void removeAll(java.lang.Iterable<T> iterable)
Iterable using Iterator.remove().public static <T> java.util.List<T> toList(java.lang.Iterable<T> iterable)
Iterable collected into a List.public static <T> java.util.List<T> asList(java.lang.Iterable<T> iterable)
List view of the given Iterable, where changes in the underlying Iterable are
reflected in the returned List. If a List is given it is returned unchanged. The list does not
implement RandomAccess unless the given Iterable does, and is best accessed in sequence. The
list does not support modification except the various removal operations, through Iterator.remove() only
if implemented in the Iterable's Iterable.iterator().public static <T> boolean contains(java.lang.Iterable<? extends T> iterable,
T object)
Iterable is equal to the given object, false otherwise.@SafeVarargs
public static <T> boolean containsAll(java.lang.Iterable<? extends T> iterable,
T... items)
Iterable contains all of the given items, false otherwise.public static <T> boolean containsAll(java.lang.Iterable<? extends T> iterable,
java.lang.Iterable<? extends T> items)
Iterable contains all of the given items, false otherwise.@SafeVarargs
public static <T> boolean containsAny(java.lang.Iterable<? extends T> iterable,
T... items)
Iterable contains any of the given items, false otherwise.public static <T> boolean containsAny(java.lang.Iterable<? extends T> iterable,
java.lang.Iterable<? extends T> items)
Iterable contains any of the given items, false otherwise.public static <T> boolean containsAny(java.util.Collection<? extends T> collection,
java.lang.Iterable<? extends T> items)
Collection contains any of the given items, false otherwise.public static int size(java.lang.Iterable<?> iterable)
Iterable, by traversing the Iterable.iterator().