home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / Notes.jar / Acme / IntHashtableEnumerator.class (.txt) < prev   
Encoding:
Java Class File  |  1998-11-16  |  1.2 KB  |  47 lines

  1. package Acme;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.NoSuchElementException;
  5.  
  6. class IntHashtableEnumerator implements Enumeration {
  7.    boolean keys;
  8.    int index;
  9.    IntHashtableEntry[] table;
  10.    IntHashtableEntry entry;
  11.  
  12.    IntHashtableEnumerator(IntHashtableEntry[] table, boolean keys) {
  13.       this.table = table;
  14.       this.keys = keys;
  15.       this.index = table.length;
  16.    }
  17.  
  18.    public boolean hasMoreElements() {
  19.       if (this.entry != null) {
  20.          return true;
  21.       } else {
  22.          while(this.index-- > 0) {
  23.             if ((this.entry = this.table[this.index]) != null) {
  24.                return true;
  25.             }
  26.          }
  27.  
  28.          return false;
  29.       }
  30.    }
  31.  
  32.    public Object nextElement() {
  33.       if (this.entry == null) {
  34.          while(this.index-- > 0 && (this.entry = this.table[this.index]) == null) {
  35.          }
  36.       }
  37.  
  38.       if (this.entry != null) {
  39.          IntHashtableEntry e = this.entry;
  40.          this.entry = e.next;
  41.          return this.keys ? new Integer(e.key) : e.value;
  42.       } else {
  43.          throw new NoSuchElementException("IntHashtableEnumerator");
  44.       }
  45.    }
  46. }
  47.