- Timestamp:
- 2002-11-30T15:07:07+13:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/selfContained/IncrementRange.java
r3548 r3593 42 42 implements Cloneable, Serializable 43 43 { 44 /**44 /** 45 45 * Create an IncrementRange which counts between first and last inclusive 46 46 * … … 83 83 * Increment a stream of characters, reading from the reader and writing the incremented characters to the writer 84 84 * 85 * @exception java.io.E xceptionif any of the characters in the string are outside the range of first-last85 * @exception java.io.Error if any of the characters in the string are outside the range of first-last 86 86 * @param str the string to be incremented 87 87 * @return the incremented string 88 88 * @see Increment 89 89 */ 90 long incrementStream(Reader rdr, Writer wtr) 91 t hrows Exception{92 long count = 0; // the return value90 long incrementStream(Reader rdr, Writer wtr) { 91 try { 92 long count = 0; // the return value 93 93 94 int i = rdr.read();95 boolean carry = true;94 int i = rdr.read(); 95 boolean carry = true; 96 96 97 while (i != -1) {98 97 while (i != -1) { 98 char c = (char) i; 99 99 100 101 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"); 103 103 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 } 108 112 } 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 } 111 120 } 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 } 131 135 } 132 136 … … 134 138 * Increment a string of characters 135 139 * 136 * @exception java. io.Exceptionif any of the characters in the string are outside the range of first-last140 * @exception java.lang.Error if any of the characters in the string are outside the range of first-last 137 141 * @param str the string to be incremented 138 142 * @return the incremented string 139 143 * @see Increment 140 144 */ 141 public final String incrementString(String str) 142 throws Exception { 145 public final String incrementString(String str) { 143 146 StringBuffer buffer = new StringBuffer(); 144 147 if (str == "") { … … 150 153 char c = str.charAt(i); 151 154 if (c < first || c > last) 152 throw new E xception("Character '" + c + "' is ouside range");155 throw new Error("Character '" + c + "' is ouside range"); 153 156 154 157 if (c == last) {
Note:
See TracChangeset
for help on using the changeset viewer.