*
* @author Aaron M. Renn <arenn@urbanophile.com>
* @author Tom Tromey <tromey@cygnus.com>
+ * @author Guilhem Lavaux <guilhem.lavaux@free.fr>
*/
public final class CollationElementIterator
{
* @param collator The <code>RuleBasedCollation</code> used for calculating collation values
* @param text The <code>String</code> to iterate over.
*/
- CollationElementIterator (String text, RuleBasedCollator collator)
+ CollationElementIterator(RuleBasedCollator collator, String text)
{
- setText (text);
this.collator = collator;
+
+ setText (text);
}
/**
- * This method returns the collation ordering value of the next character
- * in the string. This method will return <code>NULLORDER</code> if the
+ * This method returns the collation ordering value of the next character sequence
+ * in the string (it may be an extended character following collation rules).
+ * This method will return <code>NULLORDER</code> if the
* end of the string was reached.
*
* @return The collation ordering value.
*
* @return The primary order value of the specified collation value. This is the high 16 bits.
*/
- public static final int primaryOrder (int order)
+ public static final int primaryOrder(int order)
{
// From the JDK 1.2 spec.
return order >>> 16;
*
* @return The secondary order value of the specified collation value. This is the bits 8-15.
*/
- public static final short secondaryOrder (int order)
+ public static final short secondaryOrder(int order)
{
// From the JDK 1.2 spec.
return (short) ((order >>> 8) & 255);
*
* @return The tertiary order value of the specified collation value. This is the low eight bits.
*/
- public static final short tertiaryOrder (int order)
+ public static final short tertiaryOrder(int order)
{
// From the JDK 1.2 spec.
return (short) (order & 255);
*
* @since 1.2
*/
- public void setText (String text)
+ public void setText(String text)
{
this.text = text;
this.index = 0;
{
return index;
}
-
-} // class CollationElementIterator
-
+}
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.Enumeration;
* <li> Reset: '&' : <text>
* </ul>
* The modifier character indicates that accents sort backward as is the
- * case with French. The relational operators specify how the text
+ * case with French. The modifier applies to all rules <b>after</b>
+ * the modifier but before the next primary sequence. If placed at the end
+ * of the sequence if applies to all unknown accented character.
+ * The relational operators specify how the text
* argument relates to the previous term. The relation characters have
* the following meanings:
* <ul>
* anywhere in the previous rule string segment so the rule following the
* reset rule cannot be inserted.
* <p>
+ * "< a & A @ < e & E < f& F" - This sequence is equivalent to the following
+ * "< a & A < E & e < f & F".
+ * <p>
* For a description of the various comparison strength types, see the
* documentation for the <code>Collator</code> class.
* <p>
*
* @author Aaron M. Renn <arenn@urbanophile.com>
* @author Tom Tromey <tromey@cygnus.com>
- * @date March 25, 1999
+ * @author Guilhem Lavaux <guilhem@kaffe.org>
*/
-
public class RuleBasedCollator extends Collator
{
+ /**
+ * This class describes what rank has a character (or a sequence of characters)
+ * in the lexicographic order. Each element in a rule has a collation element.
+ */
final class CollationElement
{
String key;
*
* @exception ParseException If the rule string contains syntax errors.
*/
- public RuleBasedCollator (String rules) throws ParseException
+ public RuleBasedCollator(String rules) throws ParseException
{
if (rules.equals (""))
throw new ParseException ("empty rule set", 0);
* 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 <code>String</code> to compare.
- * @param s2 A second <code>String</code> to compare to the first.
+ * @param source The first <code>String</code> to compare.
+ * @param target A second <code>String</code> 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 source, String target)
+ public int compare(String source, String target)
{
CollationElementIterator cs, ct;
- cs = new CollationElementIterator (source, this);
- ct = new CollationElementIterator (target, this);
+ cs = new CollationElementIterator(this, source);
+ ct = new CollationElementIterator(this, target);
- while (true)
+ for(;;)
{
int os = next (cs, strength);
int ot = next (ct, strength);
*
* @param obj The <code>Object</code> to compare against this object.
*
- * @return <code>true</code> if the specified object is equal to this object, <code>false</code> otherwise.
+ * @return <code>true</code> if the specified object is equal to this object,
+ * <code>false</code> otherwise.
*/
- public boolean equals (Object obj)
+ public boolean equals(Object obj)
{
if (! (obj instanceof RuleBasedCollator) || ! super.equals(obj))
return false;
* for the specified <code>String</code> under the collation rules for this
* object.
*
- * @param str The <code>String</code> to return the <code>CollationElementIterator</code> instance for.
+ * @param source The <code>String</code> to return the
+ * <code>CollationElementIterator</code> instance for.
*
- * @return A <code>CollationElementIterator</code> for the specified <code>String</code>.
+ * @return A <code>CollationElementIterator</code> for the specified
+ * <code>String</code>.
*/
- public CollationElementIterator getCollationElementIterator (String source)
+ public CollationElementIterator getCollationElementIterator(String source)
{
StringBuffer expand = new StringBuffer (source.length());
int max = source.length();
for (int i = 0; i < max; ++i)
decomposeCharacter (source.charAt(i), expand);
- return new CollationElementIterator (expand.toString(), this);
+ return new CollationElementIterator(this, expand.toString());
}
/**
* for the <code>String</code> represented by the specified
* <code>CharacterIterator</code>.
*
- * @param ci The <code>CharacterIterator</code> with the desired <code>String</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)
+ public CollationElementIterator getCollationElementIterator(CharacterIterator source)
{
- StringBuffer expand = new StringBuffer ();
+ StringBuffer expand = new StringBuffer();
for (char c = source.first ();
c != CharacterIterator.DONE;
c = source.next ())
decomposeCharacter (c, expand);
- return new CollationElementIterator (expand.toString(), this);
+ return new CollationElementIterator(this, expand.toString());
}
/**
* provide speed benefits if multiple comparisons are performed, such
* as during a sort.
*
- * @param str The <code>String</code> to create a <code>CollationKey</code> for.
+ * @param source The <code>String</code> to create a <code>CollationKey</code> for.
*
* @return A <code>CollationKey</code> for the specified <code>String</code>.
*/
- public CollationKey getCollationKey (String source)
+ public CollationKey getCollationKey(String source)
{
- return new CollationKey (getCollationElementIterator (source), source,
- strength);
+ return new CollationKey(getCollationElementIterator(source), source,
+ strength);
}
/**