public class IteratorIterable<E> extends Objectimplements Iterable <E>
Iterator instance appear to be an
Iterable instance. The iterable can be constructed in one of two variants: single use, multiple use.
In the single use iterable case, the iterable is only usable for one iterative operation over the source iterator. Subsequent iterative operations use the same, exhausted source iterator. To create a single use iterable, construct a new IteratorIterable using a Iterator that is NOT a ResettableIterator iterator:
Iterator
iterator = // some non-resettable iterator
Iterable
iterable = new IteratorIterable
(iterator);
In the multiple use iterable case, the iterable is usable for any number of iterative operations over the source iterator. Of special note, even though the iterable supports multiple iterations, it does not support concurrent iterations. To implicitly create a multiple use iterable, construct a new IteratorIterable using a ResettableIterator iterator:
Integer[] array = {Integer.valueOf(1),Integer.valueOf(2),Integer.valueOf(3)};
Iterator
iterator = IteratorUtils.arrayIterator(array); // a resettable iterator
Iterable
iterable = new IteratorIterable
(iterator);
A multiple use iterable can also be explicitly constructed using any Iterator and specifying true for the multipleUse flag:
Iterator
iterator = // some non-resettable iterator
Iterable
iterable = new IteratorIterable
(iterator, true);
| Constructor and Description |
|---|
IteratorIterable(Iterator
Constructs a new
IteratorIterable that will use the given iterator.
|
IteratorIterable(Iterator
Constructs a new
IteratorIterable that will use the given iterator.
|
| Modifier and Type | Method and Description |
|---|---|
Iterator |
iterator()
Gets the iterator wrapped by this iterable.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliterator