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

  1. package java.text;
  2.  
  3. final class SimpleTextBoundary extends BreakIterator {
  4.    private int pos;
  5.    private CharacterIterator text;
  6.    private TextBoundaryData data;
  7.    private static final char END_OF_STRING = '\uffff';
  8.  
  9.    protected SimpleTextBoundary(TextBoundaryData var1) {
  10.       this.data = var1;
  11.       this.text = new StringCharacterIterator("");
  12.       this.pos = this.text.getBeginIndex();
  13.    }
  14.  
  15.    public boolean equals(Object var1) {
  16.       if (this == var1) {
  17.          return true;
  18.       } else if (!(var1 instanceof SimpleTextBoundary)) {
  19.          return false;
  20.       } else {
  21.          SimpleTextBoundary var2 = (SimpleTextBoundary)var1;
  22.          if (this.data.getClass() != var2.data.getClass()) {
  23.             return false;
  24.          } else if (this.hashCode() != var2.hashCode()) {
  25.             return false;
  26.          } else if (this.pos != var2.pos) {
  27.             return false;
  28.          } else {
  29.             return this.text.equals(var2.text);
  30.          }
  31.       }
  32.    }
  33.  
  34.    public int hashCode() {
  35.       return this.getClass().hashCode() ^ this.text.hashCode();
  36.    }
  37.  
  38.    public Object clone() {
  39.       try {
  40.          SimpleTextBoundary var1 = (SimpleTextBoundary)super.clone();
  41.          var1.text = (CharacterIterator)this.text.clone();
  42.          return var1;
  43.       } catch (InternalError var2) {
  44.          throw new InternalError();
  45.       }
  46.    }
  47.  
  48.    public CharacterIterator getText() {
  49.       return this.text;
  50.    }
  51.  
  52.    public void setText(String var1) {
  53.       this.text = new StringCharacterIterator(var1);
  54.       this.pos = this.text.getBeginIndex();
  55.    }
  56.  
  57.    public void setText(CharacterIterator var1) {
  58.       this.text = var1;
  59.       this.pos = this.text.getBeginIndex();
  60.    }
  61.  
  62.    public int first() {
  63.       this.pos = this.text.getBeginIndex();
  64.       return this.pos;
  65.    }
  66.  
  67.    public int last() {
  68.       this.pos = this.text.getEndIndex();
  69.       return this.pos;
  70.    }
  71.  
  72.    public int next(int var1) {
  73.       int var2 = this.current();
  74.       if (var1 < 0) {
  75.          for(int var3 = var1; var3 < 0 && var2 != -1; ++var3) {
  76.             var2 = this.previous();
  77.          }
  78.       } else {
  79.          for(int var4 = var1; var4 > 0 && var2 != -1; --var4) {
  80.             var2 = this.next();
  81.          }
  82.       }
  83.  
  84.       return var2;
  85.    }
  86.  
  87.    public int previous() {
  88.       if (this.pos <= this.text.getBeginIndex()) {
  89.          return -1;
  90.       } else {
  91.          int var1 = this.pos;
  92.          this.pos = this.previousSafePosition(this.pos - 1);
  93.          int var2 = this.pos;
  94.  
  95.          for(int var3 = this.next(); var3 < var1 && var3 != -1; var3 = this.next()) {
  96.             var2 = var3;
  97.          }
  98.  
  99.          this.pos = var2;
  100.          return this.pos;
  101.       }
  102.    }
  103.  
  104.    public int next() {
  105.       int var1 = this.pos;
  106.       if (this.pos < this.text.getEndIndex()) {
  107.          this.pos = this.nextPosition(this.pos);
  108.          var1 = this.pos;
  109.       } else {
  110.          var1 = -1;
  111.       }
  112.  
  113.       return var1;
  114.    }
  115.  
  116.    public int following(int var1) {
  117.       if (var1 >= this.text.getBeginIndex() && var1 < this.text.getEndIndex()) {
  118.          this.pos = this.previousSafePosition(var1);
  119.  
  120.          int var2;
  121.          do {
  122.             var2 = this.next();
  123.          } while(var2 <= var1 && var2 != -1);
  124.  
  125.          return var2;
  126.       } else {
  127.          throw new IllegalArgumentException("nextBoundaryAt offset out of bounds");
  128.       }
  129.    }
  130.  
  131.    public int current() {
  132.       return this.pos;
  133.    }
  134.  
  135.    private int previousSafePosition(int var1) {
  136.       int var2 = this.text.getBeginIndex();
  137.       int var3 = this.data.backward().initialState();
  138.  
  139.       for(char var4 = this.text.setIndex(var1); var4 != '\uffff' && !this.data.backward().isEndState(var3); var4 = this.text.previous()) {
  140.          var3 = this.data.backward().get(var3, this.mappedChar(var4));
  141.          if (this.data.backward().isMarkState(var3)) {
  142.             var2 = this.text.getIndex();
  143.          }
  144.       }
  145.  
  146.       return var2;
  147.    }
  148.  
  149.    private int nextPosition(int var1) {
  150.       int var2 = this.text.getEndIndex();
  151.       int var3 = this.data.forward().initialState();
  152.  
  153.       for(char var4 = this.text.setIndex(var1); var4 != '\uffff' && !this.data.forward().isEndState(var3); var4 = this.text.next()) {
  154.          var3 = this.data.forward().get(var3, this.mappedChar(var4));
  155.          if (this.data.forward().isMarkState(var3)) {
  156.             var2 = this.text.getIndex();
  157.          }
  158.       }
  159.  
  160.       if (this.data.forward().isEndState(var3)) {
  161.          return var2;
  162.       } else {
  163.          var3 = this.data.forward().get(var3, this.mappedChar('\uffff'));
  164.          return this.data.forward().isMarkState(var3) ? this.text.getEndIndex() : var2;
  165.       }
  166.    }
  167.  
  168.    protected int mappedChar(char var1) {
  169.       return this.data.map().mappedChar(var1);
  170.    }
  171. }
  172.