private class KeyIterator implements Iterator
1: // Since iterators implement Iterator, methods must be public
2: private class KeyIterator implements Iterator<K>
3: {
4: private Node nextNode;
5:
6: private KeyIterator()
7: {
8: nextNode = firstNode;
9: } // end default constructor
10:
11: public boolean hasNext()
12: {
13: return nextNode != null;
14: } // end hasNext
15:
16: public K next()
17: {
18: K result;
19:
20: if (hasNext())
21: {
22: result = nextNode.getKey();
23: nextNode = nextNode.getNextNode();
24: }
25: else
26: {
27: throw new NoSuchElementException();
28: } // end if
29:
30: return result;
31: } // end next
32:
33: public void remove()
34: {
35: throw new UnsupportedOperationException();
36: } // end remove
37: } // end KeyIterator