This fixed RuleBasedCollator.getCollationElementIterator(CharacterIterator) to simply return a CollationElementIterator for it. This means to tweak the latter class to work with CharacterIterator instead of String. This is the last missing jdk13 method according to JAPI.
2006-01-09 Roman Kennke <[EMAIL PROTECTED]> * java/text/CollationElementIterator.java (text): Changed type to CharacterIterator. (CollationElementIterator(RuleBasedCollator,CharacterIterator)): New constructor. (setOffset(int)): Use CharacterIterator.getEndIndex() instead of String.length(). (setText(String)): Wrap string into a StringCharacterIterator. * java/text/RuleBasedCollator.java (getCollationElementIterator(CharacterIterator)): Simply return CollationElementIterator for the character iterator, instead of expanding things. /Roman -- Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org aicas Allerton Interworks Computer Automated Systems GmbH Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany http://www.aicas.com * Tel: +49-721-663 968-0 USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe Geschäftsführer: Dr. James J. Hunt
Index: java/text/CollationElementIterator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/CollationElementIterator.java,v retrieving revision 1.24 diff -u -1 -0 -r1.24 CollationElementIterator.java --- java/text/CollationElementIterator.java 23 Jul 2005 20:25:15 -0000 1.24 +++ java/text/CollationElementIterator.java 9 Jan 2008 13:39:29 -0000 @@ -66,21 +66,21 @@ public static final int NULLORDER = -1; /** * This is the RuleBasedCollator this object was created from. */ RuleBasedCollator collator; /** * This is the String that is being iterated over. */ - String text; + CharacterIterator text; /** * This is the index into the collation decomposition where we are currently scanning. */ int index; /** * This is the index into the String where we are currently scanning. */ int textIndex; @@ -104,20 +104,35 @@ * @param collator The <code>RuleBasedCollation</code> used for calculating collation values * @param text The <code>String</code> to iterate over. */ CollationElementIterator(RuleBasedCollator collator, String text) { this.collator = collator; setText (text); } + /** + * This method initializes a new instance of <code>CollationElementIterator</code> + * to iterate over the specified <code>String</code> using the rules in the + * specified <code>RuleBasedCollator</code>. + * + * @param collator The <code>RuleBasedCollation</code> used for calculating collation values + * @param text The character iterator to iterate over. + */ + CollationElementIterator(RuleBasedCollator collator, CharacterIterator text) + { + this.collator = collator; + + setText (text); + } + RuleBasedCollator.CollationElement nextBlock() { if (index >= text_decomposition.length) return null; RuleBasedCollator.CollationElement e = text_decomposition[index]; textIndex = text_indexes[index+1]; index++; @@ -239,21 +254,21 @@ * * @since 1.2 */ public void setText(String text) { int idx = 0; int idx_idx = 0; int alreadyExpanded = 0; int idxToMove = 0; - this.text = text; + this.text = new StringCharacterIterator(text); this.index = 0; String work_text = text.intern(); ArrayList a_element = new ArrayList(); ArrayList a_idx = new ArrayList(); // Build element collection ordered as they come in "text". while (idx < work_text.length()) { @@ -433,21 +448,21 @@ * * @param offset The new iteration index position. * * @exception IllegalArgumentException If the new offset is not valid. */ public void setOffset(int offset) { if (offset < 0) throw new IllegalArgumentException("Negative offset: " + offset); - if (offset > (text.length() - 1)) + if (offset > (text.getEndIndex() - 1)) throw new IllegalArgumentException("Offset too large: " + offset); for (index = 0; index < text_decomposition.length; index++) { if (offset <= text_indexes[index]) break; } /* * As text_indexes[0] == 0, we should not have to take care whether index is * greater than 0. It is always. Index: java/text/RuleBasedCollator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/RuleBasedCollator.java,v retrieving revision 1.32 diff -u -1 -0 -r1.32 RuleBasedCollator.java --- java/text/RuleBasedCollator.java 22 Mar 2006 19:15:25 -0000 1.32 +++ java/text/RuleBasedCollator.java 9 Jan 2008 13:39:29 -0000 @@ -916,31 +916,22 @@ /** * This method returns an instance of <code>CollationElementIterator</code> * for the <code>String</code> represented by the specified * <code>CharacterIterator</code>. * * @param source The <code>CharacterIterator</code> with the desired <code>String</code>. * * @return A <code>CollationElementIterator</code> for the specified <code>String</code>. */ public CollationElementIterator getCollationElementIterator(CharacterIterator source) - throws NotImplementedException // Because decomposeCharacter does not work { - StringBuffer expand = new StringBuffer(""); - - // Right now we assume that we will read from the beginning of the string. - for (char c = source.first(); - c != CharacterIterator.DONE; - c = source.next()) - decomposeCharacter(c, expand); - - return getCollationElementIterator(expand.toString()); + return new CollationElementIterator(this, source); } /** * This method returns an instance of <code>CollationKey</code> for the * specified <code>String</code>. The object returned will have a * more efficient mechanism for its comparison function that could * provide speed benefits if multiple comparisons are performed, such * as during a sort. * * @param source The <code>String</code> to create a <code>CollationKey</code> for.