-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractDbFileIterator.java
More file actions
36 lines (28 loc) · 1.12 KB
/
AbstractDbFileIterator.java
File metadata and controls
36 lines (28 loc) · 1.12 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
package simpledb;
import java.util.NoSuchElementException;
/** Helper for implementing DbFileIterators. Handles hasNext()/next() logic. */
public abstract class AbstractDbFileIterator implements DbFileIterator {
public boolean hasNext() throws DbException, TransactionAbortedException {
if (next == null) next = readNext();
return next != null;
}
public Tuple next() throws DbException, TransactionAbortedException,
NoSuchElementException {
if (next == null) {
next = readNext();
if (next == null) throw new NoSuchElementException();
}
Tuple result = next;
next = null;
return result;
}
/** If subclasses override this, they should call super.close(). */
public void close() {
// Ensures that a future call to next() will fail
next = null;
}
/** Reads the next tuple from the underlying source.
@return the next Tuple in the iterator, null if the iteration is finished. */
protected abstract Tuple readNext() throws DbException, TransactionAbortedException;
private Tuple next = null;
}