Share via


AlphabeticIndex Class

Definition

AlphabeticIndex supports the creation of a UI index appropriate for a given language.

[Android.Runtime.Register("android/icu/text/AlphabeticIndex", ApiSince=24, DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "V" })]
public sealed class AlphabeticIndex : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IIterable
[<Android.Runtime.Register("android/icu/text/AlphabeticIndex", ApiSince=24, DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "V" })>]
type AlphabeticIndex = class
    inherit Object
    interface IIterable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
AlphabeticIndex
Attributes
Implements

Remarks

AlphabeticIndex supports the creation of a UI index appropriate for a given language. It can support either direct use, or use with a client that doesn't support localized collation. The following is an example of what an index might look like in a UI:

<b>... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  ...</b>

<b>A</b>
                Addison
                Albertson
                Azensky
<b>B</b>
                Baecker
             ...

The class can generate a list of labels for use as a UI "index", that is, a list of clickable characters (or character sequences) that allow the user to see a segment (bucket) of a larger "target" list. That is, each label corresponds to a bucket in the target list, where everything in the bucket is greater than or equal to the character (according to the locale's collation). Strings can be added to the index; they will be in sorted order in the right bucket.

The class also supports having buckets for strings before the first (underflow), after the last (overflow), and between scripts (inflow). For example, if the index is constructed with labels for Russian and English, Greek characters would fall into an inflow bucket between the other two scripts.

<em>Note:</em> If you expect to have a lot of ASCII or Latin characters as well as characters from the user's language, then it is a good idea to call addLabels(ULocale.English).

<h2>Direct Use</h2>

The following shows an example of building an index directly. The "show..." methods below are just to illustrate usage.

// Create a simple index where the values for the strings are Integers, and add the strings

            AlphabeticIndex&lt;Integer&gt; index = new AlphabeticIndex&lt;Integer&gt;(desiredLocale).addLabels(additionalLocale);
            int counter = 0;
            for (String item : test) {
                index.addRecord(item, counter++);
            }
            ...
            // Show index at top. We could skip or gray out empty buckets

            for (AlphabeticIndex.Bucket&lt;Integer&gt; bucket : index) {
                if (showAll || bucket.size() != 0) {
                    showLabelAtTop(UI, bucket.getLabel());
                }
            }
             ...
            // Show the buckets with their contents, skipping empty buckets

            for (AlphabeticIndex.Bucket&lt;Integer&gt; bucket : index) {
                if (bucket.size() != 0) {
                    showLabelInList(UI, bucket.getLabel());
                    for (AlphabeticIndex.Record&lt;Integer&gt; item : bucket) {
                        showIndexedItem(UI, item.getName(), item.getData());
                    }

The caller can build different UIs using this class. For example, an index character could be omitted or grayed-out if its bucket is empty. Small buckets could also be combined based on size, such as:

<b>... A-F G-N O-Z ...</b>

<h2>Client Support</h2>

Callers can also use the AlphabeticIndex.ImmutableIndex, or the AlphabeticIndex itself, to support sorting on a client that doesn't support AlphabeticIndex functionality.

The ImmutableIndex is both immutable and thread-safe. The corresponding AlphabeticIndex methods are not thread-safe because they "lazily" build the index buckets. <ul> <li>ImmutableIndex.getBucket(index) provides random access to all buckets and their labels and label types. <li>AlphabeticIndex.getBucketLabels() or the bucket iterator on either class can be used to get a list of the labels, such as "...", "A", "B",..., and send that list to the client. <li>When the client has a new name, it sends that name to the server. The server needs to call the following methods, and communicate the bucketIndex and collationKey back to the client.

int bucketIndex = index.getBucketIndex(name);
            String label = immutableIndex.getBucket(bucketIndex).getLabel();  // optional
            RawCollationKey collationKey = collator.getRawCollationKey(name, null);

<li>The client would put the name (and associated information) into its bucket for bucketIndex. The collationKey is a sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li> </ul>

Java documentation for android.icu.text.AlphabeticIndex.

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

AlphabeticIndex(Locale)

Create the index object.

AlphabeticIndex(RuleBasedCollator)

Create an AlphabeticIndex that uses a specific collator.

AlphabeticIndex(ULocale)

Create the index object.

Properties

BucketCount

Return the number of buckets in the index.

BucketLabels

Get the labels.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Collator

Get a clone of the collator used internally.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
InflowLabel

Get the default label used for abbreviated buckets between other labels.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
MaxLabelCount

Get the limit on the number of labels in the index.

OverflowLabel

Get the default label used in the IndexCharacters' locale for overflow, eg the first item in: .

PeerReference (Inherited from Object)
RecordCount

Return the number of records in the index: that is, the total number of distinct &lt;name,data&gt; pairs added with addRecord(.

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)
UnderflowLabel

Get the default label used in the IndexCharacters' locale for underflow, eg the last item in: X Y Z .

Methods

AddLabels(Locale[])
AddLabels(ULocale[])
AddLabels(UnicodeSet)

Add more index characters (aside from what are in the locale)

AddRecord(ICharSequence, Object)

Add a record (name and data) to the index.

AddRecord(String, Object)

Add a record (name and data) to the index.

BuildImmutableIndex()
ClearRecords()

Clear the index.

Clone()

Creates and returns a copy of this object.

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

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

(Inherited from Object)
GetBucketIndex(ICharSequence)

Get the bucket number for the given name.

GetBucketIndex(String)

Get the bucket number for the given name.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
Iterator()

Return an iterator over the buckets.

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)
SetInflowLabel(String)

Set the inflowLabel label

SetMaxLabelCount(Int32)

Set a limit on the number of labels in the index.

SetOverflowLabel(String)

Set the overflow label

SetUnderflowLabel(String)

Set the underflowLabel label

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

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.

ToEnumerable(IIterable)
ToEnumerable<T>(IIterable)

Applies to