CollationKey Class

Definition

A CollationKey represents a String under the rules of a specific Collator object.

[Android.Runtime.Register("android/icu/text/CollationKey", ApiSince=24, DoNotGenerateAcw=true)]
public sealed class CollationKey : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable
[<Android.Runtime.Register("android/icu/text/CollationKey", ApiSince=24, DoNotGenerateAcw=true)>]
type CollationKey = class
    inherit Object
    interface IComparable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
CollationKey
Attributes
Implements

Remarks

A CollationKey represents a String under the rules of a specific Collator object. Comparing two CollationKeys returns the relative order of the Strings they represent.

Since the rule set of Collators can differ, the sort orders of the same string under two different Collators might differ. Hence comparing CollationKeys generated from different Collators can give incorrect results.

Both the method CollationKey.compareTo(CollationKey) and the method Collator.compare(String, String) compare two strings and returns their relative order. The performance characteristics of these two approaches can differ. Note that collation keys are often less efficient than simply doing comparison. For more details, see the ICU User Guide.

During the construction of a CollationKey, the entire source string is examined and processed into a series of bits terminated by a null, that are stored in the CollationKey. When CollationKey.compareTo(CollationKey) executes, it performs bitwise comparison on the bit sequences. This can incurs startup cost when creating the CollationKey, but once the key is created, binary comparisons are fast. This approach is recommended when the same strings are to be compared over and over again.

On the other hand, implementations of Collator.compare(String, String) can examine and process the strings only until the first characters differing in order. This approach is recommended if the strings are to be compared only once.

More information about the composition of the bit sequence can be found in the user guide.

The following example shows how CollationKeys can be used to sort a list of Strings.

<blockquote>

// Create an array of CollationKeys for the Strings to be sorted.
            Collator myCollator = Collator.getInstance();
            CollationKey[] keys = new CollationKey[3];
            keys[0] = myCollator.getCollationKey("Tom");
            keys[1] = myCollator.getCollationKey("Dick");
            keys[2] = myCollator.getCollationKey("Harry");
            sort( keys );
<br>
            //...
<br>
            // Inside body of sort routine, compare keys this way
            if( keys[i].compareTo( keys[j] ) &gt; 0 )
               // swap keys[i] and keys[j]
<br>
            //...
<br>
            // Finally, when we've returned from sort.
            System.out.println( keys[0].getSourceString() );
            System.out.println( keys[1].getSourceString() );
            System.out.println( keys[2].getSourceString() );

</blockquote>

This class is not subclassable

Java documentation for android.icu.text.CollationKey.

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

CollationKey(String, Byte[])

CollationKey constructor.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
SourceString

Return the source string that this CollationKey represents.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CompareTo(CollationKey)

Compare this CollationKey to another CollationKey.

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

Compare this CollationKey and the argument target CollationKey for equality.

Equals(Object)

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

(Inherited from Object)
GetBound(Int32, Int32)

Produces a bound for the sort order of a given collation key and a strength level.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
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)
Merge(CollationKey)

Merges this CollationKey with another.

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)
ToArray<T>() (Inherited from Object)
ToByteArray()

Duplicates and returns the value of this CollationKey as a sequence of big-endian bytes terminated by a null.

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

IComparable.CompareTo(Object)
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