Stream library.
The following types of methods are provided:
FluentIterable based in some way on the
contents of the current one (for example transform)
last)
FluentIterable's contents (for
example anyMatch)
FluentIterable's contents into a new collection
or array (for example toList)
Several lesser-used features are currently available only as static methods on the Iterables class.
Stream is similar to this class, but generally more powerful, and certainly more
standard. Key differences include:
findFirst() or iterator() is invoked. (Even though Stream
contains all the right method signatures to implement Iterable, it does not
actually do so, to avoid implying repeat-iterability.) FluentIterable, on the other
hand, is multiple-use, and does implement Iterable.
min/max, distinct,
reduce, sorted, the very powerful collect, and built-in support for
parallelizing stream operations.
FluentIterable contains several features not available on Stream, which are
noted in the method descriptions below.
IntStream, the use of which
is strongly recommended.
Here is an example that accepts a list from a database call, filters it based on a predicate,
transforms it by invoking toString() on each element, and returns the first 10 elements
as a List:
ImmutableList<String> results =
FluentIterable.from(database.getClientList())
.filter(Client::isActiveInLastMonth)
.transform(Object::toString)
.limit(10)
.toList();
The approximate stream equivalent is:
List<String> results =
database.getClientList()
.stream()
.filter(Client::isActiveInLastMonth)
.map(Object::toString)
.limit(10)
.collect(Collectors.toList());
| Modifier and Type | Class and Description |
|---|---|
| private static class | FluentIterable.
Function that transforms |
| Access | Constructor and Description |
|---|---|
| protected | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public final boolean | |
| public final boolean | |
| public final FluentIterable | |
| public final FluentIterable | append(E... elements)
Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
followed by |
| public static <T extends @Nullable Object> FluentIterable | |
| public static <T extends @Nullable Object> FluentIterable | |
| public static <T extends @Nullable Object> FluentIterable | |
| public static <T extends @Nullable Object> FluentIterable | |
| public static <T extends @Nullable Object> FluentIterable | |
| private static <T extends @Nullable Object> FluentIterable | concatNoDefensiveCopy(final Iterable<? extends T>... inputs)
Concatenates a varargs array of iterables without making a defensive copy of the array. |
| public final boolean | |
| public final <C extends Collection | Returns: collection, for conveniencethe collection to copy elements to collection)Copies all the elements from this fluent iterable to |
| public final FluentIterable | cycle()
Returns a fluent iterable whose |
| public final FluentIterable | |
| public final <T> FluentIterable | |
| public final Optional | |
| public final Optional | firstMatch(Predicate<? super E> predicate)
Returns an |
| public static <E extends @Nullable Object> FluentIterable | |
| public static <E extends @Nullable Object> FluentIterable | |
| public static <E extends @Nullable Object> FluentIterable | from(FluentIterable<E> iterable)
Deprecated
instances of
Construct a fluent iterable from another fluent iterable.
FluentIterable don't need to be converted to FluentIterable
|
| public final E | Returns: the element at the specified position in this fluent iterableposition of the element to return position)Returns the element at the specified position in this fluent iterable. |
| private Iterable | |
| public final <K> ImmutableListMultimap | |
| public final boolean | |
| public final String | |
| public final Optional | |
| public final FluentIterable | limit(int
the maximum number of elements in the returned fluent iterable maxSize)Creates a fluent iterable with the first |
| public static <E extends @Nullable Object> FluentIterable | |
| public static <E extends @Nullable Object> FluentIterable | |
| public final int | |
| public final FluentIterable | skip(int numberToSkip)
Returns a view of this fluent iterable that skips its first |
| public final Stream | stream()
Returns a stream of this fluent iterable's contents (similar to calling |
| public final E[] | |
| public final ImmutableList | toList()
Returns an |
| public final <V> ImmutableMap | |
| public final ImmutableMultiset | |
| public final ImmutableSet | toSet()
Returns an |
| public final ImmutableList | toSortedList(Comparator<? super E>
the function by which to sort list elements comparator)Returns an |
| public final ImmutableSortedSet | toSortedSet(Comparator<? super E>
the function by which to sort set elements comparator)Returns an |
| public String | toString()
Overrides java. [e1, e2, ...,
en].
|
| public final <T extends @Nullable Object> FluentIterable | |
| public <T extends @Nullable Object> FluentIterable | transformAndConcat(Function<? super E, ? extends Iterable<? extends T>> function)
Applies |
| public final <K> ImmutableMap | Returns: a map mapping the result of evaluating the functionkeyFunction on each value
in this fluent iterable to that valuethe function used to produce the key for each value keyFunction)Returns a map with the contents of this |
| iterableDelegate | back to summary |
|---|---|
| private final Optional<Iterable<E>> iterableDelegate | |
| FluentIterable | back to summary |
|---|---|
| protected FluentIterable() Constructor for use by subclasses. | |
| FluentIterable | back to summary |
|---|---|
| pack-priv FluentIterable(Iterable<E> iterable) | |
| allMatch | back to summary |
|---|---|
| public final boolean allMatch(Predicate<? super E> predicate) Returns
| |
| anyMatch | back to summary |
|---|---|
| public final boolean anyMatch(Predicate<? super E> predicate) Returns
| |
| append | back to summary |
|---|---|
| public final FluentIterable Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
followed by those of The returned iterable's
| |
| append | back to summary |
|---|---|
| public final FluentIterable Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
followed by
| |
| concat | back to summary |
|---|---|
| public static <T extends @Nullable Object> FluentIterable Returns a fluent iterable that combines two iterables. The returned iterable has an iterator
that traverses the elements in The returned iterable's iterator supports
| |
| concat | back to summary |
|---|---|
| public static <T extends @Nullable Object> FluentIterable Returns a fluent iterable that combines three iterables. The returned iterable has an iterator
that traverses the elements in The returned iterable's iterator supports
| |
| concat | back to summary |
|---|---|
| public static <T extends @Nullable Object> FluentIterable Returns a fluent iterable that combines four iterables. The returned iterable has an iterator
that traverses the elements in The returned iterable's iterator supports
| |
| concat | back to summary |
|---|---|
| public static <T extends @Nullable Object> FluentIterable Returns a fluent iterable that combines several iterables. The returned iterable has an
iterator that traverses the elements of each iterable in The returned iterable's iterator supports
| |
| concat | back to summary |
|---|---|
| public static <T extends @Nullable Object> FluentIterable Returns a fluent iterable that combines several iterables. The returned iterable has an
iterator that traverses the elements of each iterable in The returned iterable's iterator supports
| |
| concatNoDefensiveCopy | back to summary |
|---|---|
| private static <T extends @Nullable Object> FluentIterable Concatenates a varargs array of iterables without making a defensive copy of the array. | |
| contains | back to summary |
|---|---|
| public final boolean contains(Object target) Returns
| |
| copyInto | back to summary |
|---|---|
| public final <C extends Collection Copies all the elements from this fluent iterable to
| |
| cycle | back to summary |
|---|---|
| public final FluentIterable Returns a fluent iterable whose That iterator supports Warning Typical uses of the resulting iterator may produce an infinite loop. You
should use an explicit
| |
| filter | back to summary |
|---|---|
| public final FluentIterable Returns the elements from this fluent iterable that satisfy a predicate. The resulting fluent
iterable's iterator does not support
| |
| filter | back to summary |
|---|---|
| public final <T> FluentIterable Returns the elements from this fluent iterable that are instances of class
| |
| first | back to summary |
|---|---|
| public final Optional Returns an
| |
| firstMatch | back to summary |
|---|---|
| public final Optional Returns an Warning avoid using a
| |
| from | back to summary |
|---|---|
| public static <E extends @Nullable Object> FluentIterable Returns a fluent iterable that wraps
| |
| from | back to summary |
|---|---|
| public static <E extends @Nullable Object> FluentIterable Returns a fluent iterable containing The returned iterable is an unmodifiable view of the input array.
| |
| from | back to summary |
|---|---|
| public static <E extends @Nullable Object> FluentIterable Deprecated instances of Construct a fluent iterable from another fluent iterable. This is obviously never necessary,
but is intended to help call out cases where one migration from
| |
| get | back to summary |
|---|---|
| public final E get(int position) Returns the element at the specified position in this fluent iterable.
| |
| getDelegate | back to summary |
|---|---|
| private Iterable | |
| index | back to summary |
|---|---|
| public final <K> ImmutableListMultimap Creates an index
| |
| isEmpty | back to summary |
|---|---|
| public final boolean isEmpty() Determines whether this fluent iterable is empty.
| |
| join | back to summary |
|---|---|
| public final String join(Joiner joiner) Returns a
| |
| last | back to summary |
|---|---|
| public final Optional Returns an
| |
| limit | back to summary |
|---|---|
| public final FluentIterable Creates a fluent iterable with the first
| |
| of | back to summary |
|---|---|
| public static <E extends @Nullable Object> FluentIterable Returns a fluent iterable containing no elements.
| |
| of | back to summary |
|---|---|
| public static <E extends @Nullable Object> FluentIterable Returns a fluent iterable containing the specified elements in order.
| |
| size | back to summary |
|---|---|
| public final int size() Returns the number of elements in this fluent iterable.
| |
| skip | back to summary |
|---|---|
| public final FluentIterable Returns a view of this fluent iterable that skips its first Modifications to this fluent iterable before a call to The returned fluent iterable's iterator supports
| |
| stream | back to summary |
|---|---|
| public final Stream Returns a stream of this fluent iterable's contents (similar to calling Note the earlier in the chain you can switch to
| |
| toArray | back to summary |
|---|---|
| public final E[] toArray(Class<@NonNull E> type) Returns an array containing all of the elements from this fluent iterable in iteration order.
| |
| toList | back to summary |
|---|---|
| public final ImmutableList Returns an
| |
| toMap | back to summary |
|---|---|
| public final <V> ImmutableMap Returns an immutable map whose keys are the distinct elements of this When there are multiple instances of a key in this iterable, it is unspecified whether
| |
| toMultiset | back to summary |
|---|---|
| public final ImmutableMultiset Returns an
| |
| toSet | back to summary |
|---|---|
| public final ImmutableSet Returns an
| |
| toSortedList | back to summary |
|---|---|
| public final ImmutableList Returns an
| |
| toSortedSet | back to summary |
|---|---|
| public final ImmutableSortedSet Returns an
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this fluent iterable, with the format
| |
| transform | back to summary |
|---|---|
| public final <T extends @Nullable Object> FluentIterable Returns a fluent iterable that applies The returned fluent iterable's iterator supports
| |
| transformAndConcat | back to summary |
|---|---|
| public <T extends @Nullable Object> FluentIterable Applies The returned fluent iterable's iterator supports
| |
| uniqueIndex | back to summary |
|---|---|
| public final <K> ImmutableMap Returns a map with the contents of this
If your index may associate multiple values with each key, use
| |
Iterable<E> into a fluent iterable.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public FluentIterable | apply(Iterable<E>
the function argument fromObject)Implements com. |
| FromIterableFunction | back to summary |
|---|---|
| private FromIterableFunction() | |
| apply | back to summary |
|---|---|
| public FluentIterable Implements com. Doc from java. Applies this function to the given argument.
| |