A FluentIterable can be created either from an Iterable or from a set of elements. The following types of methods are provided:
FluentIterable instance,
providing a view of the original iterable (e.g. filter(Predicate));
The following example outputs the first 3 even numbers in the range [1, 10] into a list:
List<String> result =
FluentIterable
.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.filter(new Predicate<Integer>() {
public boolean evaluate(Integer number) {
return number % 2 == 0;
}
)
.transform(TransformerUtils.stringValueTransformer())
.limit(3)
.toList();
The resulting list will contain the following elements:
[2, 4, 6]
| Modifier and Type | Field and Description |
|---|---|
| private final Iterable | iterable
A reference to the wrapped iterable. |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| private | FluentIterable(final Iterable<E>
the iterable to wrap iterable)Create a new FluentIterable by wrapping the provided iterable. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | |
| public FluentIterable | Returns: a new iterable, combining this iterable with the elementsthe elements to append to the iterable elements)Returns a new FluentIterable whose iterator will first traverse the elements of the current iterable, followed by the provided elements. |
| public FluentIterable | |
| public Enumeration | Returns: an Enumeration over the elements of this iterableReturns an Enumeration that will enumerate all elements contained in this iterable. |
| public FluentIterable | |
| public FluentIterable | Returns: a new iterable, collating this iterable with the other in natural orderthe other iterable to collate, may not be null other, final Comparator<? super E> the comparator to define an ordering, may be null,
in which case natural ordering will be used comparator)Returns a new FluentIterable whose iterator will traverse the elements of the current and provided iterable according to the ordering defined by an comparator. |
| public boolean | |
| public void | copyInto(final Collection<? super E>
the collection to add the elements collection)Traverses an iterator of this iterable and adds all elements to the provided collection. |
| public static < the element type T> FluentIterable | |
| public FluentIterable | Returns: a new iterable with the same contents as this iterableThis method fully traverses an iterator of this iterable and returns a new iterable with the same contents, but without any reference to the originating iterables and/or iterators. |
| public FluentIterable | |
| public void | |
| public E | Returns: the elementthe position of the element to return position)Returns the element at the provided position in this iterable. |
| public boolean | Returns: true if this iterable does not contain any elements, false otherwiseChecks if this iterable is empty. |
| public Iterator | |
| public FluentIterable | Returns: a new iterable, providing a bounded view of this iterablethe maximum number of elements maxSize)Returns a new FluentIterable whose iterator will return at most the provided maximum number of elements from this iterable. |
| public FluentIterable | Returns: a new iterable, providing a looping view of this iterableReturns a new FluentIterable whose iterator will loop infinitely over the elements from this iterable. |
| public static < the element type T> FluentIterable | Returns: a new FluentIterable containing the singletonthe singleton element singleton)Creates a new FluentIterable of the single provided element. |
| public static < the element type T> FluentIterable | Returns: a new FluentIterable containing the provided elementsthe elements to be contained in the FluentIterable elements)Creates a new FluentIterable from the provided elements. |
| public static < the element type T> FluentIterable | |
| public FluentIterable | Returns: a new iterable, providing a reversed view of this iterableReturns a new FluentIterable whose iterator will traverse the elements from this iterable in reverse order. |
| public int | Returns: the size of this iterableReturns the number of elements that are contained in this iterable. |
| public FluentIterable | Returns: a new iterable, providing a view of this iterable by skipping the first N elementsthe number of elements to skip elementsToSkip)Returns a new FluentIterable whose iterator will skip the first N elements from this iterable. |
| public E[] | |
| public List | Returns: a list of the iterable contentsReturns a mutable list containing all elements of this iterable by traversing its iterator. |
| public String | |
| public < the output element type O> FluentIterable | Returns: a new iterable, providing a transformed view of this iterablethe transformer applied to each element transformer)Returns a new FluentIterable whose iterator will return all elements of this iterable transformed by the provided transformer. |
| public FluentIterable | Returns: a new iterable, providing a unique view of this iterableReturns a new FluentIterable whose iterator will return a unique view of this iterable. |
| public FluentIterable | Returns: a new iterable, providing an unmodifiable view of this iterableReturns a new FluentIterable whose iterator will return an unmodifiable view of this iterable. |
| public FluentIterable | |
| public FluentIterable |
| iterable | back to summary |
|---|---|
| private final Iterable<E> iterable A reference to the wrapped iterable. | |
| FluentIterable | back to summary |
|---|---|
| pack-priv FluentIterable() Package-private constructor, used by IterableUtils. | |
| FluentIterable | back to summary |
|---|---|
| private FluentIterable(final Iterable<E> iterable) Create a new FluentIterable by wrapping the provided iterable.
| |
| allMatch | back to summary |
|---|---|
| public boolean allMatch(final Predicate<? super E> predicate) Checks if all elements contained in this iterable are matching the provided predicate.
A
| |
| anyMatch | back to summary |
|---|---|
| public boolean anyMatch(final Predicate<? super E> predicate) Checks if this iterable contains any element matching the provided predicate.
A
| |
| append | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will first traverse the elements of the current iterable, followed by the provided elements.
| |
| append | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will first traverse the elements of the current iterable, followed by the elements of the provided iterable.
| |
| asEnumeration | back to summary |
|---|---|
| public Enumeration Returns an Enumeration that will enumerate all elements contained in this iterable.
| |
| collate | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will traverse the elements of the current and provided iterable in natural order. Example: natural ordering
The returned iterable will traverse the elements in the following order: [1, 2, 3, 4, 5, 6, 7, 8]
| |
| collate | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will traverse the elements of the current and provided iterable according to the ordering defined by an comparator. Example: descending order
The returned iterable will traverse the elements in the following order: [8, 7, 6, 5, 4, 3, 2, 1]
| |
| contains | back to summary |
|---|---|
| public boolean contains(final Object object) Checks if the object is contained in this iterable.
| |
| copyInto | back to summary |
|---|---|
| public void copyInto(final Collection<? super E> collection) Traverses an iterator of this iterable and adds all elements to the provided collection.
| |
| empty | back to summary |
|---|---|
| public static <T> FluentIterable Creates a new empty FluentIterable.
| |
| eval | back to summary |
|---|---|
| public FluentIterable This method fully traverses an iterator of this iterable and returns a new iterable with the same contents, but without any reference to the originating iterables and/or iterators. Calling this method is equivalent to: FluentIterable<E> someIterable = ...; FluentIterable.of(someIterable.toList());
| |
| filter | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will only return elements from this iterable matching the provided predicate.
| |
| forEach | back to summary |
|---|---|
| public void forEach(final Closure<? super E> closure) Applies the closure to all elements contained in this iterable.
| |
| get | back to summary |
|---|---|
| public E get(final int position) Returns the element at the provided position in this iterable. In order to return the element, an iterator needs to be traversed up to the requested position.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Checks if this iterable is empty.
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over elements of type | |
| limit | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will return at most the provided maximum number of elements from this iterable.
| |
| loop | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will loop infinitely over the elements from this iterable.
| |
| of | back to summary |
|---|---|
| public static <T> FluentIterable Creates a new FluentIterable of the single provided element.
The returned iterable's iterator does not support
| |
| of | back to summary |
|---|---|
| public static <T> FluentIterable Creates a new FluentIterable from the provided elements.
The returned iterable's iterator does not support
| |
| of | back to summary |
|---|---|
| public static <T> FluentIterable Construct a new FluentIterable from the provided iterable. If the iterable is already an instance of FluentIterable, the instance will be returned instead.
The returned iterable's iterator supports
| |
| reverse | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will traverse the elements from this iterable in reverse order.
| |
| size | back to summary |
|---|---|
| public int size() Returns the number of elements that are contained in this iterable. In order to determine the size, an iterator needs to be traversed.
| |
| skip | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will skip the first N elements from this iterable.
| |
| toArray | back to summary |
|---|---|
| public E[] toArray(final Class<E> arrayClass) Returns an array containing all elements of this iterable by traversing its iterator.
| |
| toList | back to summary |
|---|---|
| public List Returns a mutable list containing all elements of this iterable by traversing its iterator. The returned list is guaranteed to be mutable.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| transform | back to summary |
|---|---|
| public <O> FluentIterable Returns a new FluentIterable whose iterator will return all elements of this iterable transformed by the provided transformer.
| |
| unique | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will return a unique view of this iterable.
| |
| unmodifiable | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will return an unmodifiable view of this iterable.
| |
| zip | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will traverse the elements of this iterable and the other iterable in alternating order.
| |
| zip | back to summary |
|---|---|
| public FluentIterable Returns a new FluentIterable whose iterator will traverse the elements of this iterable and the other iterables in alternating order.
| |