Share via


Collator Class

Definition

<strong>[icu enhancement]</strong> ICU's replacement for java.text.Collator.

[Android.Runtime.Register("android/icu/text/Collator", ApiSince=24, DoNotGenerateAcw=true)]
public abstract class Collator : Java.Lang.Object, Android.Icu.Util.IFreezable, IDisposable, Java.Interop.IJavaPeerable, Java.Util.IComparator
[<Android.Runtime.Register("android/icu/text/Collator", ApiSince=24, DoNotGenerateAcw=true)>]
type Collator = class
    inherit Object
    interface IFreezable
    interface ICloneable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComparator
Inheritance
Collator
Derived
Attributes
Implements

Remarks

<strong>[icu enhancement]</strong> ICU's replacement for java.text.Collator.&nbsp;Methods, fields, and other functionality specific to ICU are labeled '<strong>[icu]</strong>'.

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:

<ul> <li>PRIMARY strength: Typically, this is used to denote differences between base characters (for example, "a" &lt; "b"). It is the strongest difference. For example, dictionaries are divided into different sections by base character. <li>SECONDARY strength: Accents in the characters are considered secondary differences (for example, "as" &lt; "&agrave;s" &lt; "at"). Other differences between letters can also be considered secondary differences, depending on the language. A secondary difference is ignored when there is a primary difference anywhere in the strings. <li>TERTIARY strength: Upper and lower case differences in characters are distinguished at tertiary strength (for example, "ao" &lt; "Ao" &lt; "a&ograve;"). In addition, a variant of a letter differs from the base form on the tertiary strength (such as "A" and "Ⓐ"). Another example is the difference between large and small Kana. A tertiary difference is ignored when there is a primary or secondary difference anywhere in the strings. <li>QUATERNARY strength: When punctuation is ignored (see Ignoring Punctuations in the User Guide) at PRIMARY to TERTIARY strength, an additional strength level can be used to distinguish words with and without punctuation (for example, "ab" &lt; "a-b" &lt; "aB"). This difference is ignored when there is a PRIMARY, SECONDARY or TERTIARY difference. The QUATERNARY strength should only be used if ignoring punctuation is required. <li>IDENTICAL strength: When all other strengths are equal, the IDENTICAL strength is used as a tiebreaker. The Unicode code point values of the NFD form of each string are compared, just in case there is no difference. For example, Hebrew cantillation marks are only distinguished at this strength. This strength should be used sparingly, as only code point value differences between two strings is an extremely rare occurrence. Using this strength substantially decreases the performance for both comparison and collation key generation APIs. This strength also increases the size of the collation key. </ul>

Unlike the JDK, ICU4J's Collator deals only with 2 decomposition modes, the canonical decomposition mode and one that does not use any decomposition. The compatibility decomposition mode, java.text.Collator.FULL_DECOMPOSITION is not supported here. If the canonical decomposition mode is set, the Collator handles un-normalized text properly, producing the same results as if the text were normalized in NFD. If canonical decomposition is turned off, it is the user's responsibility to ensure that all text is already in the appropriate form before performing a comparison or before getting a CollationKey.

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("&agrave;&#92;u0325", "a&#92;u0325&#768;") != 0) {
                System.out.println("&agrave;&#92;u0325 is not equals to a&#92;u0325&#768; without decomposition");
                myCollator.setDecomposition(CANONICAL_DECOMPOSITION);
                if (myCollator.compare("&agrave;&#92;u0325", "a&#92;u0325&#768;") != 0) {
                    System.out.println("Error: &agrave;&#92;u0325 should be equals to a&#92;u0325&#768; with decomposition");
                }
                else {
                    System.out.println("&agrave;&#92;u0325 is equals to a&#92;u0325&#768; with decomposition");
                }
            }
            else {
                System.out.println("Error: &agrave;&#92;u0325 should be not equals to a&#92;u0325&#768; without decomposition");
            }

