92 * ... 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 ... 93 * 94 * A 95 * Addison 96 * Albertson 97 * Azensky 98 * B 99 * Baker 100 * ... 101 *
110 * The class also supports having buckets for strings before the first (underflow), 111 * after the last (overflow), and between scripts (inflow). For example, if the index 112 * is constructed with labels for Russian and English, Greek characters would fall 113 * into an inflow bucket between the other two scripts. 114 *
115 * The AlphabeticIndex class is not intended for public subclassing. 116 * 117 *
Note: If you expect to have a lot of ASCII or Latin characters 118 * as well as characters from the user's language, 119 * then it is a good idea to call addLabels(Locale::getEnglish(), status).
The following shows an example of building an index directly. 123 * The "show..." methods below are just to illustrate usage. 124 * 125 *
126 * // Create a simple index. "Item" is assumed to be an application 127 * // defined type that the application's UI and other processing knows about, 128 * // and that has a name. 129 * 130 * UErrorCode status = U_ZERO_ERROR; 131 * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status); 132 * index->addLabels(additionalLocale, status); 133 * for (Item *item in some source of Items ) { 134 * index->addRecord(item->name(), item, status); 135 * } 136 * ... 137 * // Show index at top. We could skip or gray out empty buckets 138 * 139 * while (index->nextBucket(status)) { 140 * if (showAll || index->getBucketRecordCount() != 0) { 141 * showLabelAtTop(UI, index->getBucketLabel()); 142 * } 143 * } 144 * ... 145 * // Show the buckets with their contents, skipping empty buckets 146 * 147 * index->resetBucketIterator(status); 148 * while (index->nextBucket(status)) { 149 * if (index->getBucketRecordCount() != 0) { 150 * showLabelInList(UI, index->getBucketLabel()); 151 * while (index->nextRecord(status)) { 152 * showIndexedItem(UI, static_cast(index->getRecordData())) 153 *
160 * ... A-F G-N O-Z ... 161 *
Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself, 165 * to support sorting on a client that doesn't support AlphabeticIndex functionality. 166 * 167 *
The ImmutableIndex is both immutable and thread-safe. 168 * The corresponding AlphabeticIndex methods are not thread-safe because 169 * they "lazily" build the index buckets. 170 *
181 * int32_t bucketIndex = index.getBucketIndex(name, status); 182 * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional 183 * int32_t skLength = collator.getSortKey(name, sk, skCapacity); 184 *