private class KeyIterator implements Iterator
1: private class KeyIterator implements Iterator<K>
2: {
3: private int currentIndex; // Current position in hash table
4: private int numberLeft; // Number of entries left in iteration
5:
6: private KeyIterator()
7: {
8: currentIndex = 0;
9: numberLeft = numberOfEntries;
10: } // end default constructor
11:
12: public boolean hasNext()
13: {
14: return numberLeft > 0;
15: } // end hasNext
16:
17: public K next()
18: {
19: K result = null;
20:
21: if (hasNext())
22: {
23: // Skip table locations that do not contain a current entry
24: while ( (hashTable[currentIndex] == null) || hashTable[currentIndex].isRemoved() )
25: {
26: currentIndex++;
27: } // end while
28:
29: result = hashTable[currentIndex].getKey();
30: numberLeft--;
31: currentIndex++;
32: }
33: else
34: throw new NoSuchElementException();
35:
36: return result;
37: } // end next
38:
39: public void remove()
40: {
41: throw new UnsupportedOperationException();
42: } // end remove
43: } // end KeyIterator
44: // Version 4.0
45: