home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / text / AttributedString$AttributedStringIterator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.5 KB  |  268 lines

  1. package java.text;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Hashtable;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import java.util.Vector;
  8.  
  9. final class AttributedString$AttributedStringIterator implements AttributedCharacterIterator {
  10.    private int beginIndex;
  11.    private int endIndex;
  12.    private AttributedCharacterIterator.Attribute[] relevantAttributes;
  13.    private int currentIndex;
  14.    private int currentRunIndex;
  15.    private int currentRunStart;
  16.    private int currentRunLimit;
  17.    // $FF: synthetic field
  18.    private final AttributedString this$0;
  19.  
  20.    AttributedString$AttributedStringIterator(AttributedString var1, AttributedCharacterIterator.Attribute[] var2, int var3, int var4) {
  21.       this.this$0 = var1;
  22.       if (var3 >= 0 && var3 <= var4 && var4 <= AttributedString.access$000(var1)) {
  23.          this.beginIndex = var3;
  24.          this.endIndex = var4;
  25.          this.currentIndex = var3;
  26.          this.updateRunInfo();
  27.          if (var2 != null) {
  28.             this.relevantAttributes = (AttributedCharacterIterator.Attribute[])var2.clone();
  29.          }
  30.  
  31.       } else {
  32.          throw new IllegalArgumentException("Invalid substring range");
  33.       }
  34.    }
  35.  
  36.    public boolean equals(Object var1) {
  37.       if (this == var1) {
  38.          return true;
  39.       } else if (!(var1 instanceof AttributedString$AttributedStringIterator)) {
  40.          return false;
  41.       } else {
  42.          AttributedString$AttributedStringIterator var2 = (AttributedString$AttributedStringIterator)var1;
  43.          if (this.this$0 != var2.getString()) {
  44.             return false;
  45.          } else {
  46.             return this.currentIndex == var2.currentIndex && this.beginIndex == var2.beginIndex && this.endIndex == var2.endIndex;
  47.          }
  48.       }
  49.    }
  50.  
  51.    public int hashCode() {
  52.       return this.this$0.text.hashCode() ^ this.currentIndex ^ this.beginIndex ^ this.endIndex;
  53.    }
  54.  
  55.    public Object clone() {
  56.       try {
  57.          AttributedString$AttributedStringIterator var1 = (AttributedString$AttributedStringIterator)super.clone();
  58.          return var1;
  59.       } catch (CloneNotSupportedException var2) {
  60.          throw new InternalError();
  61.       }
  62.    }
  63.  
  64.    public char first() {
  65.       return this.internalSetIndex(this.beginIndex);
  66.    }
  67.  
  68.    public char last() {
  69.       return this.endIndex == this.beginIndex ? this.internalSetIndex(this.endIndex) : this.internalSetIndex(this.endIndex - 1);
  70.    }
  71.  
  72.    public char current() {
  73.       return this.currentIndex == this.endIndex ? '\uffff' : AttributedString.access$100(this.this$0, this.currentIndex);
  74.    }
  75.  
  76.    public char next() {
  77.       return this.currentIndex < this.endIndex ? this.internalSetIndex(this.currentIndex + 1) : '\uffff';
  78.    }
  79.  
  80.    public char previous() {
  81.       return this.currentIndex > this.beginIndex ? this.internalSetIndex(this.currentIndex - 1) : '\uffff';
  82.    }
  83.  
  84.    public char setIndex(int var1) {
  85.       if (var1 >= this.beginIndex && var1 <= this.endIndex) {
  86.          return this.internalSetIndex(var1);
  87.       } else {
  88.          throw new IllegalArgumentException("Invalid index");
  89.       }
  90.    }
  91.  
  92.    public int getBeginIndex() {
  93.       return this.beginIndex;
  94.    }
  95.  
  96.    public int getEndIndex() {
  97.       return this.endIndex;
  98.    }
  99.  
  100.    public int getIndex() {
  101.       return this.currentIndex;
  102.    }
  103.  
  104.    public int getRunStart() {
  105.       return this.currentRunStart;
  106.    }
  107.  
  108.    public int getRunStart(AttributedCharacterIterator.Attribute var1) {
  109.       if (this.currentRunStart != this.beginIndex && this.currentRunIndex != -1) {
  110.          Object var2 = this.getAttribute(var1);
  111.          int var3 = this.currentRunStart;
  112.  
  113.          for(int var4 = this.currentRunIndex; var3 > this.beginIndex && AttributedString.access$300(var2, AttributedString.access$200(this.this$0, var1, var4 - 1)); var3 = this.this$0.runStarts[var4]) {
  114.             --var4;
  115.          }
  116.  
  117.          if (var3 < this.beginIndex) {
  118.             var3 = this.beginIndex;
  119.          }
  120.  
  121.          return var3;
  122.       } else {
  123.          return this.currentRunStart;
  124.       }
  125.    }
  126.  
  127.    public int getRunStart(Set var1) {
  128.       if (this.currentRunStart != this.beginIndex && this.currentRunIndex != -1) {
  129.          int var2 = this.currentRunStart;
  130.  
  131.          for(int var3 = this.currentRunIndex; var2 > this.beginIndex && AttributedString.access$400(this.this$0, var1, this.currentRunIndex, var3 - 1); var2 = this.this$0.runStarts[var3]) {
  132.             --var3;
  133.          }
  134.  
  135.          if (var2 < this.beginIndex) {
  136.             var2 = this.beginIndex;
  137.          }
  138.  
  139.          return var2;
  140.       } else {
  141.          return this.currentRunStart;
  142.       }
  143.    }
  144.  
  145.    public int getRunLimit() {
  146.       return this.currentRunLimit;
  147.    }
  148.  
  149.    public int getRunLimit(AttributedCharacterIterator.Attribute var1) {
  150.       if (this.currentRunLimit != this.endIndex && this.currentRunIndex != -1) {
  151.          Object var2 = this.getAttribute(var1);
  152.          int var3 = this.currentRunLimit;
  153.  
  154.          for(int var4 = this.currentRunIndex; var3 < this.endIndex && AttributedString.access$300(var2, AttributedString.access$200(this.this$0, var1, var4 + 1)); var3 = var4 < this.this$0.runCount - 1 ? this.this$0.runStarts[var4 + 1] : this.endIndex) {
  155.             ++var4;
  156.          }
  157.  
  158.          if (var3 > this.endIndex) {
  159.             var3 = this.endIndex;
  160.          }
  161.  
  162.          return var3;
  163.       } else {
  164.          return this.currentRunLimit;
  165.       }
  166.    }
  167.  
  168.    public int getRunLimit(Set var1) {
  169.       if (this.currentRunLimit != this.endIndex && this.currentRunIndex != -1) {
  170.          int var2 = this.currentRunLimit;
  171.  
  172.          for(int var3 = this.currentRunIndex; var2 < this.endIndex && AttributedString.access$400(this.this$0, var1, this.currentRunIndex, var3 + 1); var2 = var3 < this.this$0.runCount - 1 ? this.this$0.runStarts[var3 + 1] : this.endIndex) {
  173.             ++var3;
  174.          }
  175.  
  176.          if (var2 > this.endIndex) {
  177.             var2 = this.endIndex;
  178.          }
  179.  
  180.          return var2;
  181.       } else {
  182.          return this.currentRunLimit;
  183.       }
  184.    }
  185.  
  186.    public Map getAttributes() {
  187.       return (Map)(this.this$0.runAttributes != null && this.currentRunIndex != -1 && this.this$0.runAttributes[this.currentRunIndex] != null ? new AttributedString.AttributeMap(this.this$0, this.currentRunIndex, this.beginIndex, this.endIndex) : new Hashtable());
  188.    }
  189.  
  190.    public Set getAllAttributeKeys() {
  191.       if (this.this$0.runAttributes == null) {
  192.          return new HashSet();
  193.       } else {
  194.          AttributedString var1 = this.this$0;
  195.          synchronized(var1) {
  196.             HashSet var2 = new HashSet();
  197.  
  198.             for(int var3 = 0; var3 < this.this$0.runCount; ++var3) {
  199.                if (this.this$0.runStarts[var3] < this.endIndex && (var3 == this.this$0.runCount - 1 || this.this$0.runStarts[var3 + 1] > this.beginIndex)) {
  200.                   Vector var4 = this.this$0.runAttributes[var3];
  201.                   if (var4 != null) {
  202.                      int var5 = var4.size();
  203.  
  204.                      while(var5-- > 0) {
  205.                         var2.add(var4.get(var5));
  206.                      }
  207.                   }
  208.                }
  209.             }
  210.  
  211.             return var2;
  212.          }
  213.       }
  214.    }
  215.  
  216.    public Object getAttribute(AttributedCharacterIterator.Attribute var1) {
  217.       int var2 = this.currentRunIndex;
  218.       return var2 < 0 ? null : AttributedString.access$500(this.this$0, var1, var2, this.beginIndex, this.endIndex);
  219.    }
  220.  
  221.    private AttributedString getString() {
  222.       return this.this$0;
  223.    }
  224.  
  225.    private char internalSetIndex(int var1) {
  226.       this.currentIndex = var1;
  227.       if (var1 < this.currentRunStart || var1 >= this.currentRunLimit) {
  228.          this.updateRunInfo();
  229.       }
  230.  
  231.       return this.currentIndex == this.endIndex ? '\uffff' : AttributedString.access$100(this.this$0, var1);
  232.    }
  233.  
  234.    private void updateRunInfo() {
  235.       if (this.currentIndex == this.endIndex) {
  236.          this.currentRunStart = this.currentRunLimit = this.endIndex;
  237.          this.currentRunIndex = -1;
  238.       } else {
  239.          AttributedString var1 = this.this$0;
  240.          synchronized(var1) {
  241.             int var2;
  242.             for(var2 = -1; var2 < this.this$0.runCount - 1 && this.this$0.runStarts[var2 + 1] <= this.currentIndex; ++var2) {
  243.             }
  244.  
  245.             this.currentRunIndex = var2;
  246.             if (var2 >= 0) {
  247.                this.currentRunStart = this.this$0.runStarts[var2];
  248.                if (this.currentRunStart < this.beginIndex) {
  249.                   this.currentRunStart = this.beginIndex;
  250.                }
  251.             } else {
  252.                this.currentRunStart = this.beginIndex;
  253.             }
  254.  
  255.             if (var2 < this.this$0.runCount - 1) {
  256.                this.currentRunLimit = this.this$0.runStarts[var2 + 1];
  257.                if (this.currentRunLimit > this.endIndex) {
  258.                   this.currentRunLimit = this.endIndex;
  259.                }
  260.             } else {
  261.                this.currentRunLimit = this.endIndex;
  262.             }
  263.          }
  264.       }
  265.  
  266.    }
  267. }
  268.