Java documentation for android.icu.text.Collator.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Collator()

Empty default constructor to make javadocs happy

Collator(IntPtr, JniHandleOwnership)

Fields

CanonicalDecomposition
Obsolete.

Decomposition mode value.

FullDecomposition
Obsolete.

<strong>[icu] Note:</strong> This is for backwards compatibility with Java APIs only.

Identical
Obsolete.

Smallest Collator strength value.

NoDecomposition
Obsolete.

Decomposition mode value.

Primary
Obsolete.

Strongest collator strength value.

Quaternary
Obsolete.

<strong>[icu]</strong> Fourth level collator strength value.

Secondary
Obsolete.

Second level collator strength value.

Tertiary
Obsolete.

Third level collator strength value.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Decomposition

Returns the decomposition mode of this Collator. -or- Sets the decomposition mode of this Collator.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
Instance

Returns the Collator for the current default locale.

IsFrozen

Determines whether the object has been frozen or not.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
MaxVariable

<strong>[icu]</strong> Returns the maximum reordering group whose characters are affected by the alternate handling behavior.

PeerReference (Inherited from Object)
Strength

Returns this Collator's strength attribute. -or- Sets this Collator's strength attribute.

TailoredSet

<strong>[icu]</strong> Returns a UnicodeSet that contains all the characters and sequences tailored in this collator.

ThresholdClass
ThresholdType
UCAVersion
VariableTop
Version

Methods

Clone()

Clones the collator.

CloneAsThawed()

Provides for the clone operation.

Compare(Object, Object)

Compares the source Object to the target Object.

Compare(String, String)

Compares the source text String to the target text String according to this Collator's rules, strength and decomposition mode.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Equals(String, String)

Compares the equality of two text Strings using this Collator's rules, strength and decomposition mode.

Freeze()

Freezes the collator.

GetAvailableLocales()

Returns the set of locales, as Locale objects, for which collators are installed.

GetAvailableULocales()

<strong>[icu]</strong> Returns the set of locales, as ULocale objects, for which collators are installed.

GetCollationKey(String)

Transforms the String into a CollationKey suitable for efficient repeated comparison.

GetDisplayName(Locale, Locale)

<strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the displayLocale.

GetDisplayName(Locale)

<strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the default DISPLAY locale.

GetDisplayName(ULocale, ULocale)

<strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the displayLocale.

GetDisplayName(ULocale)

<strong>[icu]</strong> Returns the name of the collator for the objectLocale, localized for the default DISPLAY locale.

GetEquivalentReorderCodes(Int32)

Retrieves all the reorder codes that are grouped with the given reorder code.

GetFunctionalEquivalent(String, ULocale, Boolean[])

<strong>[icu]</strong> Returns the functionally equivalent locale for the given requested locale, with respect to given keyword, for the collation service.

GetFunctionalEquivalent(String, ULocale)

<strong>[icu]</strong> Returns the functionally equivalent locale for the given requested locale, with respect to given keyword, for the collation service.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetInstance(Locale)

Returns the Collator for the desired locale.

GetInstance(ULocale)

<strong>[icu]</strong> Returns the Collator for the desired locale.

GetKeywords()

<strong>[icu]</strong> Returns an array of all possible keywords that are relevant to collation.

GetKeywordValues(String)

<strong>[icu]</strong> Given a keyword, returns an array of all values for that keyword that are currently in use.

GetKeywordValuesForLocale(String, ULocale, Boolean)

<strong>[icu]</strong> Given a key and a locale, returns an array of string values in a preferred order that would make a difference.

GetReorderCodes()

Retrieves the reordering codes for this collator.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetMaxVariable(Int32)

<strong>[icu]</strong> Sets the variable top to the top of the specified reordering group.

SetReorderCodes(Int32[])

Sets the reordering codes for this collator.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IComparator.Compare(Object, Object)
IFreezable.CloneAsThawed()
IFreezable.Freeze()
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to