Ignore:
Timestamp:
2002-11-30T15:07:07+13:00 (22 years ago)
Author:
say1
Message:

more comments and error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/IncrementRange.java

    r3548 r3593  
    4242  implements Cloneable, Serializable
    4343{
    44  /**
     44  /**
    4545   * Create an IncrementRange which counts between first and last inclusive
    4646   *
     
    8383   * Increment a stream of characters, reading from the reader and writing the incremented characters to the writer
    8484   *
    85    * @exception java.io.Exception if any of the characters in the string are outside the range of first-last
     85   * @exception java.io.Error if any of the characters in the string are outside the range of first-last
    8686   * @param str the string to be incremented
    8787   * @return the incremented string
    8888   * @see Increment
    8989   */
    90   long incrementStream(Reader rdr, Writer wtr)
    91     throws Exception {
    92     long count = 0; // the return value
     90  long incrementStream(Reader rdr, Writer wtr) {
     91    try {
     92      long count = 0; // the return value
    9393   
    94     int i = rdr.read();
    95     boolean carry = true;
     94      int i = rdr.read();
     95      boolean carry = true;
    9696   
    97     while (i != -1) {
    98       char c = (char) i;
     97      while (i != -1) {
     98    char c = (char) i;
    9999     
    100       // check the validity of the character we're about to increment
    101       if (c < first || c > last)
    102     throw new Exception("Character '" + c + "' is ouside range");
     100    // check the validity of the character we're about to increment
     101    if (c < first || c > last)
     102      throw new Error("Character '" + c + "' is ouside range");
    103103     
    104       if (c == last) {
    105     if (carry == true) {
    106       wtr.write(first);
    107       carry = true;
     104    if (c == last) {
     105      if (carry == true) {
     106        wtr.write(first);
     107        carry = true;
     108      } else {
     109        wtr.write(c);
     110        carry = false;
     111      }
    108112    } else {
    109       wtr.write(c);
    110       carry = false;
     113      if (carry == true) {
     114        wtr.write(++c);
     115        carry = false;
     116      } else {
     117        wtr.write(c);
     118        carry = false;
     119      }
    111120    }
    112       } else {
    113     if (carry == true) {
    114       wtr.write(++c);
    115       carry = false;
    116     } else {
    117       wtr.write(c);
    118       carry = false;
    119     }
    120       }
    121       count++;
    122 
    123       // read the next character
    124       i = rdr.read();
    125     }
    126     if (carry == true) {
    127       wtr.write(first);
    128       count++;
    129     }
    130     return count;
     121    count++;
     122
     123    // read the next character
     124    i = rdr.read();
     125      }
     126      if (carry == true) {
     127    wtr.write(first);
     128    count++;
     129      }
     130      return count;
     131    } catch (IOException e) {
     132      System.err.println("IOException in incrementStream()");
     133      throw new Error(e.toString());
     134    }
    131135  }
    132136
     
    134138   * Increment a string of characters
    135139   *
    136    * @exception java.io.Exception if any of the characters in the string are outside the range of first-last
     140   * @exception java.lang.Error if any of the characters in the string are outside the range of first-last
    137141   * @param str the string to be incremented
    138142   * @return the incremented string
    139143   * @see Increment
    140144   */
    141   public final String incrementString(String str)
    142     throws Exception {
     145  public final String incrementString(String str)  {
    143146    StringBuffer buffer = new StringBuffer();
    144147    if (str == "") {
     
    150153    char c = str.charAt(i);
    151154    if (c < first || c > last)
    152       throw new Exception("Character '" + c + "' is ouside range");
     155      throw new Error("Character '" + c + "' is ouside range");
    153156
    154157    if (c == last) {
Note: See TracChangeset for help on using the changeset viewer.