home *** CD-ROM | disk | FTP | other *** search
- package Acme;
-
- import java.util.Enumeration;
- import java.util.NoSuchElementException;
-
- class IntHashtableEnumerator implements Enumeration {
- boolean keys;
- int index;
- IntHashtableEntry[] table;
- IntHashtableEntry entry;
-
- IntHashtableEnumerator(IntHashtableEntry[] table, boolean keys) {
- this.table = table;
- this.keys = keys;
- this.index = table.length;
- }
-
- public boolean hasMoreElements() {
- if (this.entry != null) {
- return true;
- } else {
- while(this.index-- > 0) {
- if ((this.entry = this.table[this.index]) != null) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public Object nextElement() {
- if (this.entry == null) {
- while(this.index-- > 0 && (this.entry = this.table[this.index]) == null) {
- }
- }
-
- if (this.entry != null) {
- IntHashtableEntry e = this.entry;
- this.entry = e.next;
- return this.keys ? new Integer(e.key) : e.value;
- } else {
- throw new NoSuchElementException("IntHashtableEnumerator");
- }
- }
- }
-