Index: java/text/CollationElementIterator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/CollationElementIterator.java,v retrieving revision 1.12 diff -u -b -B -r1.12 CollationElementIterator.java --- java/text/CollationElementIterator.java 6 Jan 2004 20:35:29 -0000 1.12 +++ java/text/CollationElementIterator.java 7 Jan 2004 09:25:25 -0000 @@ -71,22 +71,22 @@ /** * This is the RuleBasedCollator this object was created from. */ - private RuleBasedCollator collator; + RuleBasedCollator collator; /** * This is the String that is being iterated over. */ - private String text; + String text; /** * This is the index into the collation decomposition where we are currently scanning. */ - private int index; + int index; /** * This is the index into the String where we are currently scanning. */ - private int textIndex; + int textIndex; /** * Array containing the collation decomposition of the @@ -227,14 +227,16 @@ * This method sets the String that it is iterating over * to the specified String. * - * @param The new String to iterate over. + * @param text The new String to iterate over. + * + * @since 1.2 */ public void setText(String text) { int idx = 0; this.text = text; - index = 0; + this.index = 0; String work_text = text.intern(); @@ -300,19 +302,17 @@ * * @param ci The CharacterIterator containing the new String to iterate over. */ - public void setText(CharacterIterator ci) + public void setText(CharacterIterator source) { - StringBuffer sb = new StringBuffer(""); + StringBuffer expand = new StringBuffer(); // For now assume we read from the beginning of the string. - char c = ci.first(); - while (c != CharacterIterator.DONE) - { - sb.append(c); - c = ci.next(); - } + for (char c = source.first(); + c != CharacterIterator.DONE; + c = source.next()) + expand.append(c); - setText(sb.toString()); + setText(expand.toString()); } /** @@ -320,6 +320,8 @@ * that is being iterated over. * * @return The iteration index position. + * + * @since 1.2 */ public int getOffset() { Index: java/text/CollationKey.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/CollationKey.java,v retrieving revision 1.9 diff -u -b -B -r1.9 CollationKey.java --- java/text/CollationKey.java 21 Oct 2003 14:56:12 -0000 1.9 +++ java/text/CollationKey.java 7 Jan 2004 09:25:26 -0000 @@ -180,7 +180,11 @@ */ public int hashCode() { - return key.hashCode(); + // We just follow BitSet instead of thinking up something new. + long h = originalText.hashCode(); + for (int i = key.length - 1; i >= 0; --i) + h ^= key[i] * (i + 1); + return (int) ((h >> 32) ^ h); } /** Index: java/text/RuleBasedCollator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/RuleBasedCollator.java,v retrieving revision 1.19 diff -u -b -B -r1.19 RuleBasedCollator.java --- java/text/RuleBasedCollator.java 6 Jan 2004 20:35:29 -0000 1.19 +++ java/text/RuleBasedCollator.java 7 Jan 2004 09:25:26 -0000 @@ -180,8 +180,7 @@ { return (primary << 16) + (secondary << 8) + tertiary; } - - } // inner class CollationElement + } /** * Basic collation instruction (internal format) to build the series of @@ -210,6 +209,56 @@ } /** + * This the the original rule string. + */ + private String rules; + + /** + * This is the table of collation element values + */ + private Object[] ce_table; + + /** + * Quick-prefix finder. + */ + HashMap prefix_tree; + + /** + * This is the value of the last sequence entered into + * ce_table. It is used to compute the + * ordering value of unspecified character. + */ + private int last_primary_value; + + /** + * This variable is true if accents need to be sorted + * in the other direction. + */ + private boolean inverseAccentComparison; + + /** + * This method initializes a new instance of RuleBasedCollator + * with the specified collation rules. Note that an application normally + * obtains an instance of RuleBasedCollator by calling the + * getInstance method of Collator. That method + * automatically loads the proper set of rules for the desired locale. + * + * @param rules The collation rule string. + * + * @exception ParseException If the rule string contains syntax errors. + */ + public RuleBasedCollator(String rules) throws ParseException + { + if (rules.equals("")) + throw new ParseException("empty rule set", 0); + + this.rules = rules; + + buildCollationVector(parseString(rules)); + buildPrefixAccess(); + } + + /** * This method returns the number of common characters at the beginning * of the string of the two parameters. * @@ -220,14 +269,17 @@ */ static int findPrefixLength(String prefix, String s) { - int i; + int index; + int len = prefix.length(); - for (i = 0; i < prefix.length() && i < s.length(); i++) + for (index = 0; index < len && index < s.length(); ++index) { - if (prefix.charAt(i) != s.charAt(i)) - return i; + if (prefix.charAt(index) != s.charAt(index)) + return index; } - return i; + + + return index; } /** @@ -514,6 +566,16 @@ } /** + * This method creates a copy of this object. + * + * @return A copy of this object. + */ + public Object clone() + { + return super.clone(); + } + + /** * This method completely parses a string 'rules' containing sorting rules. * * @param rules String containing the rules to be parsed. @@ -534,66 +596,6 @@ } /** - * This the the original rule string. - */ - private String rules; - - /** - * This is the table of collation element values - */ - private Object[] ce_table; - - /** - * Quick-prefix finder. - */ - HashMap prefix_tree; - - /** - * This is the value of the last sequence entered into - * ce_table. It is used to compute the - * ordering value of unspecified character. - */ - private int last_primary_value; - - /** - * This variable is true if accents need to be sorted - * in the other direction. - */ - private boolean inverseAccentComparison; - - /** - * This method initializes a new instance of RuleBasedCollator - * with the specified collation rules. Note that an application normally - * obtains an instance of RuleBasedCollator by calling the - * getInstance method of Collator. That method - * automatically loads the proper set of rules for the desired locale. - * - * @param rules The collation rule string. - * - * @exception ParseException If the rule string contains syntax errors. - */ - public RuleBasedCollator(String rules) throws ParseException - { - this.rules = rules; - - if (rules.equals("")) - throw new ParseException("Empty rule set", 0); - - buildCollationVector(parseString(rules)); - buildPrefixAccess(); - } - - /** - * This method creates a copy of this object. - * - * @return A copy of this object. - */ - public Object clone() - { - return super.clone(); - } - - /** * This method uses the sorting instructions built by address@hidden #parseString} * to build collation elements which can be directly used to sort strings. * @@ -718,13 +720,15 @@ */ public int compare(String source, String target) { - CollationElementIterator cei1 = getCollationElementIterator(source); - CollationElementIterator cei2 = getCollationElementIterator(target); + CollationElementIterator cs, ct; + + cs = getCollationElementIterator(source); + ct = getCollationElementIterator(target); for(;;) { - CollationElement ord1block = cei1.nextBlock(); - CollationElement ord2block = cei2.nextBlock(); + CollationElement ord1block = cs.nextBlock(); + CollationElement ord2block = ct.nextBlock(); int ord1; int ord2; @@ -752,8 +756,8 @@ } // Check for primary strength differences - int prim1 = cei1.primaryOrder(ord1); - int prim2 = cei2.primaryOrder(ord2); + int prim1 = cs.primaryOrder(ord1); + int prim2 = ct.primaryOrder(ord2); if (prim1 < prim2) return -1; @@ -763,8 +767,8 @@ continue; // Check for secondary strength differences - int sec1 = cei1.secondaryOrder(ord1); - int sec2 = cei2.secondaryOrder(ord2); + int sec1 = cs.secondaryOrder(ord1); + int sec2 = ct.secondaryOrder(ord2); if (sec1 < sec2) return -1; @@ -774,8 +778,8 @@ continue; // Check for tertiary differences - int tert1 = cei1.tertiaryOrder(ord1); - int tert2 = cei2.tertiaryOrder(ord2); + int tert1 = cs.tertiaryOrder(ord1); + int tert2 = ct.tertiaryOrder(ord2); if (tert1 < tert2) return -1; @@ -856,17 +860,15 @@ */ public CollationElementIterator getCollationElementIterator(CharacterIterator source) { - StringBuffer sb = new StringBuffer(""); + StringBuffer expand = new StringBuffer(""); // Right now we assume that we will read from the beginning of the string. - char c = source.first(); - while (c != CharacterIterator.DONE) - { - sb.append(c); - c = source.next(); - } + for (char c = source.first(); + c != CharacterIterator.DONE; + c = source.next()) + decomposeCharacter(c, expand); - return getCollationElementIterator(sb.toString()); + return getCollationElementIterator(expand.toString()); } /**