public abstract class FluentCloseableIterable<T> extends AbstractCloseableIterable<T>
FluentIterable to work
with CloseableIterablesclosed| Modifier | Constructor and Description |
|---|---|
protected |
FluentCloseableIterable() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(Predicate<? super T> predicate)
Returns
true if every element in this fluent iterable satisfies the predicate. |
boolean |
anyMatch(Predicate<? super T> predicate)
Returns
true if any element in this fluent iterable satisfies the predicate. |
FluentCloseableIterable<T> |
append(Iterable<? extends T> other)
Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
followed by those of
other. |
FluentCloseableIterable<T> |
append(T... elements)
Returns a fluent iterable whose iterators traverse first the elements of this fluent iterable,
followed by
elements. |
FluentCloseableIterable<T> |
autoClose()
Returns a fluent iterable where the underlying resources are automatically closed when its iterator has been
exhausted.
|
boolean |
contains(Object target)
Returns
true if this fluent iterable contains any object for which
equals(target) is true. |
<C extends Collection<? super T>> |
copyInto(C collection)
Copies all the elements from this fluent iterable to
collection. |
FluentCloseableIterable<T> |
cycle()
Returns a fluent iterable whose
Iterator cycles indefinitely over the elements of
this fluent iterable. |
<E> FluentCloseableIterable<E> |
filter(Class<E> type)
Returns the elements from this fluent iterable that are instances of class
type. |
FluentCloseableIterable<T> |
filter(Predicate<? super T> predicate)
Returns the elements from this fluent iterable that satisfy a predicate.
|
Optional<T> |
first()
Returns an
Optional containing the first element in this fluent iterable. |
Optional<T> |
firstMatch(Predicate<? super T> predicate)
Returns an
Optional containing the first element in this fluent iterable that
satisfies the given predicate, if such an element exists. |
static <E> FluentCloseableIterable<E> |
from(CloseableIterable<E> iterable)
Create a
FluentCloseableIterable from a CloseableIterable |
T |
get(int position)
Returns the element at the specified position in this fluent iterable.
|
<K> ImmutableListMultimap<K,T> |
index(Function<? super T,K> keyFunction)
Creates an index
ImmutableListMultimap that contains the results of applying a
specified function to each item in this FluentIterable of values. |
boolean |
isEmpty()
Determines whether this fluent iterable is empty.
|
String |
join(Joiner joiner)
Returns a
String containing all of the elements of this fluent iterable joined with
joiner. |
Optional<T> |
last()
Returns an
Optional containing the last element in this fluent iterable. |
FluentCloseableIterable<T> |
limit(int size)
Creates a fluent iterable with the first
size elements of this
fluent iterable. |
int |
size()
Returns the number of elements in this fluent iterable.
|
FluentCloseableIterable<T> |
skip(int numberToSkip)
Returns a view of this fluent iterable that skips its first
numberToSkip
elements. |
T[] |
toArray(Class<T> type)
Returns an array containing all of the elements from this fluent iterable in iteration order.
|
ImmutableList<T> |
toList()
Returns an
ImmutableList containing all of the elements from this fluent iterable in
proper sequence. |
<V> ImmutableMap<T,V> |
toMap(Function<? super T,V> valueFunction)
Returns an immutable map whose keys are the distinct elements of this
FluentIterable
and whose value for each key was computed by valueFunction. |
ImmutableMultiset<T> |
toMultiset()
Returns an
ImmutableMultiset containing all of the elements from this fluent iterable. |
ImmutableSet<T> |
toSet()
Returns an
ImmutableSet containing all of the elements from this fluent iterable with
duplicates removed. |
Iterable<T> |
toSimpleIterable()
Returns a generic iterable with no beanlike properties such as
isEmpty(). |
ImmutableList<T> |
toSortedList(Comparator<? super T> comparator)
Returns an
ImmutableList containing all of the elements from this FluentIterable in the order specified by comparator. |
ImmutableSortedSet<T> |
toSortedSet(Comparator<? super T> comparator)
Returns an
ImmutableSortedSet containing all of the elements from this FluentIterable in the order specified by comparator, with duplicates (determined by
comparator.compare(x, y) == 0) removed. |
String |
toString()
Returns a string representation of this fluent iterable, with the format
[e1, e2, ..., en]. |
<E> FluentCloseableIterable<E> |
transform(Function<? super T,? extends E> function)
Returns a fluent iterable that applies
function to each element of this
fluent iterable. |
<E> FluentCloseableIterable<E> |
transformAndConcat(Function<? super T,? extends Iterable<E>> function)
Applies
function to each element of this fluent iterable and returns
a fluent iterable with the concatenated combination of results. |
<K> ImmutableMap<K,T> |
uniqueIndex(Function<? super T,K> keyFunction)
Returns a map with the contents of this
FluentIterable as its values, indexed
by keys derived from those values. |
close, closeQuietly, doClose, iterator, retrieveIteratorclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static <E> FluentCloseableIterable<E> from(CloseableIterable<E> iterable)
FluentCloseableIterable from a CloseableIterablepublic final FluentCloseableIterable<T> autoClose()
limit() is an example of one method which can
prevent the completion of an iterator. For instance from(iterable).autoClose().limit(1) will not close the
resource if there is more than 1 element, but from(iterable).limit(1).autoClose() will close the underlying
resource.public String toString()
[e1, e2, ..., en].public final int size()
public final boolean contains(Object target)
true if this fluent iterable contains any object for which
equals(target) is true.public final FluentCloseableIterable<T> cycle()
Iterator cycles indefinitely over the elements of
this fluent iterable.
That iterator supports remove() if iterable.iterator() does. After
remove() is called, subsequent cycles omit the removed element, which is no longer in
this fluent iterable. The iterator's hasNext() method returns true until
this fluent iterable is empty.
Warning: Typical uses of the resulting iterator may produce an infinite loop. You
should use an explicit break or be certain that you will eventually remove all the
elements.
public final FluentCloseableIterable<T> append(Iterable<? extends T> other)
other. The iterators are not polled until necessary.
The returned iterable's Iterator supports remove() when the corresponding
Iterator supports it.
@SafeVarargs public final FluentCloseableIterable<T> append(T... elements)
elements.public final FluentCloseableIterable<T> filter(Predicate<? super T> predicate)
remove().public final <E> FluentCloseableIterable<E> filter(Class<E> type)
type.public final boolean anyMatch(Predicate<? super T> predicate)
true if any element in this fluent iterable satisfies the predicate.public final boolean allMatch(Predicate<? super T> predicate)
true if every element in this fluent iterable satisfies the predicate.
If this fluent iterable is empty, true is returned.public final Optional<T> firstMatch(Predicate<? super T> predicate)
Optional containing the first element in this fluent iterable that
satisfies the given predicate, if such an element exists.
Warning: avoid using a predicate that matches null. If null
is matched in this fluent iterable, a NullPointerException will be thrown.
public final <E> FluentCloseableIterable<E> transform(Function<? super T,? extends E> function)
function to each element of this
fluent iterable.
The returned fluent iterable's iterator supports remove() if this iterable's
iterator does. After a successful remove() call, this fluent iterable no longer
contains the corresponding element.
public final <E> FluentCloseableIterable<E> transformAndConcat(Function<? super T,? extends Iterable<E>> function)
function to each element of this fluent iterable and returns
a fluent iterable with the concatenated combination of results. function
returns an Iterable of results.
The returned fluent iterable's iterator supports remove() if this
function-returned iterables' iterator does. After a successful remove() call,
the returned fluent iterable no longer contains the corresponding element.
public final Optional<T> first()
Optional containing the first element in this fluent iterable.
If the iterable is empty, Optional.absent() is returned.public final Optional<T> last()
Optional containing the last element in this fluent iterable.
If the iterable is empty, Optional.absent() is returned.public final FluentCloseableIterable<T> skip(int numberToSkip)
numberToSkip
elements. If this fluent iterable contains fewer than numberToSkip elements,
the returned fluent iterable skips all of its elements.
Modifications to this fluent iterable before a call to iterator() are
reflected in the returned fluent iterable. That is, the its iterator skips the first
numberToSkip elements that exist when the iterator is created, not when skip()
is called.
The returned fluent iterable's iterator supports remove() if the
Iterator of this fluent iterable supports it. Note that it is not
possible to delete the last skipped element by immediately calling remove() on the
returned fluent iterable's iterator, as the Iterator contract states that a call
to * remove() before a call to next() will throw an
IllegalStateException.
public final FluentCloseableIterable<T> limit(int size)
size elements of this
fluent iterable. If this fluent iterable does not contain that many elements,
the returned fluent iterable will have the same behavior as this fluent iterable.
The returned fluent iterable's iterator supports remove() if this
fluent iterable's iterator does.public final boolean isEmpty()
public final ImmutableList<T> toList()
ImmutableList containing all of the elements from this fluent iterable in
proper sequence.public final ImmutableList<T> toSortedList(Comparator<? super T> comparator)
ImmutableList containing all of the elements from this FluentIterable in the order specified by comparator. To produce an ImmutableList sorted by its natural ordering, use toSortedList(Ordering.natural()).public final ImmutableSet<T> toSet()
ImmutableSet containing all of the elements from this fluent iterable with
duplicates removed.public final ImmutableSortedSet<T> toSortedSet(Comparator<? super T> comparator)
ImmutableSortedSet containing all of the elements from this FluentIterable in the order specified by comparator, with duplicates (determined by
comparator.compare(x, y) == 0) removed. To produce an ImmutableSortedSet sorted
by its natural ordering, use toSortedSet(Ordering.natural()).public final ImmutableMultiset<T> toMultiset()
ImmutableMultiset containing all of the elements from this fluent iterable.public final <V> ImmutableMap<T,V> toMap(Function<? super T,V> valueFunction)
FluentIterable
and whose value for each key was computed by valueFunction. The map's iteration order
is the order of the first appearance of each key in this iterable.
When there are multiple instances of a key in this iterable, it is unspecified whether
valueFunction will be applied to more than one instance of that key and, if it is,
which result will be mapped to that key in the returned map.
public final <K> ImmutableListMultimap<K,T> index(Function<? super T,K> keyFunction)
ImmutableListMultimap that contains the results of applying a
specified function to each item in this FluentIterable of values. Each element of this
iterable will be stored as a value in the resulting multimap, yielding a multimap with the same
size as this iterable. The key used to store that value in the multimap will be the result of
calling the function on that value. The resulting multimap is created as an immutable snapshot.
In the returned multimap, keys appear in the order they are first encountered, and the values
corresponding to each key appear in the same order as they are encountered.public final <K> ImmutableMap<K,T> uniqueIndex(Function<? super T,K> keyFunction)
FluentIterable as its values, indexed
by keys derived from those values. In other words, each input value produces an entry in the
map whose key is the result of applying keyFunction to that value. These entries appear
in the same order as they appeared in this fluent iterable. Example usage:
Color red = new Color("red", 255, 0, 0);
...
FluentIterable<Color> allColors = FluentIterable.from(ImmutableSet.of(red, green, blue));
Map<String, Color> colorForName = allColors.uniqueIndex(toStringFunction());
assertThat(colorForName).containsEntry("red", red);
If your index may associate multiple values with each key, use index.
public final T[] toArray(Class<T> type)
public final <C extends Collection<? super T>> C copyInto(C collection)
collection. This is equivalent to
calling Iterables.addAll(collection, this).public final String join(Joiner joiner)
String containing all of the elements of this fluent iterable joined with
joiner.public final T get(int position)
public final Iterable<T> toSimpleIterable()
isEmpty(). This is useful with libraries
that use reflection to determine bean definitions such as Jackson.
Note this will prevent access to close the underlying resource. It is suggested that autoClose() be used
before calling this method.Copyright © 2018 Calrissian. All rights reserved.