ICU 4.8.1.1  4.8.1.1
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields
AlphabeticIndex Class Reference

class AlphabeticIndex supports the creation of a UI index appropriate for a given language, such as: More...

#include <alphaindex.h>

Inheritance diagram for AlphabeticIndex:
UObject UMemory

Data Structures

struct  Bucket
 A Bucket holds an index label and references to everything belonging to that label. More...
struct  Record
 A record, or item, in the index. More...

Public Types

enum  ELangType { kNormal, kSimplified, kTraditional }
 Language Types. More...

Public Member Functions

 AlphabeticIndex (const Locale &locale, UErrorCode &status)
 Construct an AlphabeticIndex object for the specified locale.
virtual AlphabeticIndexaddLabels (const UnicodeSet &additions, UErrorCode &status)
 Add Labels to this Index.
virtual AlphabeticIndexaddLabels (const Locale &locale, UErrorCode &status)
 Add the index characters from a Locale to the index.
virtual ~AlphabeticIndex ()
 Destructor.
virtual const RuleBasedCollatorgetCollator () const
 Get the Collator that establishes the ordering of the items in this index.
virtual const UnicodeStringgetInflowLabel () const
 Get the default label used for abbreviated buckets between other index characters.
virtual AlphabeticIndexsetInflowLabel (const UnicodeString &inflowLabel, UErrorCode &status)
 Set the default label used for abbreviated buckets between other index characters.
virtual const UnicodeStringgetOverflowLabel () const
 Get the special label used for items that sort after the last normal label, and that would not otherwise have an appropriate label.
