home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / COM / objectspace / jgl / HashMapIterator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-03-12  |  2.7 KB  |  168 lines

  1. package COM.objectspace.jgl;
  2.  
  3. public final class HashMapIterator implements ForwardIterator {
  4.    public static final int PAIR = 1;
  5.    public static final int KEY = 2;
  6.    public static final int VALUE = 3;
  7.    HashMap myHashMap;
  8.    HashMap.HashMapNode myNode;
  9.    int myMode = 1;
  10.  
  11.    public HashMapIterator() {
  12.    }
  13.  
  14.    public HashMapIterator(HashMapIterator var1) {
  15.       this.myHashMap = var1.myHashMap;
  16.       this.myNode = var1.myNode;
  17.       this.myMode = var1.myMode;
  18.    }
  19.  
  20.    HashMapIterator(HashMap.HashMapNode var1, HashMap var2, int var3) {
  21.       this.myHashMap = var2;
  22.       this.myNode = var1;
  23.       this.myMode = var3;
  24.    }
  25.  
  26.    public Object clone() {
  27.       return new HashMapIterator(this);
  28.    }
  29.  
  30.    public boolean equals(Object var1) {
  31.       if (var1 instanceof HashMapIterator) {
  32.          HashMapIterator var2 = (HashMapIterator)var1;
  33.          if (this.myNode == var2.myNode || false) {
  34.             return true;
  35.          }
  36.       }
  37.  
  38.       return false;
  39.    }
  40.  
  41.    public boolean equals(HashMapIterator var1) {
  42.       return this.myNode == var1.myNode;
  43.    }
  44.  
  45.    public boolean atBegin() {
  46.       for(int var1 = 0; var1 < this.myHashMap.length; ++var1) {
  47.          if (this.myHashMap.buckets[var1] != null) {
  48.             if (this.myNode != this.myHashMap.buckets[var1]) {
  49.                return false;
  50.             }
  51.  
  52.             return true;
  53.          }
  54.       }
  55.  
  56.       return true;
  57.    }
  58.  
  59.    public boolean atEnd() {
  60.       return this.myNode == null;
  61.    }
  62.  
  63.    public boolean hasMoreElements() {
  64.       return this.myNode != null;
  65.    }
  66.  
  67.    public void advance() {
  68.       this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode);
  69.    }
  70.  
  71.    public void advance(int var1) {
  72.       if (var1 < 0) {
  73.          throw new InvalidOperationException("Attempt to advance a ForwardIterator in the wrong direction.");
  74.       } else {
  75.          while(var1-- > 0) {
  76.             this.advance();
  77.          }
  78.  
  79.       }
  80.    }
  81.  
  82.    public Object nextElement() {
  83.       Object var1 = null;
  84.       switch (this.myMode) {
  85.          case 1:
  86.             var1 = new Pair(this.myNode.key, this.myNode.value);
  87.             break;
  88.          case 2:
  89.             var1 = this.myNode.key;
  90.             break;
  91.          case 3:
  92.             var1 = this.myNode.value;
  93.       }
  94.  
  95.       this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode);
  96.       return var1;
  97.    }
  98.  
  99.    public Object get() {
  100.       switch (this.myMode) {
  101.          case 1:
  102.             return new Pair(this.myNode.key, this.myNode.value);
  103.          case 2:
  104.             return this.myNode.key;
  105.          case 3:
  106.             return this.myNode.value;
  107.          default:
  108.             return null;
  109.       }
  110.    }
  111.  
  112.    public void put(Object var1) {
  113.       switch (this.myMode) {
  114.          case 1:
  115.             Pair var2 = (Pair)var1;
  116.             this.myNode.key = var2.first;
  117.             this.myNode.value = var2.second;
  118.             return;
  119.          case 2:
  120.             this.myNode.key = var1;
  121.             return;
  122.          case 3:
  123.             this.myNode.value = var1;
  124.             return;
  125.          default:
  126.       }
  127.    }
  128.  
  129.    public Object key() {
  130.       return this.myNode.key;
  131.    }
  132.  
  133.    public Object value() {
  134.       return this.myNode.value;
  135.    }
  136.  
  137.    public void value(Object var1) {
  138.       this.myNode.value = var1;
  139.    }
  140.  
  141.    public int distance(ForwardIterator var1) {
  142.       HashMap.HashMapNode var2 = this.myNode;
  143.       HashMap.HashMapNode var3 = ((HashMapIterator)var1).myNode;
  144.  
  145.       int var4;
  146.       for(var4 = 0; this.myNode != var3; this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode)) {
  147.          ++var4;
  148.       }
  149.  
  150.       this.myNode = var2;
  151.       return var4;
  152.    }
  153.  
  154.    private HashMap.HashMapNode next(HashMap.HashMapNode var1) {
  155.       for(int var2 = var1.hash % this.myHashMap.length + 1; var2 < this.myHashMap.length; ++var2) {
  156.          if (this.myHashMap.buckets[var2] != null) {
  157.             return this.myHashMap.buckets[var2];
  158.          }
  159.       }
  160.  
  161.       return null;
  162.    }
  163.  
  164.    public Container getContainer() {
  165.       return this.myHashMap;
  166.    }
  167. }
  168.