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

  1. package COM.objectspace.jgl;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public final class DequeIterator implements RandomAccessIterator, Serializable {
  6.    Deque myDeque;
  7.    int myBlockIndex;
  8.    int myMapIndex;
  9.  
  10.    public DequeIterator() {
  11.    }
  12.  
  13.    public DequeIterator(DequeIterator var1) {
  14.       this.myDeque = var1.myDeque;
  15.       this.myMapIndex = var1.myMapIndex;
  16.       this.myBlockIndex = var1.myBlockIndex;
  17.    }
  18.  
  19.    DequeIterator(Deque var1, int var2, int var3) {
  20.       this.myDeque = var1;
  21.       this.myBlockIndex = var2;
  22.       this.myMapIndex = var3;
  23.    }
  24.  
  25.    public Object clone() {
  26.       return new DequeIterator(this);
  27.    }
  28.  
  29.    public boolean atBegin() {
  30.       return this.equals(this.myDeque.myStart);
  31.    }
  32.  
  33.    public boolean atEnd() {
  34.       return this.equals(this.myDeque.myFinish);
  35.    }
  36.  
  37.    public boolean hasMoreElements() {
  38.       return !this.equals(this.myDeque.myFinish);
  39.    }
  40.  
  41.    public void advance() {
  42.       if (++this.myBlockIndex == Deque.BLOCK_SIZE) {
  43.          ++this.myMapIndex;
  44.          this.myBlockIndex = 0;
  45.       }
  46.  
  47.    }
  48.  
  49.    public void advance(int var1) {
  50.       this.myBlockIndex += var1;
  51.       if (this.myBlockIndex >= Deque.BLOCK_SIZE) {
  52.          int var3 = this.myBlockIndex / Deque.BLOCK_SIZE;
  53.          this.myMapIndex += var3;
  54.          this.myBlockIndex %= Deque.BLOCK_SIZE;
  55.       } else {
  56.          if (this.myBlockIndex < 0) {
  57.             int var2 = (Deque.BLOCK_SIZE - 1 - this.myBlockIndex) / Deque.BLOCK_SIZE;
  58.             this.myMapIndex -= var2;
  59.             this.myBlockIndex += var2 * Deque.BLOCK_SIZE;
  60.          }
  61.  
  62.       }
  63.    }
  64.  
  65.    public void retreat() {
  66.       if (--this.myBlockIndex == -1) {
  67.          --this.myMapIndex;
  68.          this.myBlockIndex = Deque.BLOCK_SIZE - 1;
  69.       }
  70.  
  71.    }
  72.  
  73.    public void retreat(int var1) {
  74.       this.advance(-var1);
  75.    }
  76.  
  77.    public Object nextElement() {
  78.       Object var1 = this.myDeque.myMap[this.myMapIndex][this.myBlockIndex];
  79.       if (++this.myBlockIndex == Deque.BLOCK_SIZE) {
  80.          ++this.myMapIndex;
  81.          this.myBlockIndex = 0;
  82.       }
  83.  
  84.       return var1;
  85.    }
  86.  
  87.    DequeIterator copy(int var1) {
  88.       DequeIterator var2 = new DequeIterator(this);
  89.       var2.advance(var1);
  90.       return var2;
  91.    }
  92.  
  93.    public int distance(ForwardIterator var1) {
  94.       DequeIterator var2 = (DequeIterator)var1;
  95.       int var3 = var2.myBlockIndex - this.myBlockIndex;
  96.       return this.myMapIndex == var2.myMapIndex ? var3 : Deque.BLOCK_SIZE * (var2.myMapIndex - this.myMapIndex) + var3;
  97.    }
  98.  
  99.    public int index() {
  100.       return this.myDeque.myStart.distance(this);
  101.    }
  102.  
  103.    public Object get() {
  104.       return this.myDeque.myMap[this.myMapIndex][this.myBlockIndex];
  105.    }
  106.  
  107.    public void put(Object var1) {
  108.       this.myDeque.myMap[this.myMapIndex][this.myBlockIndex] = var1;
  109.    }
  110.  
  111.    public Object get(int var1) {
  112.       int var2 = this.myMapIndex;
  113.       int var3 = this.myBlockIndex;
  114.       this.advance(var1);
  115.       Object var4 = this.myDeque.myMap[this.myMapIndex][this.myBlockIndex];
  116.       this.myMapIndex = var2;
  117.       this.myBlockIndex = var3;
  118.       return var4;
  119.    }
  120.  
  121.    public void put(int var1, Object var2) {
  122.       int var3 = this.myMapIndex;
  123.       int var4 = this.myBlockIndex;
  124.       this.advance(var1);
  125.       this.myDeque.myMap[this.myMapIndex][this.myBlockIndex] = var2;
  126.       this.myMapIndex = var3;
  127.       this.myBlockIndex = var4;
  128.    }
  129.  
  130.    public boolean equals(Object var1) {
  131.       return var1 instanceof DequeIterator && this.equals((DequeIterator)var1);
  132.    }
  133.  
  134.    public boolean equals(DequeIterator var1) {
  135.       return this.myBlockIndex == var1.myBlockIndex && this.myMapIndex == var1.myMapIndex && this.myDeque == var1.myDeque;
  136.    }
  137.  
  138.    public boolean less(RandomAccessIterator var1) {
  139.       DequeIterator var2 = (DequeIterator)var1;
  140.       return this.myMapIndex < var2.myMapIndex || this.myMapIndex == var2.myMapIndex && this.myBlockIndex < var2.myBlockIndex;
  141.    }
  142.  
  143.    public Container getContainer() {
  144.       return this.myDeque;
  145.    }
  146. }
  147.