virtual AlphabeticIndexsetOverflowLabel (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.
virtual const UnicodeStringgetUnderflowLabel () const
 Get the special label used for items that sort before the first normal label, and that would not otherwise have an appropriate label.
virtual AlphabeticIndexsetUnderflowLabel (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.
virtual int32_t getMaxLabelCount () const
 Get the limit on the number of labels permitted in the index.
virtual AlphabeticIndexsetMaxLabelCount (int32_t maxLabelCount, UErrorCode &status)
 Set a limit on the number of labels permitted in the index.
virtual const UnicodeStringgetOverflowComparisonString (const UnicodeString &lowerLimit, UErrorCode &status)
 Get the Unicode character (or tailored string) that defines an overflow bucket; that is anything greater than or equal to that string should go in that bucket, instead of with the last character.
virtual AlphabeticIndexaddRecord (const UnicodeString &name, const void *data, UErrorCode &status)
 Add a record to the index.
virtual AlphabeticIndexclearRecords (UErrorCode &status)
 Remove all Records from the Index.
virtual int32_t getBucketCount (UErrorCode &status)
 Get the number of labels in this index.
virtual int32_t getRecordCount (UErrorCode &status)
 Get the total number of Records in this index, that is, the number of <name, data> pairs added.
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.
virtual int32_t getBucketIndex () const
 Get the zero based index of the current Bucket from an iteration over the Buckets of this index.
virtual UBool nextBucket (UErrorCode &status)
 Advance the iteration over the Buckets of this index.
virtual const UnicodeStringgetBucketLabel () const
 Return the name of the Label of the current bucket from an iteration over the buckets.
virtual UAlphabeticIndexLabelType getBucketLabelType () const
 Return the type of the label for the current Bucket (selected by the iteration over Buckets.)
virtual int32_t getBucketRecordCount () const
 Get the number of <name, data> Records in the current Bucket.
virtual AlphabeticIndexresetBucketIterator (UErrorCode &status)
 Reset the Bucket iteration for this index.
virtual UBool nextRecord (UErrorCode &status)
 Advance to the next record in the current Bucket.
virtual const UnicodeStringgetRecordName () const
 Get the name of the current Record.
virtual const void * getRecordData () const
 Return the data pointer of the Record currently being iterated over.
virtual AlphabeticIndexresetRecordIterator ()
 Reset the Record iterator position to before the first Record in the current Bucket.

Static Public Member Functions

static void staticCleanup ()
 Delete all shared (static) data associated with an AlphabeticIndex.
static ELangType langTypeFromLocale (const Locale &loc)
 Get the Language Type for this Index.

Data Fields

UVector * inputRecords_
 Holds all user records before they are distributed into buckets.

Detailed Description

class AlphabeticIndex supports the creation of a UI index appropriate for a given language, such as:

  ... 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 \u00C6 \u00D8 \u00C5 ...
  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.

Example

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

Notes:

Draft:
This API may be changed in the future versions and was introduced in ICU 4.8 This API might change or be removed in a future release.

Definition at line 163 of file alphaindex.h.


Member Enumeration Documentation

Language Types.

For internal ICU use only.

Internal:
Do not use. This API is for internal use only.
Enumerator:
kNormal 
Internal:
Do not use.

This API is for internal use only.

kSimplified 
Internal:
Do not use.

This API is for internal use only.

kTraditional 
Internal:
Do not use.

This API is for internal use only.

Definition at line 622 of file alphaindex.h.


Constructor & Destructor Documentation

AlphabeticIndex::AlphabeticIndex ( const Locale locale,
UErrorCode status 
)

Construct an AlphabeticIndex object for the specified locale.

If the locale's data does not include index characters, a set of them will be synthesized based on the locale's exemplar characters. The locale determines the sorting order for both the index characters and the user item names appearing under each Index character.

Parameters:
localethe desired locale.
statusError code, will be set with the reason if the construction of the AlphabeticIndex object fails.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex::~AlphabeticIndex ( ) [virtual]

Destructor.

Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Member Function Documentation

virtual AlphabeticIndex& AlphabeticIndex::addLabels ( const UnicodeSet additions,
UErrorCode status 
) [virtual]

Add Labels to this Index.

The labels are additions to those that are already in the index; they do not replace the existing ones.

Parameters:
additionsThe additional characters to add to the index, such as A-Z.
statusError code, will be set with the reason if the operation fails.
Returns:
this, for chaining
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::addLabels ( const Locale locale,
UErrorCode status 
) [virtual]

Add the index characters from a Locale to the index.

The labels are added to those that are already in the index; they do not replace the existing index characters. The collation order for this index is not changed; it remains that of the locale that was originally specified when creating this Index.

Parameters:
localeThe locale whose index characters are to be added.
statusError code, will be set with the reason if the operation fails.
Returns:
this, for chaining
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::addRecord ( const UnicodeString name,
const void *  data,
UErrorCode status 
) [virtual]

Add a record to the index.

Each record will be associated with an index Bucket based on the record's name. The list of records for each bucket will be sorted based on the collation ordering of the names in the index's locale. Records with duplicate names are permitted; they will be kept in the order that they were added.

Parameters:
nameThe display name for the Record. The Record will be placed in a bucket based on this name.
dataAn optional pointer to user data associated with this item. When iterating the contents of a bucket, both the data pointer the name will be available for each Record.
statusError code, will be set with the reason if the operation fails.
Returns:
This, for chaining.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::clearRecords ( UErrorCode status) [virtual]

Remove all Records from the Index.

The set of Buckets, which define the headings under which records are classified, is not altered.

Parameters:
statusError code, will be set with the reason if the operation fails.
Returns:
This, for chaining.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getBucketCount ( UErrorCode status) [virtual]

Get the number of labels in this index.

Note: may trigger lazy index construction.

Parameters:
statusError code, will be set with the reason if the operation fails.
Returns:
The number of labels in this index, including any under, over or in-flow labels.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getBucketIndex ( const UnicodeString itemName,
UErrorCode status 
) [virtual]

Given the name of a record, return the zero-based index of the Bucket in which the item should appear.

The name need not be in the index. A Record will not be added to the index by this function. Bucket numbers are zero-based, in Bucket iteration order.

Parameters:
itemNameThe name whose bucket position in the index is to be determined.
statusError code, will be set with the reason if the operation fails.
Returns:
The bucket number for this name.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getBucketIndex ( ) const [virtual]

Get the zero based index of the current Bucket from an iteration over the Buckets of this index.

Return -1 if no iteration is in process.

Returns:
the index of the current Bucket
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const UnicodeString& AlphabeticIndex::getBucketLabel ( ) const [virtual]

Return the name of the Label of the current bucket from an iteration over the buckets.

If the iteration is before the first Bucket (nextBucket() has not been called), or after the last, return an empty string.

Returns:
the bucket label.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Return the type of the label for the current Bucket (selected by the iteration over Buckets.)

Returns:
the label type.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getBucketRecordCount ( ) const [virtual]

Get the number of <name, data> Records in the current Bucket.

If the current bucket iteration position is before the first label or after the last, return 0.

Returns:
the number of Records.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const RuleBasedCollator& AlphabeticIndex::getCollator ( ) const [virtual]

Get the Collator that establishes the ordering of the items in this index.

Ownership of the collator remains with the AlphabeticIndex instance.

The returned collator is a reference to the internal collator used by this index. It may be safely used to compare the names of items or to get sort keys for names. However if any settings need to be changed, or other non-const methods called, a cloned copy must be made first.

Returns:
The collator
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const UnicodeString& AlphabeticIndex::getInflowLabel ( ) const [virtual]

Get the default label used for abbreviated buckets between other index characters.

For example, consider the labels when Latin and Greek are used: X Y Z ... &#x0391; &#x0392; &#x0393;.

Returns:
inflow label
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getMaxLabelCount ( ) const [virtual]

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

The number does not include over, under and inflow labels.

Returns:
maxLabelCount maximum number of labels.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const UnicodeString& AlphabeticIndex::getOverflowComparisonString ( const UnicodeString lowerLimit,
UErrorCode status 
) [virtual]

Get the Unicode character (or tailored string) that defines an overflow bucket; that is anything greater than or equal to that string should go in that bucket, instead of with the last character.

Normally that is the first character of the script after lowerLimit. Thus in X Y Z ... Devanagari-ka, the overflow character for Z would be the Greek-alpha.

Parameters:
lowerLimitThe character below the overflow (or inflow) bucket
statuserror code
Returns:
string that defines top of the overflow buck for lowerLimit, or an empty string if there is none
Internal:
Do not use. This API is for internal use only.
virtual const UnicodeString& AlphabeticIndex::getOverflowLabel ( ) const [virtual]

Get the special label used for items that sort after the last normal label, and that would not otherwise have an appropriate label.

Returns:
the overflow label
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual int32_t AlphabeticIndex::getRecordCount ( UErrorCode status) [virtual]

Get the total number of Records in this index, that is, the number of <name, data> pairs added.

Parameters:
statusError code, will be set with the reason if the operation fails.
Returns:
The number of records in this index, that is, the total number of (name, data) items added with addRecord().
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const void* AlphabeticIndex::getRecordData ( ) const [virtual]

Return the data pointer of the Record currently being iterated over.

Return NULL if the current iteration position before the first item in this Bucket, or after the last.

Returns:
The current Record's data pointer.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const UnicodeString& AlphabeticIndex::getRecordName ( ) const [virtual]

Get the name of the current Record.

Return an empty string if the Record iteration position is before first or after the last.

Returns:
The name of the current index item.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual const UnicodeString& AlphabeticIndex::getUnderflowLabel ( ) const [virtual]

Get the special label used for items that sort before the first normal label, and that would not otherwise have an appropriate label.

Returns:
underflow label
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
static ELangType AlphabeticIndex::langTypeFromLocale ( const Locale loc) [static]

Get the Language Type for this Index.

Based on the locale.

Internal:
Do not use. This API is for internal use only.
virtual UBool AlphabeticIndex::nextBucket ( UErrorCode status) [virtual]

Advance the iteration over the Buckets of this index.

Return FALSE if there are no more Buckets.

Parameters:
statusError code, will be set with the reason if the operation fails. U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while an enumeration of its contents are in process.
Returns:
TRUE if success, FALSE if at end of iteration
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual UBool AlphabeticIndex::nextRecord ( UErrorCode status) [virtual]

Advance to the next record in the current Bucket.

When nextBucket() is called, Record iteration is reset to just before the first Record in the new Bucket.

Parameters:
statusError code, will be set with the reason if the operation fails. U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while an enumeration of its contents are in process.
Returns:
TRUE if successful, FALSE when the iteration advances past the last item.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Reset the Bucket iteration for this index.

The next call to nextBucket() will restart the iteration at the first label.

Parameters:
statusError code, will be set with the reason if the operation fails.
Returns:
this, for chaining.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8

Reset the Record iterator position to before the first Record in the current Bucket.

Returns:
This, for chaining.
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::setInflowLabel ( const UnicodeString inflowLabel,
UErrorCode status 
) [virtual]

Set the default label used for abbreviated buckets between other index characters.

An inflow label will be automatically inserted if two otherwise-adjacent label characters are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek, sorts between the two. The default inflow character is an ellipsis (...)

Parameters:
inflowLabelthe new Inflow label.
statusError code, will be set with the reason if the operation fails.
Returns:
this
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::setMaxLabelCount ( int32_t  maxLabelCount,
UErrorCode status 
) [virtual]

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

The number does not include over, under and inflow labels. Currently, if the number is exceeded, then every nth item is removed to bring the count down. A more sophisticated mechanism may be available in the future.

Parameters:
maxLabelCountthe maximum number of labels.
statuserror code
Returns:
This, for chaining
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::setOverflowLabel ( const UnicodeString overflowLabel,
UErrorCode status 
) [virtual]

Set the label used for items that sort after the last normal label, and that would not otherwise have an appropriate label.

Parameters:
overflowLabelthe new overflow label.
statusError code, will be set with the reason if the operation fails.
Returns:
this
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
virtual AlphabeticIndex& AlphabeticIndex::setUnderflowLabel ( const UnicodeString underflowLabel,
UErrorCode status 
) [virtual]

Set the label used for items that sort before the first normal label, and that would not otherwise have an appropriate label.

Parameters:
underflowLabelthe new underflow label.
statusError code, will be set with the reason if the operation fails.
Returns:
this
Draft:
This API may be changed in the future versions and was introduced in ICU 4.8
static void AlphabeticIndex::staticCleanup ( ) [static]

Delete all shared (static) data associated with an AlphabeticIndex.

Internal function, not intended for direct use.

Internal:
Do not use. This API is for internal use only..

Field Documentation

Holds all user records before they are distributed into buckets.

Type of contents is (Record *)

Internal:
Do not use. This API is for internal use only.

Definition at line 597 of file alphaindex.h.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines