|
| AlphabeticIndex (const Locale &locale, UErrorCode &status) |
| Construct an AlphabeticIndex object for the specified locale. More...
|
|
| AlphabeticIndex (RuleBasedCollator *collator, UErrorCode &status) |
| Construct an AlphabeticIndex that uses a specific collator. More...
|
|
virtual AlphabeticIndex & | addLabels (const UnicodeSet &additions, UErrorCode &status) |
| Add Labels to this Index. More...
|
|
virtual AlphabeticIndex & | addLabels (const Locale &locale, UErrorCode &status) |
| Add the index characters from a Locale to the index. More...
|
|
virtual | ~AlphabeticIndex () |
| Destructor. More...
|
|
ImmutableIndex * | buildImmutableIndex (UErrorCode &errorCode) |
| Builds an immutable, thread-safe version of this instance, without data records. More...
|
|
virtual const RuleBasedCollator & | getCollator () const |
| Get the Collator that establishes the ordering of the items in this index. More...
|
|
virtual const UnicodeString & | getInflowLabel () const |
| Get the default label used for abbreviated buckets between other index characters. More...
|
|
virtual AlphabeticIndex & | setInflowLabel (const UnicodeString &inflowLabel, UErrorCode &status) |
| Set the default label used for abbreviated buckets between other index characters. More...
|
|
virtual const UnicodeString & | getOverflowLabel () const |
| Get the special label used for items that sort after the last normal label, and that would not otherwise have an appropriate label. More...
|
|
virtual AlphabeticIndex & | setOverflowLabel (const UnicodeString &overflowLabel, UErrorCode &status) |
| Set the label used for items that sort after the last normal label, and that would not otherwise have an appropriate label. More...
|
|
virtual const UnicodeString & | getUnderflowLabel () const |
| Get the special label used for items that sort before the first normal label, and that would not otherwise have an appropriate label. More...
|
|
virtual AlphabeticIndex & | setUnderflowLabel (const UnicodeString &underflowLabel, UErrorCode &status) |
| Set the label used for items that sort before the first normal label, and that would not otherwise have an appropriate label. More...
|
|
virtual int32_t | getMaxLabelCount () const |
| Get the limit on the number of labels permitted in the index. More...
|
|
virtual AlphabeticIndex & | setMaxLabelCount (int32_t maxLabelCount, UErrorCode &status) |
| Set a limit on the number of labels permitted in the index. More...
|
|
virtual AlphabeticIndex & | addRecord (const UnicodeString &name, const void *data, UErrorCode &status) |
| Add a record to the index. More...
|
|
virtual AlphabeticIndex & | clearRecords (UErrorCode &status) |
| Remove all Records from the Index. More...
|
|
virtual int32_t | getBucketCount (UErrorCode &status) |
| Get the number of labels in this index. More...
|
|
virtual int32_t | getRecordCount (UErrorCode &status) |
| Get the total number of Records in this index, that is, the number of <name, data> pairs added. More...
|
|
virtual int32_t | getBucketIndex (const UnicodeString &itemName, UErrorCode &status) |
| Given the name of a record, return the zero-based index of the Bucket in which the item should appear. More...
|
|
virtual int32_t | getBucketIndex () const |
| Get the zero based index of the current Bucket from an iteration over the Buckets of this index. More...
|
|
virtual UBool | nextBucket (UErrorCode &status) |
| Advance the iteration over the Buckets of this index. More...
|
|
virtual const UnicodeString & | getBucketLabel () const |
| Return the name of the Label of the current bucket from an iteration over the buckets. More...
|
|
virtual UAlphabeticIndexLabelType | getBucketLabelType () const |
| Return the type of the label for the current Bucket (selected by the iteration over Buckets.) More...
|
|
virtual int32_t | getBucketRecordCount () const |
| Get the number of <name, data> Records in the current Bucket. More...
|
|
virtual AlphabeticIndex & | resetBucketIterator (UErrorCode &status) |
| Reset the Bucket iteration for this index. More...
|
|
virtual UBool | nextRecord (UErrorCode &status) |
| Advance to the next record in the current Bucket. More...
|
|
virtual const UnicodeString & | getRecordName () const |
| Get the name of the current Record. More...
|
|
virtual const void * | getRecordData () const |
| Return the data pointer of the Record currently being iterated over. More...
|
|
virtual AlphabeticIndex & | resetRecordIterator () |
| Reset the Record iterator position to before the first Record in the current Bucket. More...
|
|
virtual | ~UObject () |
| Destructor. More...
|
|
virtual UClassID | getDynamicClassID () const |
| ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More...
|
|
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:
... 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 ...
A
Addison
Albertson
Azensky
B
Baker
...
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.
The AlphabeticIndex class is not intended for public subclassing.
Note: 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(Locale::getEnglish(), status).
Direct Use
The following shows an example of building an index directly. The "show..." methods below are just to illustrate usage.
// Create a simple index. "Item" is assumed to be an application
// defined type that the application's UI and other processing knows about,
// and that has a name.
UErrorCode status = U_ZERO_ERROR;
AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
index->addLabels(additionalLocale, status);
for (Item *item in some source of Items ) {
index->addRecord(item->name(), item, status);
}
...
// Show index at top. We could skip or gray out empty buckets
while (index->nextBucket(status)) {
if (showAll || index->getBucketRecordCount() != 0) {
showLabelAtTop(UI, index->getBucketLabel());
}
}
...
// Show the buckets with their contents, skipping empty buckets
index->resetBucketIterator(status);
while (index->nextBucket(status)) {
if (index->getBucketRecordCount() != 0) {
showLabelInList(UI, index->getBucketLabel());
while (index->nextRecord(status)) {
showIndexedItem(UI, static_cast<Item *>(index->getRecordData()))
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:
... A-F G-N O-Z ...
Client Support
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.
-
ImmutableIndex.getBucket(index) provides random access to all buckets and their labels and label types.
-
The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1) can be used to get a list of the labels, such as "...", "A", "B",..., and send that list to the client.
-
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.
int32_t bucketIndex = index.getBucketIndex(name, status);
const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional
int32_t skLength = collator.getSortKey(name, sk, skCapacity);
-
The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a sequence of bytes that can be compared with a binary compare, and produce the right localized result.
- Stable:
- ICU 4.8
Definition at line 189 of file alphaindex.h.