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 / HashSetIterator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-03-12  |  2.2 KB  |  121 lines

  1. package COM.objectspace.jgl;
  2.  
  3. public final class HashSetIterator implements ForwardIterator {
  4.    HashSet myHashSet;
  5.    HashSet.HashSetNode myNode;
  6.  
  7.    public HashSetIterator() {
  8.    }
  9.  
  10.    public HashSetIterator(HashSetIterator var1) {
  11.       this.myHashSet = var1.myHashSet;
  12.       this.myNode = var1.myNode;
  13.    }
  14.  
  15.    HashSetIterator(HashSet.HashSetNode var1, HashSet var2) {
  16.       this.myHashSet = var2;
  17.       this.myNode = var1;
  18.    }
  19.  
  20.    public Object clone() {
  21.       return new HashSetIterator(this);
  22.    }
  23.  
  24.    public boolean equals(Object var1) {
  25.       if (var1 instanceof HashSetIterator) {
  26.          HashSetIterator var2 = (HashSetIterator)var1;
  27.          if (this.myNode == var2.myNode || false) {
  28.             return true;
  29.          }
  30.       }
  31.  
  32.       return false;
  33.    }
  34.  
  35.    public boolean equals(HashSetIterator var1) {
  36.       return this.myNode == var1.myNode;
  37.    }
  38.  
  39.    public boolean atBegin() {
  40.       if (this.myHashSet == null) {
  41.          return false;
  42.       } else {
  43.          for(int var1 = 0; var1 < this.myHashSet.length; ++var1) {
  44.             if (this.myHashSet.buckets[var1] != null) {
  45.                if (this.myNode != this.myHashSet.buckets[var1]) {
  46.                   return false;
  47.                }
  48.  
  49.                return true;
  50.             }
  51.          }
  52.  
  53.          return true;
  54.       }
  55.    }
  56.  
  57.    public boolean atEnd() {
  58.       return this.myNode == null;
  59.    }
  60.  
  61.    public boolean hasMoreElements() {
  62.       return this.myNode != null;
  63.    }
  64.  
  65.    public void advance() {
  66.       this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode);
  67.    }
  68.  
  69.    public void advance(int var1) {
  70.       if (var1 < 0) {
  71.          throw new InvalidOperationException("Attempt to advance a ForwardIterator in the wrong direction.");
  72.       } else {
  73.          while(var1-- > 0) {
  74.             this.advance();
  75.          }
  76.  
  77.       }
  78.    }
  79.  
  80.    public Object nextElement() {
  81.       Object var1 = this.myNode.object;
  82.       this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode);
  83.       return var1;
  84.    }
  85.  
  86.    public Object get() {
  87.       return this.myNode.object;
  88.    }
  89.  
  90.    public void put(Object var1) {
  91.       this.myNode.object = var1;
  92.    }
  93.  
  94.    public int distance(ForwardIterator var1) {
  95.       HashSet.HashSetNode var2 = this.myNode;
  96.       HashSet.HashSetNode var3 = ((HashSetIterator)var1).myNode;
  97.  
  98.       int var4;
  99.       for(var4 = 0; this.myNode != var3; this.myNode = this.myNode.next != null ? this.myNode.next : this.next(this.myNode)) {
  100.          ++var4;
  101.       }
  102.  
  103.       this.myNode = var2;
  104.       return var4;
  105.    }
  106.  
  107.    public Container getContainer() {
  108.       return this.myHashSet;
  109.    }
  110.  
  111.    private HashSet.HashSetNode next(HashSet.HashSetNode var1) {
  112.       for(int var2 = var1.hash % this.myHashSet.length + 1; var2 < this.myHashSet.length; ++var2) {
  113.          if (this.myHashSet.buckets[var2] != null) {
  114.             return this.myHashSet.buckets[var2];
  115.          }
  116.       }
  117.  
  118.       return null;
  119.    }
  120. }
  121.