-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashTableIterator.java
50 lines (43 loc) · 1.09 KB
/
HashTableIterator.java
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
import java.util.Iterator;
public class HashTableIterator implements Iterator<Term> {
private int max;
private int current;
private Term[] table;
private Term nextTerm;
HashTableIterator(Term[] table){
max = table.length-1;
//Current starts at -1 because getNext begins checking at current+1
current = -1;
this.table = table;
nextTerm = getNext();
}
@Override
public boolean hasNext() {
return (nextTerm != null);
}
@Override
public Term next() {
Term ret = nextTerm;
nextTerm = getNext();
return ret;
}
@Override
public void remove() {
}
private Term getNext(){
//Find next non-null/reserved term.
for(int i = (current + 1); i<= max; i++){
try {
Term t = table[i];
if(t.getWord() != "RESERVED")
{
current = i;
return t;
}
}
catch (NullPointerException e){}
}
//No more terms
return null;
}
}