Final

java.text
Class Collator

java.lang.Object
  extended by java.text.Collator
All Implemented Interfaces:
Cloneable, Comparator
Direct Known Subclasses:
RuleBasedCollator

public abstract class Collator
extends Object
implements Comparator, Cloneable

Collator is an abstract class which is the root of classes which provide Locale specific String comparison to determine their ordering with respect to each other.


Field Summary
static int CANONICAL_DECOMPOSITION
          Constant used to specify the decomposition rule.
static int FULL_DECOMPOSITION
          Constant used to specify the decomposition rule.
static int IDENTICAL
          Constant used to specify the collation strength.
static int NO_DECOMPOSITION
          Constant used to specify the decomposition rule.
static int PRIMARY
          Constant used to specify the collation strength.
static int SECONDARY
          Constant used to specify the collation strength.
static int TERTIARY
          Constant used to specify the collation strength.
 
Constructor Summary
protected Collator()
          Constructs a new instance of this Collator.
 
Method Summary
 Object clone()
          Answers a new Collator with the same decomposition rule and strength value as this Collator.
 int compare(Object object1, Object object2)
          Compares the two objects to determine their relative ordering.
abstract  int compare(String string1, String string2)
          Compares the two Strings to determine their relative ordering.
 boolean equals(Object object)
          Compares the specified object to this Collator and answer if they are equal.
 boolean equals(String string1, String string2)
          Compares the two Strings using the collation rules to determine if they are equal.
static Locale[] getAvailableLocales()
          Gets the list of installed Locales which support Collator.
abstract  CollationKey getCollationKey(String string)
          Answers a CollationKey for the specified String for this Collator with the current decomposition rule and stength value.
 int getDecomposition()
          Answers the decomposition rule for this Collator.
static Collator getInstance()
          Answers a Collator instance which is appropriate for the default Locale.
static Collator getInstance(Locale locale)
          Answers a Collator instance which is appropriate for the specified Locale.
 int getStrength()
          Answers the strength value for this Collator.
abstract  int hashCode()
          Answers an integer hash code for the receiver.
 void setDecomposition(int value)
          Sets the decomposition rule for this Collator.
 void setStrength(int value)
          Sets the strength value for this Collator.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_DECOMPOSITION

public static final int NO_DECOMPOSITION
Constant used to specify the decomposition rule.

See Also:
Constant Field Values

CANONICAL_DECOMPOSITION

public static final int CANONICAL_DECOMPOSITION
Constant used to specify the decomposition rule.

See Also:
Constant Field Values

FULL_DECOMPOSITION

public static final int FULL_DECOMPOSITION
Constant used to specify the decomposition rule.

See Also:
Constant Field Values

PRIMARY

public static final int PRIMARY
Constant used to specify the collation strength.

See Also:
Constant Field Values

SECONDARY

public static final int SECONDARY
Constant used to specify the collation strength.

See Also:
Constant Field Values

TERTIARY

public static final int TERTIARY
Constant used to specify the collation strength.

See Also:
Constant Field Values

IDENTICAL

public static final int IDENTICAL
Constant used to specify the collation strength.

See Also:
Constant Field Values
Constructor Detail

Collator

protected Collator()
Constructs a new instance of this Collator.

Method Detail

clone

public Object clone()
Answers a new Collator with the same decomposition rule and strength value as this Collator.

Overrides:
clone in class Object
Returns:
a shallow copy of this Collator
See Also:
Cloneable

compare

public int compare(Object object1,
                   Object object2)
Compares the two objects to determine their relative ordering. The objects must be Strings.

Specified by:
compare in interface Comparator
Parameters:
object1 - the first String to compare
object2 - the second String to compare
Returns:
an int < 0 if object1 is less than object2, 0 if they are equal, and > 0 if object1 is greater than object2
Throws:
ClassCastException - when the objects are not Strings

compare

public abstract int compare(String string1,
                            String string2)
Compares the two Strings to determine their relative ordering.

Parameters:
string1 - the first String to compare
string2 - the second String to compare
Returns:
an int < 0 if string1 is less than string2, 0 if they are equal, and > 0 if string1 is greater than string2

equals

public boolean equals(Object object)
Compares the specified object to this Collator and answer if they are equal. The object must be an instance of Collator and have the same strength and decomposition values.

Specified by:
equals in interface Comparator
Overrides:
equals in class Object
Parameters:
object - the object to compare with this object
Returns:
true if the specified object is equal to this Collator, false otherwise
See Also:
hashCode()

equals

public boolean equals(String string1,
                      String string2)
Compares the two Strings using the collation rules to determine if they are equal.

Parameters:
string1 - the first String to compare
string2 - the second String to compare
Returns:
true if the strings are equal using the collation rules, false otherwise

getAvailableLocales

public static Locale[] getAvailableLocales()
Gets the list of installed Locales which support Collator.

Returns:
an array of Locale

getCollationKey

public abstract CollationKey getCollationKey(String string)
Answers a CollationKey for the specified String for this Collator with the current decomposition rule and stength value.

Returns:
a CollationKey

getDecomposition

public int getDecomposition()
Answers the decomposition rule for this Collator.

Returns:
the decomposition rule, either NO_DECOMPOSITION, CANONICAL_DECOMPOSITION or FULL_DECOMPOSITION

getInstance

public static Collator getInstance()
Answers a Collator instance which is appropriate for the default Locale.

Returns:
a Collator

getInstance

public static Collator getInstance(Locale locale)
Answers a Collator instance which is appropriate for the specified Locale.

Parameters:
locale - the Locale
Returns:
a Collator

getStrength

public int getStrength()
Answers the strength value for this Collator.

Returns:
the strength value, either PRIMARY, SECONDARY, TERTIARY, or IDENTICAL

hashCode

public abstract int hashCode()
Answers an integer hash code for the receiver. Objects which are equal answer the same value for this method.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(Object), equals(String, String)

setDecomposition

public void setDecomposition(int value)
Sets the decomposition rule for this Collator.

Parameters:
value - the decomposition rule, either NO_DECOMPOSITION, CANONICAL_DECOMPOSITION or FULL_DECOMPOSITION
Throws:
IllegalArgumentException - when the decomposition rule is not valid

setStrength

public void setStrength(int value)
Sets the strength value for this Collator.

Parameters:
value - the strength value, either PRIMARY, SECONDARY, TERTIARY, or IDENTICAL
Throws:
IllegalArgumentException - when the strength value is not valid

Final

Licensed Materials - Property of IBM
© Copyright IBM Corp. 2006, 2008 All Rights Reserved.