See More

package simpledb; import java.util.*; /** * Implements a OpIterator by wrapping an Iterable. */ public class TupleIterator implements OpIterator { /** * */ private static final long serialVersionUID = 1L; Iterator i = null; TupleDesc td = null; Iterable tuples = null; /** * Constructs an iterator from the specified Iterable, and the specified * descriptor. * * @param tuples * The set of tuples to iterate over */ public TupleIterator(TupleDesc td, Iterable tuples) { this.td = td; this.tuples = tuples; // check that all tuples are the right TupleDesc for (Tuple t : tuples) { if (!t.getTupleDesc().equals(td)) throw new IllegalArgumentException( "incompatible tuple in tuple set"); } } public void open() { i = tuples.iterator(); } public boolean hasNext() { return i.hasNext(); } public Tuple next() { return i.next(); } public void rewind() { close(); open(); } public TupleDesc getTupleDesc() { return td; } public void close() { i = null; } }