edu.rice.cs.plt.iter
Class ReadOnceIterable<T>
java.lang.Object
edu.rice.cs.plt.iter.ReadOnceIterable<T>
- All Implemented Interfaces:
- Iterable<T>
public class ReadOnceIterable<T>
- extends Object
- implements Iterable<T>
An iterable that simply wraps an Iterator. Unlike most iterables,
state changes on the wrapped iterator (such as advancing) are reflected across
invocations of iterator(); once the iterator has been traversed,
this iterable is effectively empty. While these semantics are inconvenient at
times, they also allow a very lightweight implementation. Clients that need
to traverse an iterator multiple times (or that need a SizedIterable)
can use a SnapshotIterable instead, at the expense of copying and
storing the entire contents of the iterator.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReadOnceIterable
public ReadOnceIterable(Iterator<T> iter)
iterator
public Iterator<T> iterator()
- Specified by:
iterator in interface Iterable<T>
make
public static <T> ReadOnceIterable<T> make(Iterator<T> iter)
- Call the constructor (allows
T to be inferred)