Implements a OpIterator by wrapping an Iterable .
| 8 | * Implements a OpIterator by wrapping an Iterable<Tuple>. |
| 9 | */ |
| 10 | public class TupleIterator implements OpIterator { |
| 11 | /** |
| 12 | * |
| 13 | */ |
| 14 | private static final long serialVersionUID = 1L; |
| 15 | Iterator<Tuple> i = null; |
| 16 | TupleDesc td = null; |
| 17 | Iterable<Tuple> tuples = null; |
| 18 | |
| 19 | /** |
| 20 | * Constructs an iterator from the specified Iterable, and the specified |
| 21 | * descriptor. |
| 22 | * |
| 23 | * @param tuples |
| 24 | * The set of tuples to iterate over |
| 25 | */ |
| 26 | public TupleIterator(TupleDesc td, Iterable<Tuple> tuples) { |
| 27 | this.td = td; |
| 28 | this.tuples = tuples; |
| 29 | |
| 30 | // check that all tuples are the right TupleDesc |
| 31 | for (Tuple t : tuples) { |
| 32 | if (!t.getTupleDesc().equals(td)) |
| 33 | throw new IllegalArgumentException( |
| 34 | "incompatible tuple in tuple set"); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public void open() { |
| 39 | i = tuples.iterator(); |
| 40 | } |
| 41 | |
| 42 | public boolean hasNext() { |
| 43 | return i.hasNext(); |
| 44 | } |
| 45 | |
| 46 | public Tuple next() { |
| 47 | return i.next(); |
| 48 | } |
| 49 | |
| 50 | public void rewind() { |
| 51 | close(); |
| 52 | open(); |
| 53 | } |
| 54 | |
| 55 | public TupleDesc getTupleDesc() { |
| 56 | return td; |
| 57 | } |
| 58 | |
| 59 | public void close() { |
| 60 | i = null; |
| 61 | } |
| 62 | } |
nothing calls this directly
no outgoing calls
no test coverage detected