Build 1.0_r1(from source)

java.text
Class RuleBasedCollator

java.lang.Object
  extended by java.text.Collator
      extended by java.text.RuleBasedCollator
All Implemented Interfaces:
Cloneable, Comparator<Object>

public class RuleBasedCollator
extends Collator

RuleBasedCollator is a concrete subclass of Collator. It allows customization of the Collator via user-specified rule sets. RuleBasedCollator is designed to be fully compliant to the Unicode Collation Algorithm (UCA) and conforms to ISO 14651.

Create a RuleBasedCollator from a locale by calling the getInstance(Locale) factory method in the base class Collator.Collator.getInstance(Locale) creates a RuleBasedCollator object based on the collation rules defined by the argument locale. If a customized collation is required, use the RuleBasedCollator(String) constructor with the appropriate rules. The customized RuleBasedCollator will base its ordering on UCA, while re-adjusting the attributes and orders of the characters in the specified rule accordingly.


Field Summary
 
Fields inherited from class java.text.Collator
CANONICAL_DECOMPOSITION, EQUAL, FULL_DECOMPOSITION, GREATER, icuColl, IDENTICAL, LESS, NO_DECOMPOSITION, PRIMARY, SECONDARY, TERTIARY
 
Constructor Summary
RuleBasedCollator(com.ibm.icu4jni.text.Collator wrapper)
           
RuleBasedCollator(String rules)
          Constructs a new instance of RuleBasedCollator using the specified rules.
 
Method Summary
 Object clone()
          Obtains the cloned object of the RuleBasedCollator
 int compare(String source, String target)
          Compares the source text String to the target text String according to the collation rules, strength and decomposition mode for this RuleBasedCollator.
 boolean equals(Object obj)
          Compares the equality of two RuleBasedCollator objects.
 CollationElementIterator getCollationElementIterator(CharacterIterator source)
          Obtains a CollationElementIterator for the given CharacterIterator.
 CollationElementIterator getCollationElementIterator(String source)
          Obtains a CollationElementIterator for the given String.
 CollationKey getCollationKey(String source)
          Obtains the CollationKey for the given source text.
 String getRules()
          Obtains the collation rules of the RuleBasedCollator.
 int hashCode()
          Obtains a unique hash code for the RuleBasedCollator
 
Methods inherited from class java.text.Collator
compare, equals, getAvailableLocales, getDecomposition, getInstance, getInstance, getStrength, setDecomposition, setStrength
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleBasedCollator

RuleBasedCollator(com.ibm.icu4jni.text.Collator wrapper)

RuleBasedCollator

public RuleBasedCollator(String rules)
                  throws ParseException
Constructs a new instance of RuleBasedCollator using the specified rules.

Parameters:
rules - the collation rules.
Throws:
ParseException - when the rules contains an invalid collation rule syntax.
Method Detail

getCollationElementIterator

public CollationElementIterator getCollationElementIterator(CharacterIterator source)
Obtains a CollationElementIterator for the given CharacterIterator. The source iterator's integrity will be preserved since a new copy will be created for use.

Parameters:
source - the specified source
Returns:
a CollationElementIterator for the source.

getCollationElementIterator

public CollationElementIterator getCollationElementIterator(String source)
Obtains a CollationElementIterator for the given String.

Parameters:
source - the specified source
Returns:
a CollationElementIterator for the given String

getRules

public String getRules()
Obtains the collation rules of the RuleBasedCollator.

Returns:
the collation rules.

clone

public Object clone()
Obtains the cloned object of the RuleBasedCollator

Overrides:
clone in class Collator
Returns:
the cloned object of the RuleBasedCollator
See Also:
Cloneable

compare

public int compare(String source,
                   String target)
Compares the source text String to the target text String according to the collation rules, strength and decomposition mode for this RuleBasedCollator. See the Collator class description for an example of use.

General recommendation: If comparisons are to be done to the same String multiple times, it would be more efficient to generate CollationKeys for the String s and use CollationKey.compareTo(CollationKey) for the comparisons. If the each Strings are compared to only once, using the method RuleBasedCollator.compare(String, String) will have a better performance.

Specified by:
compare in class Collator
Parameters:
source - the source text
target - the target text
Returns:
an integer which may be a negative value, zero, or else a positive value depending on whether source is less than, equivalent to, or greater than target.

getCollationKey

public CollationKey getCollationKey(String source)
Obtains the CollationKey for the given source text.

Specified by:
getCollationKey in class Collator
Parameters:
source - the specified source text
Returns:
the CollationKey for the given source text.

hashCode

public int hashCode()
Obtains a unique hash code for the RuleBasedCollator

Specified by:
hashCode in class Collator
Returns:
the hash code for the RuleBasedCollator
See Also:
Collator.equals(Object), Collator.equals(String, String)

equals

public boolean equals(Object obj)
Compares the equality of two RuleBasedCollator objects. RuleBasedCollator objects are equal if they have the same collation rules and the same attributes.

Specified by:
equals in interface Comparator<Object>
Overrides:
equals in class Collator
Parameters:
obj - the other object.
Returns:
true if this RuleBasedCollator has exactly the same collation behaviour as obj, false otherwise.
See Also:
Collator.hashCode()

Build 1.0_r1(from source)

Please submit a feedback, bug or feature