home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / text / StringCharacterIterator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.2 KB  |  115 lines

  1. package java.text;
  2.  
  3. public final class StringCharacterIterator implements CharacterIterator {
  4.    private String text;
  5.    private int begin;
  6.    private int end;
  7.    private int pos;
  8.  
  9.    public StringCharacterIterator(String var1) {
  10.       this(var1, 0);
  11.    }
  12.  
  13.    public StringCharacterIterator(String var1, int var2) {
  14.       this(var1, 0, var1.length(), var2);
  15.    }
  16.  
  17.    public StringCharacterIterator(String var1, int var2, int var3, int var4) {
  18.       if (var1 == null) {
  19.          throw new NullPointerException();
  20.       } else {
  21.          this.text = var1;
  22.          if (var2 >= 0 && var2 <= var3 && var3 <= var1.length()) {
  23.             if (var4 >= var2 && var4 <= var3) {
  24.                this.begin = var2;
  25.                this.end = var3;
  26.                this.pos = var4;
  27.             } else {
  28.                throw new IllegalArgumentException("Invalid position");
  29.             }
  30.          } else {
  31.             throw new IllegalArgumentException("Invalid substring range");
  32.          }
  33.       }
  34.    }
  35.  
  36.    public char first() {
  37.       this.pos = this.begin;
  38.       return this.text.charAt(this.pos);
  39.    }
  40.  
  41.    public char last() {
  42.       this.pos = this.end - 1;
  43.       return this.text.charAt(this.pos);
  44.    }
  45.  
  46.    public char setIndex(int var1) {
  47.       if (var1 >= this.begin && var1 < this.end) {
  48.          this.pos = var1;
  49.          return this.text.charAt(var1);
  50.       } else {
  51.          throw new IllegalArgumentException("Invalid index");
  52.       }
  53.    }
  54.  
  55.    public char current() {
  56.       return this.pos >= this.begin && this.pos < this.end ? this.text.charAt(this.pos) : '\uffff';
  57.    }
  58.  
  59.    public char next() {
  60.       if (this.pos < this.end - 1) {
  61.          ++this.pos;
  62.          return this.text.charAt(this.pos);
  63.       } else {
  64.          this.pos = this.end;
  65.          return '\uffff';
  66.       }
  67.    }
  68.  
  69.    public char previous() {
  70.       return this.pos > this.begin ? this.text.charAt(--this.pos) : '\uffff';
  71.    }
  72.  
  73.    public int getBeginIndex() {
  74.       return this.begin;
  75.    }
  76.  
  77.    public int getEndIndex() {
  78.       return this.end;
  79.    }
  80.  
  81.    public int getIndex() {
  82.       return this.pos;
  83.    }
  84.  
  85.    public boolean equals(Object var1) {
  86.       if (this == var1) {
  87.          return true;
  88.       } else if (!(var1 instanceof StringCharacterIterator)) {
  89.          return false;
  90.       } else {
  91.          StringCharacterIterator var2 = (StringCharacterIterator)var1;
  92.          if (this.hashCode() != var2.hashCode()) {
  93.             return false;
  94.          } else if (!this.text.equals(var2.text)) {
  95.             return false;
  96.          } else {
  97.             return this.pos == var2.pos && this.begin == var2.begin && this.end == var2.end;
  98.          }
  99.       }
  100.    }
  101.  
  102.    public int hashCode() {
  103.       return this.text.hashCode() ^ this.pos ^ this.begin ^ this.end;
  104.    }
  105.  
  106.    public Object clone() {
  107.       try {
  108.          StringCharacterIterator var1 = (StringCharacterIterator)super.clone();
  109.          return var1;
  110.       } catch (CloneNotSupportedException var2) {
  111.          throw new InternalError();
  112.       }
  113.    }
  114. }
  115.