|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.collect.Iterables
public final class Iterables
This class contains static utility methods that operate on or return objects
of type Iterable. Also see the parallel implementations in Iterators.
| Method Summary | ||
|---|---|---|
static
|
addAll(Collection<T> collection,
Iterable<? extends T> iterable)
Adds all elements in iterable to collection. |
|
static
|
all(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns true if no element in iterable evaluates to false under predicate. |
|
static
|
any(Iterable<T> iterable,
Predicate<? super T> predicate)
Returns true if some element in iterable evaluates to
true under predicate. |
|
static
|
concat(Iterable<? extends Iterable<? extends T>> iterables)
Variant of Iterators.concat that acts on and returns instances of
Iterable. |
|
static
|
concat(Iterable<? extends T>... iterables)
Variant of Iterators.concat that acts on and returns instances of
Iterable. |
|
static
|
concat(Iterable<? extends T> firstElements,
Iterable<? extends T> nextElements)
Variant of Iterators.concat that acts on and returns instances of
Iterable. |
|
static
|
cycle(Iterable<T> iterable)
Variant of Iterators.cycle which returns an Iterable. |
|
static
|
cycle(T... elements)
Variant of cycle(Iterable) accepting varargs parameters. |
|
static boolean |
elementsEqual(Iterable<?> iterable1,
Iterable<?> iterable2)
Determines whether the two Iterables contain equal elements. |
|
static
|
emptyIterable()
Returns the empty Iterable. |
|
static
|
filter(Iterable<?> unfiltered,
Class<T> type)
Returns all instances of type found in unfiltered. |
|
static
|
filter(Iterable<T> unfiltered,
Predicate<? super T> predicate)
Variant of Iterators.filter(Iterator,Predicate), which accepts and
returns an iterable instead of an iterator. |
|
static
|
find(Iterable<E> iterable,
Predicate<? super E> predicate)
Returns the first element in iterable for which the given predicate
matches. |
|
static int |
frequency(Iterable<?> iterable,
Object element)
Variant of Collections.frequency for iterables. |
|
static
|
getOnlyElement(Iterable<T> iterable)
Returns the single element contained in iterable. |
|
static
|
getOnlyElement(Iterable<T> iterable,
T defaultValue)
Returns the single element contained in iterator, or defaultValue if the iterator is empty. |
|
static
|
newArray(Iterable<T> iterable,
Class<T> type)
Converts an Iterable into an array. |
|
static
|
partition(Iterable<? extends T> iterable,
int partitionSize,
boolean padToSize)
Partition an iterable into sub iterables of the given size like so: {A, B, C, D, E, F} with partition size 3 => {A, B, C} and {D, E, F}. |
|
static
|
reverse(List<T> list)
Adapt a list to an Iterable over a reversed version of the list. |
|
static
|
rotate(List<T> list,
int distance)
Provides a rotated view of a list. |
|
static String |
toString(Iterable<?> iterable)
Returns a string representation of iterable in the same format as
Iterators#toString(java.util.Iterator). |
|
static
|
transform(Iterable<F> fromIterable,
Function<? super F,? extends T> function)
Returns an iterable that applies function to each element of fromIterable. |
|
static
|
unmodifiableIterable(Iterable<T> iterable)
Returns an unmodifiable view of iterable. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> Iterable<T> emptyIterable()
public static <T> Iterable<T> unmodifiableIterable(Iterable<T> iterable)
iterable.
public static boolean elementsEqual(Iterable<?> iterable1,
Iterable<?> iterable2)
true if iterable1 and
iterable2 contain the same number of elements and every element of
iterable1 is equal to the corresponding element of iterable2.
public static String toString(Iterable<?> iterable)
iterable in the same format as
Iterators#toString(java.util.Iterator).
public static <T> T getOnlyElement(Iterable<T> iterable)
iterable.
NoSuchElementException - if the iterable is empty
IllegalArgumentException - if the iterable contains multiple
elements
public static <T> T getOnlyElement(Iterable<T> iterable,
@Nullable
T defaultValue)
iterator, or defaultValue if the iterator is empty.
IllegalArgumentException - if the iterator contains multiple
elements
public static <T> T[] newArray(Iterable<T> iterable,
Class<T> type)
Iterable into an array.
iterable - any instance of Iterable (will not be modified)type - the type of the elements
public static <T> boolean addAll(Collection<T> collection,
Iterable<? extends T> iterable)
iterable to collection.
true if collection was modified as a result of this
operation.
public static int frequency(Iterable<?> iterable,
@Nullable
Object element)
Collections.frequency for iterables.
public static <T> Iterable<T> cycle(Iterable<T> iterable)
Iterators.cycle which returns an Iterable.
Iterators.cycle(Iterable)public static <T> Iterable<T> cycle(T... elements)
cycle(Iterable) accepting varargs parameters.
public static <T> Iterable<T> concat(Iterable<? extends T> firstElements,
Iterable<? extends T> nextElements)
Iterators.concat that acts on and returns instances of
Iterable.
public static <T> Iterable<T> concat(Iterable<? extends T>... iterables)
Iterators.concat that acts on and returns instances of
Iterable.
public static <T> Iterable<T> concat(Iterable<? extends Iterable<? extends T>> iterables)
Iterators.concat that acts on and returns instances of
Iterable.
public static <T> Iterable<Iterable<T>> partition(Iterable<? extends T> iterable,
int partitionSize,
boolean padToSize)
NOTE: You must read partitions one at a time from the returned iterable Once you read forward any iterables from previous partitions will become invalid.
NOTE: This is optimized for a the simple case of iterating through each sub-iterable in order only once. Other operations will succeed, but will suffer a performance penalty to maintain correctness.
iterable - the iterable to partitionpartitionSize - the size of each partitionpadToSize - whether to pad the last partition to the partition size
with null.
public static <T> Iterable<T> filter(Iterable<T> unfiltered,
Predicate<? super T> predicate)
Iterators.filter(Iterator,Predicate), which accepts and
returns an iterable instead of an iterator.
Iterators.filter(Iterator, Predicate)
public static <T> Iterable<T> filter(Iterable<?> unfiltered,
Class<T> type)
type found in unfiltered. Similar
to filter(Iterable,Predicate).
unfiltered - an iterable containing objects of any typetype - the type of elements desired
public static <T> boolean any(Iterable<T> iterable,
Predicate<? super T> predicate)
true if some element in iterable evaluates to
true under predicate. Returns false if iterable is empty.
public static <T> boolean all(Iterable<T> iterable,
Predicate<? super T> predicate)
true if no element in iterable evaluates to false under predicate. Returns true if iterable is
empty.
public static <E> E find(Iterable<E> iterable,
Predicate<? super E> predicate)
iterable for which the given predicate
matches.
NoSuchElementException - if no element in iterable matches
the given predicate
public static <F,T> Iterable<T> transform(Iterable<F> fromIterable,
Function<? super F,? extends T> function)
function to each element of fromIterable.
public static <T> Iterable<T> reverse(List<T> list)
Listmylist = ... for (String str : Iterables.reverse(mylist)) { ... }
public static <T> Iterable<T> rotate(List<T> list,
int distance)
Collections.rotate(java.util.List>, int)
only in that it leaves the underlying list unchanged. Note that this is a
"live" view of the list that will change as the list changes. However, the
behavior of an Iterator constructed from a rotated view of the list
is undefined if the list is changed after the Iterator is constructed.
list - the list to return a rotated view of.distance - the distance to rotate the list. There are no constraints
on this value; it may be zero, negative, or greater than list.size().
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||