add more comments
[IRC.git] / Robust / src / ClassLibrary / HashMapIterator.java
1 class HashMapIterator {
2     HashMap map;
3     int type;
4     int bin;
5     HashEntry he;
6
7     public HashMapIterator(HashMap map, int type) {
8         this.map=map;
9         this.type=type;
10         this.bin=0;
11         this.he=null;
12     }
13
14     public boolean hasNext() {
15         if (he!=null&&he.next!=null)
16             return true;
17         int i=bin;
18         while((i<map.table.length)&&map.table[i]==null)
19             i++;
20         return (i<map.table.length);
21     }
22
23     public Object next() {
24         if (he!=null&&he.next!=null) {
25             he=he.next;
26             Object o;
27             if (type==0)
28                 o=he.key;
29             else
30                 o=he.value;
31             return o;
32         }
33         while((bin<map.table.length)&&
34               (map.table[bin]==null))
35             bin++;
36         if (bin<map.table.length) {
37             he=map.table[bin++];
38             Object o;
39             if (type==0)
40                 o=he.key;
41             else
42                 o=he.value;
43             return o;
44         } else System.error();
45     }
46 }