home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / netscape / util / HashtableEnumerator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  896 b   |  39 lines

  1. package netscape.util;
  2.  
  3. class HashtableEnumerator implements Enumeration {
  4.    boolean keyEnum;
  5.    int index;
  6.    int returnedCount;
  7.    Hashtable table;
  8.  
  9.    HashtableEnumerator(Hashtable var1, boolean var2) {
  10.       this.table = var1;
  11.       this.keyEnum = var2;
  12.       this.returnedCount = 0;
  13.       if (var1.keys != null) {
  14.          this.index = var1.keys.length;
  15.       } else {
  16.          this.index = 0;
  17.       }
  18.    }
  19.  
  20.    public boolean hasMoreElements() {
  21.       return this.returnedCount < this.table.count;
  22.    }
  23.  
  24.    public Object nextElement() {
  25.       --this.index;
  26.  
  27.       while(this.index >= 0 && this.table.elements[this.index] == null) {
  28.          --this.index;
  29.       }
  30.  
  31.       if (this.index >= 0 && this.returnedCount < this.table.count) {
  32.          ++this.returnedCount;
  33.          return this.keyEnum ? this.table.keys[this.index] : this.table.elements[this.index];
  34.       } else {
  35.          throw new NoSuchElementException();
  36.       }
  37.    }
  38. }
  39.