Index: java/text/CollationElementIterator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/CollationElementIterator.java,v retrieving revision 1.11 diff -u -b -B -r1.11 CollationElementIterator.java --- java/text/CollationElementIterator.java 29 Dec 2003 21:50:36 -0000 1.11 +++ java/text/CollationElementIterator.java 6 Jan 2004 20:35:03 -0000 @@ -117,7 +117,7 @@ RuleBasedCollator.CollationElement e = (RuleBasedCollator.CollationElement) text_decomposition[index++]; - textIndex += e.char_seq.length(); + textIndex += e.key.length(); return e; } @@ -131,7 +131,7 @@ RuleBasedCollator.CollationElement e = (RuleBasedCollator.CollationElement) text_decomposition[index]; - textIndex -= e.char_seq.length(); + textIndex -= e.key.length(); return e; } @@ -278,7 +278,7 @@ if (prefix.expansion != null) { work_text = prefix.expansion - + work_text.substring (idx+prefix.char_seq.length()); + + work_text.substring (idx+prefix.key.length()); idx = 0; v.add (prefix); } @@ -286,7 +286,7 @@ { if (!prefix.ignore) v.add (prefix); - idx += prefix.char_seq.length(); + idx += prefix.key.length(); } } @@ -351,7 +351,7 @@ { RuleBasedCollator.CollationElement e = (RuleBasedCollator.CollationElement) text_decomposition[i]; - int idx = textIndex + e.char_seq.length(); + int idx = textIndex + e.key.length(); if (idx > offset) break; Index: java/text/RuleBasedCollator.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/text/RuleBasedCollator.java,v retrieving revision 1.18 diff -u -b -B -r1.18 RuleBasedCollator.java --- java/text/RuleBasedCollator.java 29 Dec 2003 21:50:36 -0000 1.18 +++ java/text/RuleBasedCollator.java 6 Jan 2004 20:35:03 -0000 @@ -35,13 +35,12 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package java.text; -import java.util.Vector; +import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; -import java.util.Comparator; +import java.util.Vector; /* Written using "Java Class Libraries", 2nd edition, plus online * API docs for JDK 1.2 from http://www.javasoft.com. @@ -117,8 +116,8 @@ * anywhere in the previous rule string segment so the rule following the * reset rule cannot be inserted. *
- * "< a & A @ < e & E < f& F" - This sequence is equivalent to the following - * "< a & A < E & e < f & F". + * "< a & A @ < e & E < f& F" - This sequence is equivalent to the following + * "< a & A < E & e < f & F". *
* For a description of the various comparison strength types, see the
* documentation for the Collator
class.
@@ -151,7 +150,7 @@
*/
final class CollationElement
{
- String char_seq;
+ String key;
int primary;
short secondary;
short tertiary;
@@ -159,10 +158,10 @@
boolean ignore;
String expansion;
- CollationElement(String char_seq, int primary, short secondary, short tertiary,
+ CollationElement(String key, int primary, short secondary, short tertiary,
short equality, String expansion)
{
- this.char_seq = char_seq;
+ this.key = key;
this.primary = primary;
this.secondary = secondary;
this.tertiary = tertiary;
@@ -171,9 +170,9 @@
this.expansion = expansion;
}
- CollationElement(String char_seq)
+ CollationElement(String key)
{
- this.char_seq = char_seq;
+ this.key = key;
this.ignore = true;
}
@@ -563,6 +562,38 @@
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.
*
@@ -669,101 +700,8 @@
{
CollationElement e = (CollationElement) ce_table[i];
- prefix_tree.put(e.char_seq, e);
- }
- }
-
- /**
- * 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 returns a String
containing the collation rules
- * for this object.
- *
- * @return The collation rules for this object.
- */
- public String getRules()
- {
- return rules;
- }
-
- /**
- * This method builds a default collation element without invoking
- * the database created from the rules passed to the constructor.
- *
- * @param c Character which needs a collation element.
- * @return A valid brand new CollationElement instance.
- */
- CollationElement getDefaultElement(char c)
- {
- int v;
-
- // Preliminary support for generic accent sorting inversion (I don't know if all
- // characters in the range should be sorted backward). This is the place
- // to fix this if needed.
- if (inverseAccentComparison && (c >= 0x02B9 && c <= 0x0361))
- v = 0x0361 - ((int)c - 0x02B9);
- else
- v = (short)c;
- return new CollationElement(""+c, last_primary_value + v,
- (short)0, (short)0, (short) 0, null);
- }
-
- /**
- * This method returns an instance for CollationElementIterator
- * for the specified String
under the collation rules for this
- * object.
- *
- * @param str The String
to return the CollationElementIterator
instance for.
- *
- * @return A CollationElementIterator
for the specified String
.
- */
- public CollationElementIterator getCollationElementIterator(String str)
- {
- return new CollationElementIterator(this, str);
- }
-
- /**
- * This method returns an instance of CollationElementIterator
- * for the String
represented by the specified
- * CharacterIterator
.
- *
- * @param ci The CharacterIterator
with the desired String
.
- *
- * @return A CollationElementIterator
for the specified String
.
- */
- public CollationElementIterator getCollationElementIterator(CharacterIterator ci)
- {
- StringBuffer sb = new StringBuffer("");
-
- // Right now we assume that we will read from the beginning of the string.
- char c = ci.first();
- while (c != CharacterIterator.DONE)
- {
- sb.append(c);
- c = ci.next();
+ prefix_tree.put(e.key, e);
}
-
- return getCollationElementIterator(sb.toString());
}
/**
@@ -772,16 +710,16 @@
* the second. The value depends not only on the collation rules in
* effect, but also the strength and decomposition settings of this object.
*
- * @param s1 The first String
to compare.
- * @param s2 A second String
to compare to the first.
+ * @param source The first String
to compare.
+ * @param target A second String
to compare to the first.
*
- * @return A negative integer if s1 < s2, a positive integer
- * if s1 > s2, or 0 if s1 == s2.
+ * @return A negative integer if source < target, a positive integer
+ * if source > target, or 0 if source == target.
*/
- public int compare(String s1, String s2)
+ public int compare(String source, String target)
{
- CollationElementIterator cei1 = getCollationElementIterator(s1);
- CollationElementIterator cei2 = getCollationElementIterator(s2);
+ CollationElementIterator cei1 = getCollationElementIterator(source);
+ CollationElementIterator cei2 = getCollationElementIterator(target);
for(;;)
{
@@ -808,8 +746,8 @@
if (ord1 == ord2)
{
if (getStrength() == IDENTICAL)
- if (!ord1block.char_seq.equals(ord2block.char_seq))
- return ord1block.char_seq.compareTo(ord2block.char_seq);
+ if (!ord1block.key.equals(ord2block.key))
+ return ord1block.key.compareTo(ord2block.key);
continue;
}
@@ -847,8 +785,88 @@
continue;
// Apparently JDK does this (at least for my test case).
- return ord1block.char_seq.compareTo(ord2block.char_seq);
+ return ord1block.key.compareTo(ord2block.key);
+ }
+ }
+
+ /**
+ * This method tests this object for equality against the specified
+ * object. This will be true if and only if the specified object is
+ * another reference to this object.
+ *
+ * @param obj The Object
to compare against this object.
+ *
+ * @return true
if the specified object is equal to this object,
+ * false
otherwise.
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * This method builds a default collation element without invoking
+ * the database created from the rules passed to the constructor.
+ *
+ * @param c Character which needs a collation element.
+ * @return A valid brand new CollationElement instance.
+ */
+ CollationElement getDefaultElement(char c)
+ {
+ int v;
+
+ // Preliminary support for generic accent sorting inversion (I don't know if all
+ // characters in the range should be sorted backward). This is the place
+ // to fix this if needed.
+ if (inverseAccentComparison && (c >= 0x02B9 && c <= 0x0361))
+ v = 0x0361 - ((int) c - 0x02B9);
+ else
+ v = (short) c;
+ return new CollationElement("" + c, last_primary_value + v,
+ (short) 0, (short) 0, (short) 0, null);
+ }
+
+ /**
+ * This method returns an instance for CollationElementIterator
+ * for the specified String
under the collation rules for this
+ * object.
+ *
+ * @param source The String
to return the
+ * CollationElementIterator
instance for.
+ *
+ * @return A CollationElementIterator
for the specified
+ * String
.
+ */
+ public CollationElementIterator getCollationElementIterator(String source)
+ {
+ return new CollationElementIterator(this, source);
+ }
+
+ /**
+ * This method returns an instance of CollationElementIterator
+ * for the String
represented by the specified
+ * CharacterIterator
.
+ *
+ * @param source The CharacterIterator
with the desired String
.
+ *
+ * @return A CollationElementIterator
for the specified String
.
+ */
+ public CollationElementIterator getCollationElementIterator(CharacterIterator source)
+ {
+ StringBuffer sb = 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();
}
+
+ return getCollationElementIterator(sb.toString());
}
/**
@@ -858,13 +876,13 @@
* provide speed benefits if multiple comparisons are performed, such
* as during a sort.
*
- * @param str The String
to create a CollationKey
for.
+ * @param source The String
to create a CollationKey
for.
*
* @return A CollationKey
for the specified String
.
*/
- public CollationKey getCollationKey(String str)
+ public CollationKey getCollationKey(String source)
{
- CollationElementIterator cei = getCollationElementIterator(str);
+ CollationElementIterator cei = getCollationElementIterator(source);
Vector vect = new Vector(25);
int ord = cei.next();
@@ -894,31 +912,25 @@
for (int i = 0; i < objarr.length; i++)
{
- int j = ((Integer)objarr[i]).intValue();
- key [i * 4] = (byte)((j & 0xFF000000) >> 24);
- key [i * 4 + 1] = (byte)((j & 0x00FF0000) >> 16);
- key [i * 4 + 2] = (byte)((j & 0x0000FF00) >> 8);
- key [i * 4 + 3] = (byte)(j & 0x000000FF);
+ int j = ((Integer) objarr[i]).intValue();
+ key [i * 4] = (byte) ((j & 0xFF000000) >> 24);
+ key [i * 4 + 1] = (byte) ((j & 0x00FF0000) >> 16);
+ key [i * 4 + 2] = (byte) ((j & 0x0000FF00) >> 8);
+ key [i * 4 + 3] = (byte) (j & 0x000000FF);
}
- return new CollationKey(this, str, key);
+ return new CollationKey(this, source, key);
}
/**
- * This method tests this object for equality against the specified
- * object. This will be true if and only if the specified object is
- * another reference to this object.
- *
- * @param obj The Object
to compare against this object.
+ * This method returns a String
containing the collation rules
+ * for this object.
*
- * @return true
if the specified object is equal to this object, false
otherwise.
+ * @return The collation rules for this object.
*/
- public boolean equals(Object obj)
+ public String getRules()
{
- if (obj == this)
- return true;
- else
- return false;
+ return rules;
}
/**
@@ -929,15 +941,5 @@
public int hashCode()
{
return System.identityHashCode(this);
- }
-
- /**
- * This method creates a copy of this object.
- *
- * @return A copy of this object.
- */
- public Object clone()
- {
- return super.clone();
}
}