|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectorg.tbull.util.Collections.LazyMapIterator<I,O>
public static class Collections.LazyMapIterator<I,O>
An iterator that provides the mapLazy
functionality.
The lazy iterator guarantees to fetch only one element from the input lists/iterators at each call to
next()
. Also, an input list/iterator is not queried before the input before it is exhausted.
You can get the lazy iterator by direct instantiation or using one of the mapLazy
functions.
RuntimeException
s from the input iterators are passed along. Notably, the iterators from the
Collections framework throw ConcurrentModificationException
when they detect you didn't synchronize properly.
This iterator implements Iterator
and Iterable
at the same time. In case you chain
multiple grep/map
invocations as in
mapLazy(mapper2, mapLazy(mapper1, lists))
there arises an ambiguity, because the functions come in an overloaded version for each of them
to take as input, so the compiler will not know which version to choose. You can easily resolve the
ambiguity by either invoking the iterator()
method on the intermediate IterableIterator
like
mapLazy(mapper2, mapLazy(mapper1, lists).iterator())
or by casting it to a pure Iterator
mapLazy(mapper2, (Iterator) mapLazy(mapper1, lists))
.
Constructor Summary | |
---|---|
Collections.LazyMapIterator(Mapper<? super I,? extends O> mapper,
Iterable<I>[] lists)
Constructs a LazyMapIterator that iterates over the given iterables (lists). |
|
Collections.LazyMapIterator(Mapper<? super I,? extends O> mapper,
Iterator<I>[] iterators)
Constructs a LazyMapIterator that fetches from the given iterators. |
Method Summary | |
---|---|
boolean |
hasNext()
|
Iterator<O> |
iterator()
|
O |
next()
|
void |
remove()
Always throws UnsupportedOperationException . |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Collections.LazyMapIterator(Mapper<? super I,? extends O> mapper, Iterable<I>[] lists)
public Collections.LazyMapIterator(Mapper<? super I,? extends O> mapper, Iterator<I>[] iterators)
Method Detail |
---|
public boolean hasNext()
hasNext
in interface Iterator<O>
public O next() throws NoSuchElementException
next
in interface Iterator<O>
NoSuchElementException
public void remove() throws UnsupportedOperationException
UnsupportedOperationException
.
remove
in interface Iterator<O>
UnsupportedOperationException
public Iterator<O> iterator()
iterator
in interface Iterable<O>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |