85 |
* @param collator The <code>RuleBasedCollation</code> used for calculating collation values |
* @param collator The <code>RuleBasedCollation</code> used for calculating collation values |
86 |
* @param text The <code>String</code> to iterate over. |
* @param text The <code>String</code> to iterate over. |
87 |
*/ |
*/ |
88 |
CollationElementIterator (RuleBasedCollator collator, String text) |
CollationElementIterator (String text, RuleBasedCollator collator) |
89 |
{ |
{ |
90 |
|
setText (text); |
91 |
this.collator = collator; |
this.collator = collator; |
|
this.text = text; |
|
92 |
} |
} |
93 |
|
|
94 |
/** |
/** |
98 |
* |
* |
99 |
* @return The collation ordering value. |
* @return The collation ordering value. |
100 |
*/ |
*/ |
101 |
public int next () |
public int next() |
102 |
{ |
{ |
103 |
if (index >= text.length ()) |
if (index == text.length()) |
104 |
return NULLORDER; |
return NULLORDER; |
105 |
|
|
106 |
String s = text.charAt (index) + ""; |
String s = text.charAt (index) + ""; |
126 |
* This method resets the internal position pointer to read from the |
* This method resets the internal position pointer to read from the |
127 |
* beginning of the <code>String again. |
* beginning of the <code>String again. |
128 |
*/ |
*/ |
129 |
public void reset () |
public void reset() |
130 |
{ |
{ |
131 |
index = 0; |
index = 0; |
132 |
} |
} |
163 |
* This method sets the <code>String</code> that it is iterating over |
* This method sets the <code>String</code> that it is iterating over |
164 |
* to the specified <code>String</code>. |
* to the specified <code>String</code>. |
165 |
* |
* |
166 |
* @param The new <code>String</code> to iterate over. |
* @param text The new <code>String</code> to iterate over. |
167 |
|
* |
168 |
|
* @since 1.2 |
169 |
*/ |
*/ |
170 |
public void setText (String text) |
public void setText (String text) |
171 |
{ |
{ |
182 |
*/ |
*/ |
183 |
public void setText (CharacterIterator ci) |
public void setText (CharacterIterator ci) |
184 |
{ |
{ |
185 |
|
// For now assume we read from the beginning of the string. |
186 |
|
char c = ci.first(); |
187 |
StringBuffer sb = new StringBuffer (""); |
StringBuffer sb = new StringBuffer (""); |
188 |
|
|
|
// For now assume we read from the beginning of the string. |
|
|
char c = ci.first (); |
|
189 |
while (c != CharacterIterator.DONE) |
while (c != CharacterIterator.DONE) |
190 |
{ |
{ |
191 |
sb.append (c); |
sb.append (c); |
192 |
c = ci.next (); |
c = ci.next(); |
193 |
} |
} |
194 |
|
|
195 |
setText (sb.toString ()); |
setText (sb.toString()); |
196 |
} |
} |
197 |
|
|
198 |
/** |
/** |
200 |
* that is being iterated over. |
* that is being iterated over. |
201 |
* |
* |
202 |
* @return The iteration index position. |
* @return The iteration index position. |
203 |
|
* |
204 |
|
* @since 1.2 |
205 |
*/ |
*/ |
206 |
public int getOffset () |
public int getOffset() |
207 |
{ |
{ |
208 |
return index; |
return index; |
209 |
} |
} |
252 |
* |
* |
253 |
* @return The collation ordering value. |
* @return The collation ordering value. |
254 |
*/ |
*/ |
255 |
public int previous () |
public int previous() |
256 |
{ |
{ |
257 |
--index; |
--index; |
258 |
if (index < 0) |
if (index < 0) |
261 |
String s = text.charAt (index) + ""; |
String s = text.charAt (index) + ""; |
262 |
return collator.getCollationElementValue (s); |
return collator.getCollationElementValue (s); |
263 |
} |
} |
264 |
} |
|
265 |
|
} // class CollationElementIterator |
266 |
|
|