Sdílet prostřednictvím


CollationKey Class

Definition

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

[Android.Runtime.Register("java/text/CollationKey", DoNotGenerateAcw=true)]
public abstract class CollationKey : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable
[<Android.Runtime.Register("java/text/CollationKey", 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. Using CollationKeys to compare Strings is generally faster than using Collator.compare. Thus, when the Strings must be compared multiple times, for example when sorting a list of Strings. It's more efficient to use CollationKeys.

You can not create CollationKeys directly. Rather, generate them by calling Collator.getCollationKey. You can only compare CollationKeys generated from the same Collator object.

Generating a CollationKey for a String involves examining the entire String and converting it to series of bits that can be compared bitwise. This allows fast comparisons once the keys are generated. The cost of generating keys is recouped in faster comparisons when Strings need to be compared many times. On the other hand, the result of a comparison is often determined by the first couple of characters of each String. Collator.compare examines only as many characters as it needs which allows it to be faster when doing single comparisons.

The following example shows how CollationKeys might be used to sort a list of Strings. <blockquote>

{@code
            // 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);

            //...

            // Inside body of sort routine, compare keys this way
            if (keys[i].compareTo(keys[j]) > 0)
               // swap keys[i] and keys[j]

            //...

            // 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>

Added in 1.1.

Java documentation for java.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(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

CollationKey(String)

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

Returns the 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.

ThresholdType

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

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CompareTo(CollationKey)

Compare this CollationKey to the target CollationKey.

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

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

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

Converts the CollationKey to a sequence of bits.

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)

Applies to