HashMap
[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.next!=null)
16             return true;
17         int i=bin;
18         while(map.table[i]==null&&(i<map.table.length))
19             i++;
20         return (i<map.table.length);
21     }
22
23     public Object next() {
24         if (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((map.table[bin]==null)&&(bin<map.table.length))
34             bin++;
35         if (bin<map.table.length) {
36             he=map.table[bin];
37             Object o;
38             if (type==0)
39                 o=he.key;
40             else
41                 o=he.value;
42             return o;
43         } else System.error();
44     }
45
46 }