-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTupleIterator.java
More file actions
60 lines (50 loc) · 1.24 KB
/
TupleIterator.java
File metadata and controls
60 lines (50 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package simpledb;
import java.util.*;
/**
* Implements a OpIterator by wrapping an Iterable<Tuple>.
*/
public class TupleIterator implements OpIterator {
/**
*
*/
private static final long serialVersionUID = 1L;
Iterator<Tuple> i = null;
TupleDesc td = null;
Iterable<Tuple> 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<Tuple> 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;
}
}