ICU Enhancement
This class is ICU's replacement for java..
ICU
Methods, fields, and other functionality specific to ICU are labeled 'ICU'.
Collator performs locale-sensitive string comparison. A concrete subclass, RuleBasedCollator, allows customization of the collation ordering by the use of rule sets.
A Collator is thread-safe only when frozen. See isFrozen() and Freezable.
Following the Unicode Consortium's specifications for the Unicode Collation Algorithm (UCA), there are 5 different levels of strength used in comparisons:
For more information about the collation service see the User Guide.
Examples of use
// Get the Collator for US English and set its strength to PRIMARY
Collator usCollator = Collator.getInstance(Locale.US);
usCollator.setStrength(Collator.PRIMARY);
if (usCollator.compare("abc", "ABC") == 0) {
System.out.println("Strings are equivalent");
}
The following example shows how to compare two strings using the
Collator for the default locale.
// Compare two strings in the default locale
Collator myCollator = Collator.getInstance();
myCollator.setDecomposition(NO_DECOMPOSITION);
if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
System.out.println("à\u0325 is not equals to a\u0325̀ without decomposition");
myCollator.setDecomposition(CANONICAL_DECOMPOSITION);
if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
System.out.println("Error: à\u0325 should be equals to a\u0325̀ with decomposition");
}
else {
System.out.println("à\u0325 is equals to a\u0325̀ with decomposition");
}
}
else {
System.out.println("Error: à\u0325 should be not equals to a\u0325̀ without decomposition");
}
RuleBasedCollator, CollationKey
| Modifier and Type | Class and Description |
|---|---|
| private static class | Collator.ASCII
Simpler/faster methods for ASCII than ones based on Unicode data. |
| public abstract static class | Collator.CollatorFactory
A factory used with registerFactory to register multiple collators and provide display names for them. |
| private static class | |
| public static interface | Collator.ReorderCodes
Reordering codes for non-script groups that can be reordered under collation. |
| pack-priv abstract static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | BASE
The resource bundle base name for this service. |
| public static final int | CANONICAL_DECOMPOSITION
Decomposition mode value. |
| private static final boolean | |
| public static final int | FULL_DECOMPOSITION
ICU Note This is for backwards compatibility with Java APIs only. |
| public static final int | IDENTICAL
Smallest Collator strength value. |
| private static final String[] | KEYWORDS
The list of keywords for this service. |
| public static final int | NO_DECOMPOSITION
Decomposition mode value. |
| public static final int | PRIMARY
Strongest collator strength value. |
| public static final int | QUATERNARY
ICU |
| private static final String | RESOURCE
The resource name for this service. |
| public static final int | SECONDARY
Second level collator strength value. |
| private static Collator. | |
| public static final int | TERTIARY
Third level collator strength value. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public Object | |
| public Collator | cloneAsThawed()
Implements com. |
| public abstract int | Returns: Returns an integer value. Value is less than zero if source is less than target, value is zero if source and target are equal, value is greater than zero if source is greater than target.the source String. source, String the target String. target)Redeclares java. |
| public int | Returns: Returns an integer value. Value is less than zero if source is less than target, value is zero if source and target are equal, value is greater than zero if source is greater than target.the source Object. source, Object the target Object. target)Implements java. |
| protected int | doCompare(CharSequence left, CharSequence right)
Deprecated
This API is ICU internal only.
Compares two CharSequences.
|
| public boolean | Returns: true if this Collator has exactly the same collation behavior as obj, false otherwise.the Collator to compare to. obj)Overrides java. Implements java. |
| public boolean | |
| public Collator | Returns: the collator itself.Implements com. |
| public static Locale[] | Returns: the list of locales in which collators are installed. This list includes any that have been registered, in addition to those that are installed with ICU4J.Returns the set of locales, as Locale objects, for which collators are installed. |
| public static final ULocale[] | Returns: the list of locales in which collators are installed. This list includes any that have been registered, in addition to those that are installed with ICU4J.ICU |
| public abstract CollationKey | Returns: the CollationKey for the given String based on this Collator's collation rules. If the source String is null, a null CollationKey is returned.the string to be transformed into a CollationKey. source)Transforms the String into a CollationKey suitable for efficient repeated comparison. |
| public int | |
| public static String | Returns: the display namethe locale of the collator objectLocale, Locale the locale for the collator's display name displayLocale)ICU |
| public static String | Returns: the display namethe locale of the collator objectLocale, ULocale the locale for the collator's display name displayLocale)ICU |
| public static String | |
| public static String | |
| public static int[] | Returns: the set of all reorder codes in the same group as the given reorder code.The reorder code to determine equivalence for. reorderCode)Retrieves all the reorder codes that are grouped with the given reorder code. |
| public static final ULocale | Returns: the localea particular keyword as enumerated by
getKeywords. keyword, ULocale The requested locale locID, boolean[] If non-null, isAvailable[0] will receive and
output boolean that indicates whether the requested locale was
'available' to the collation service. If non-null, isAvailable
must have length >= 1. isAvailable)ICU |
| public static final ULocale | Returns: the localea particular keyword as enumerated by
getKeywords. keyword, ULocale The requested locale locID)ICU |
| public static final Collator | Returns: the Collator for the default locale (for example, en_US) if it is created successfully. Otherwise if there is no Collator associated with the current locale, the root collator will be returned.Returns the Collator for the current default locale. |
| public static final Collator | Returns: Collator for the desired locale if it is created successfully. Otherwise if there is no Collator associated with the current locale, the root collator will be returned.the desired locale. locale)ICU |
| public static final Collator | Returns: Collator for the desired locale if it is created successfully. Otherwise if there is no Collator associated with the current locale, the root collator will be returned.the desired locale. locale)Returns the Collator for the desired locale. |
| private static final int | |
| public static final String[] | |
| public static final String[] | |
| public static final String[] | Returns: an array of string values for the given key and the locale.one of the keys supported by this service. For now, only
"collation" is supported. key, ULocale the locale locale, boolean if set to true it will return only commonly used values
with the given locale in preferred order. Otherwise,
it will return all the available values for the locale. commonlyUsed)ICU |
| public ULocale | Returns: the information specified by type, or null if this object was not constructed from locale data.type of information requested, either typecom. or com..ICU |
| public int | |
| public abstract RawCollationKey | Returns: If key is null, a new instance of RawCollationKey will be created and returned, otherwise the user provided key will be returned.the text String to be transformed into a RawCollationKey source, RawCollationKey key)ICU |
| private static final int | |
| public int[] | Returns: a copy of the reordering codes for this collator; if none are set then returns an empty arrayRetrieves the reordering codes for this collator. |
| private static Collator. | |
| public int | Returns: this Collator's current strength attribute.Returns this Collator's strength attribute. |
| public UnicodeSet | Returns: a pointer to a UnicodeSet object containing all the code points and sequences that may sort differently than in the root collator.ICU |
| public abstract VersionInfo | |
| public abstract int | |
| public abstract VersionInfo | |
| private static final boolean | |
| public int | Returns: a hash code value.Overrides java. |
| public boolean | isFrozen()
Implements com. |
| public static final Object | Returns: an object that can be used to unregister the registered factory.the factory to register factoryICU |
| public static final Object | Returns: an object that can be used to unregister the registered collator.the collator to register collator, ULocale the locale for which this is the default collator locale)ICU |
| private static void | setAttributesFromKeywords(ULocale loc, Collator coll, RuleBasedCollator rbc)
Sets collation attributes according to locale keywords. |
| public void | setDecomposition(int
the new decomposition mode decomposition)Sets the decomposition mode of this Collator. |
| pack-priv void | |
| public Collator | Returns: thisone of Collator.ReorderCodes.SPACE, Collator.ReorderCodes.PUNCTUATION,
Collator.ReorderCodes.SYMBOL, Collator.ReorderCodes.CURRENCY;
or Collator.ReorderCodes.DEFAULT to restore the default max variable group group)ICU |
| public void | setReorderCodes(int...
the reordering codes to apply to this collator; if this is null or an empty array
then this clears any existing reordering order)Sets the reordering codes for this collator. |
| public void | |
| public Collator | |
| public abstract int | Returns: variable top primary weightone or more (if contraction) characters to which the
variable top should be set varTop)
Deprecated
ICU 53 Call
setMaxVariable(int) instead.
ICU |
| public abstract void | setVariableTop(int
primary weight, as returned by setVariableTop or getVariableTop varTop)
Deprecated
ICU 53 Call setMaxVariable() instead.
ICU |
| public static final boolean | Returns: true if the collator was successfully unregistered.the object previously returned by registerInstance. registryKey)ICU |