edu.rice.cs.plt.iter
Class ReadOnceIterable<T>

java.lang.Object
  extended by 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.


Constructor Summary
ReadOnceIterable(Iterator<T> iter)
           
 
Method Summary
 Iterator<T> iterator()
           
static
<T> ReadOnceIterable<T>
make(Iterator<T> iter)
          Call the constructor (allows T to be inferred)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadOnceIterable

public ReadOnceIterable(Iterator<T> iter)
Method Detail

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)