Modifier and Type | Method and Description |
---|---|
static <T> Enumeration<T> |
asEnumeration(Iterator<T> iterator)
Adapts an
Iterator to the Enumeration interface. |
static <T> Iterator<T> |
concat(Iterator<? extends Iterator<? extends T>> inputs)
Combines multiple iterators into a single iterator.
|
static <T> UnmodifiableIterator<T> |
emptyIterator()
Returns the empty
Iterator . |
static <T> ListIterator<T> |
emptyListIterator()
Returns the empty
ListIterator . |
static <T> UnmodifiableIterator<T> |
forArray(T... array)
Returns an iterator containing the elements of
array in order. |
static <T> UnmodifiableIterator<T> |
forArray(T[] array,
int offset,
int length)
Returns an iterator containing the elements in the specified range of
array in order. |
static <T> T |
getOnlyElement(Iterator<T> iterator)
Returns the single element contained in
iterator . |
static <T> UnmodifiableIterator<T> |
singletonIterator(T value)
Returns an iterator containing only
value . |
static String |
toString(Iterator<?> iterator)
Returns a string representation of
iterator , with the format
[e1, e2, ..., en] . |
static <F,T> Iterator<T> |
transform(Iterator<F> fromIterator,
Function<? super F,? extends T> function)
Returns an iterator that applies
function to each element of fromIterator . |
static <T> UnmodifiableIterator<T> |
unmodifiableIterator(Iterator<T> iterator)
Returns an unmodifiable view of
iterator . |
public static <T> UnmodifiableIterator<T> emptyIterator()
Iterator
.public static <T> ListIterator<T> emptyListIterator()
ListIterator
.public static <T> UnmodifiableIterator<T> unmodifiableIterator(Iterator<T> iterator)
iterator
.public static String toString(Iterator<?> iterator)
iterator
, with the format
[e1, e2, ..., en]
. The iterator will be left exhausted: its
hasNext()
method will return false
.public static <T> T getOnlyElement(Iterator<T> iterator)
iterator
.NoSuchElementException
- if the iterator is emptyIllegalArgumentException
- if the iterator contains multiple
elements. The state of the iterator is unspecified.public static <T> Iterator<T> concat(Iterator<? extends Iterator<? extends T>> inputs)
inputs
. The input
iterators are not polled until necessary.
The returned iterator supports remove()
when the corresponding
input iterator supports it. The methods of the returned iterator may throw
NullPointerException
if any of the input iterators are null.
public static <F,T> Iterator<T> transform(Iterator<F> fromIterator, Function<? super F,? extends T> function)
function
to each element of fromIterator
.
The returned iterator supports remove()
if the provided iterator
does. After a successful remove()
call, fromIterator
no
longer contains the corresponding element.
public static <T> UnmodifiableIterator<T> forArray(T... array)
array
in order. The
returned iterator is a view of the array; subsequent changes to the array
will be reflected in the iterator.
Note: It is often preferable to represent your data using a
collection type, for example using Arrays.asList(Object[])
, making
this method unnecessary.
public static <T> UnmodifiableIterator<T> forArray(T[] array, int offset, int length)
array
in order. The returned iterator is a view of the array;
subsequent changes to the array will be reflected in the iterator.array
- array to read elements out ofoffset
- index of first array element to retrievelength
- number of elements in iterationIndexOutOfBoundsException
- if offset
is negative,
length
is negative, or offset + length > array.length
public static <T> UnmodifiableIterator<T> singletonIterator(@Nullable T value)
value
.public static <T> Enumeration<T> asEnumeration(Iterator<T> iterator)
Iterator
to the Enumeration
interface.Collections.enumeration(Collection)
Copyright © 2006-2012 Google, Inc.. All Rights Reserved.