|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.collect.Iterators
public final class Iterators
This class contains static utility methods that operate on or return objects
of type Iterator. Also see the parallel implementations in Iterables.
| Method Summary | ||
|---|---|---|
static
|
addAll(Collection<T> collection,
Iterator<? extends T> iterator)
Adds all elements in iterator to collection. |
|
static
|
all(Iterator<T> iterator,
Predicate<? super T> predicate)
Returns true if no element returned by iterator evaluates
to false under predicate. |
|
static
|
any(Iterator<T> iterator,
Predicate<? super T> predicate)
Returns true if some element returned by iterator evaluates
to true under predicate. |
|
static
|
asEnumeration(Iterator<T> iterator)
Adapts an Iterator to the Enumeration interface. |
|
static
|
concat(Iterator<? extends Iterator<? extends T>> iterators)
Concatenates multiple iterators into a single iterator. |
|
static
|
concat(Iterator<? extends T>... iterators)
Varargs form of #concat(Iterator). |
|
static
|
concat(Iterator<? extends T> a,
Iterator<? extends T> b)
Two-argument form of #concat(Iterator). |
|
static
|
cycle(Iterable<T> iterable)
Returns an iterator that cycles indefinitely over the elements of iterable until it is empty. |
|
static
|
cycle(T... elements)
Variant of #cycle(Iterable) accepting varargs parameters. |
|
static boolean |
elementsEqual(Iterator<?> iterator1,
Iterator<?> iterator2)
Determines whether two iterators contain equal elements. |
|
static
|
emptyIterator()
Returns the empty Iterator. |
|
static
|
filter(Iterator<?> unfiltered,
Class<T> type)
Returns all instances of type found in unfiltered. |
|
static
|
filter(Iterator<T> unfiltered,
Predicate<? super T> predicate)
Returns the elements of unfiltered for which predicate
evaluates to true. |
|
static
|
find(Iterator<E> iterator,
Predicate<? super E> predicate)
Returns the first element in iterator for which the given predicate
matches. |
|
static
|
forEnumeration(Enumeration<T> enumeration)
Adapts an Enumeration to the Iterator interface. |
|
static int |
frequency(Iterator<?> iterator,
Object element)
Variant of Collections#frequency for iterators. |
|
static
|
getOnlyElement(Iterator<T> iterator)
Returns the single element contained in iterator. |
|
static
|
getOnlyElement(Iterator<T> iterator,
T defaultValue)
Returns the single element contained in iterator, or defaultValue if the iterator is empty. |
|
static
|
newArray(Iterator<T> iterator,
Class<T> type)
Converts an Iterator into an array. |
|
static
|
partition(Iterator<? extends T> iterator,
int partitionSize,
boolean padToSize)
Partition an iterator into sub iterators of the given size like so: {A, B, C, D, E, F} with partition size 3 => {A, B, C} and {D, E, F}. |
|
static String |
toString(Iterator<?> iterator)
Returns a string representation of the elements in iterator, in the
format "[e1, e2, ..., en]". |
|
static
|
transform(Iterator<F> fromIterator,
Function<? super F,? extends T> function)
Returns an iterator that applies function to each element of fromIterator. |
|
static
|
unmodifiableIterator(Iterator<T> iterator)
Returns an unmodifiable view of iterator. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> Iterator<T> emptyIterator()
public static <T> Iterator<T> unmodifiableIterator(Iterator<T> iterator)
iterator.
public static boolean elementsEqual(Iterator<?> iterator1,
Iterator<?> iterator2)
true if iterator1 and iterator2 contain the same number of elements and every element of iterator1 is equal to the corresponding element of iterator2.
Note that this will actually modify the supplied iterators such that they will not be usable after calling this method (they will have been advanced some number of elements forward).
public static String toString(Iterator<?> iterator)
iterator, in the
format "[e1, e2, ..., en]".
public static <T> T getOnlyElement(Iterator<T> iterator)
iterator.
NoSuchElementException - if the iterator is empty
IllegalArgumentException - if the iterator contains multiple
elements
public static <T> T getOnlyElement(Iterator<T> iterator,
@Nullable
T defaultValue)
iterator, or defaultValue if the iterator is empty.
IllegalArgumentException - if the iterator contains multiple
elements
public static <T> T[] newArray(Iterator<T> iterator,
Class<T> type)
Iterator into an array.
iterator - any instance of Iterator (will not be modified)type - the type of the elements
public static <T> boolean addAll(Collection<T> collection,
Iterator<? extends T> iterator)
iterator to collection.
true if collection was modified as a result of this
operation.
public static int frequency(Iterator<?> iterator,
@Nullable
Object element)
Collections#frequency for iterators.
public static <T> Iterator<T> cycle(Iterable<T> iterable)
iterable until it 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 static <T> Iterator<T> cycle(T... elements)
#cycle(Iterable) accepting varargs parameters.
public static <T> Iterator<T> concat(Iterator<? extends T> a,
Iterator<? extends T> b)
#concat(Iterator).
public static <T> Iterator<T> concat(Iterator<? extends T>... iterators)
#concat(Iterator).
public static <T> Iterator<T> concat(Iterator<? extends Iterator<? extends T>> iterators)
The returned iterator supports Iterator.remove() when and only
when the appropriate source iterator supports it. The methods of the
returned iterator may throw NullPointerException if any of the
source iterators are null.
public static <T> Iterator<Iterator<T>> partition(Iterator<? extends T> iterator,
int partitionSize,
boolean padToSize)
NOTE: You must read partitions one at a time from the returned iterator Once you read forward any iterators from previous partitions will become invalid.
iterator - the iterator to partitionpartitionSize - the size of each partitionpadToSize - whether to pad the last partition to the partition size
with null
public static <T> Iterator<T> filter(Iterator<T> unfiltered,
Predicate<? super T> predicate)
unfiltered for which predicate
evaluates to true. May return an empty iterator, but never null. The resulting iterator does not support Iterator.remove().
public static <T> Iterator<T> filter(Iterator<?> unfiltered,
Class<T> type)
type found in unfiltered. Similar
to filter(Iterator,Predicate).
unfiltered - an iterator containing objects of any typetype - the type of elements desired
public static <T> boolean any(Iterator<T> iterator,
Predicate<? super T> predicate)
true if some element returned by iterator evaluates
to true under predicate. Returns false if iterator is empty.
public static <T> boolean all(Iterator<T> iterator,
Predicate<? super T> predicate)
true if no element returned by iterator evaluates
to false under predicate. Returns true if iterator is empty.
public static <E> E find(Iterator<E> iterator,
Predicate<? super E> predicate)
iterator for which the given predicate
matches. If a matching element is found, the iterator will be left in a
state such that calling iterator.remove() will remove the found
item. If no such element is found, the iterator will be left exhausted such
that iterator.hasNext() returns false.
iterator
NoSuchElementException - if no element in iterator matches
the given predicate
public static <F,T> Iterator<T> transform(Iterator<F> fromIterator,
Function<? super F,? extends T> function)
function to each element of fromIterator.
public static <T> Iterator<T> forEnumeration(Enumeration<T> enumeration)
public static <T> Enumeration<T> asEnumeration(Iterator<T> iterator)
Collections.enumeration(Collection)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||