... 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
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.
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(ULocale.English).
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<Integer> index = new AlphabeticIndex<Integer>(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<Integer> bucket : index) {
if (showAll || bucket.size() != 0) {
showLabelAtTop(UI, bucket.getLabel());
}
}
...
// Show the buckets with their contents, skipping empty buckets
for (AlphabeticIndex.Bucket<Integer> bucket : index) {
if (bucket.size() != 0) {
showLabelInList(UI, bucket.getLabel());
for (AlphabeticIndex.Record<Integer> 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:
... A-F G-N O-Z ...
Callers can also use the AlphabeticIndex., 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.
int bucketIndex = index.getBucketIndex(name); String label = immutableIndex.getBucket(bucketIndex).getLabel(); // optional RawCollationKey collationKey = collator.getRawCollationKey(name, null);
| Modifier and Type | Class and Description |
|---|---|
| public static class | |
| private static class | |
| public static class | AlphabeticIndex.ImmutableIndex<
The Record value type is unused. It can be omitted for this class
if it was omitted for the AlphabeticIndex that built it. V>Immutable, thread-safe version of |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | BASE
Prefix string for Chinese index buckets. |
| private static final Comparator | |
| private AlphabeticIndex. | |
| private static final char | |
| private RuleBasedCollator | |
| private final RuleBasedCollator | |
| private final RuleBasedCollator | |
| private final List | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private String | |
| private final UnicodeSet | |
| private List | |
| private int | |
| private String | |
| private final Comparator | |
| private String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | AlphabeticIndex(RuleBasedCollator
The collator to use to order the contents of this index. collator)Create an AlphabeticIndex that uses a specific collator. |
| private | AlphabeticIndex(ULocale locale, RuleBasedCollator collator)
Internal constructor containing implementation used by public constructors. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private void | |
| public AlphabeticIndex | Returns: this, for chainingadditional characters to add to the index, such as A-Z. additions)Add more index characters (aside from what are in the locale) |
| public AlphabeticIndex | |
| public AlphabeticIndex | |
| public AlphabeticIndex | Returns: this, for chainingName, such as a name name, V Data, such as an address or link data)Add a record (name and data) to the index. |
| public AlphabeticIndex. | Returns: an immutable index instanceBuilds an immutable, thread-safe version of this instance, without data records. |
| public AlphabeticIndex | |
| private AlphabeticIndex. | |
| private static String | |
| public int | |
| public int | Returns: the bucket index for the nameName, such as a name name)Get the bucket number for the given name. |
| public List | |
| public RuleBasedCollator | Returns: a clone of the collator used internallyGet a clone of the collator used internally. |
| public List | Returns: list of first characters in each script
Deprecated
This API is ICU internal, only for testing.
Return a list of the first character in each script.
|
| public String | Returns: inflow labelGet the default label used for abbreviated buckets between other labels. |
| public int | Returns: maxLabelCount maximum number of labels.Get the limit on the number of labels in the index. |
| public String | Returns: overflow labelGet the default label used in the IndexCharacters' locale for overflow, eg the first item in: ... |
| public int | Returns: total number of records in bucketsReturn the number of records in the index: that is, the total number of distinct <name,data> pairs added with addRecord(...), over all the buckets. |
| public String | Returns: underflow labelGet the default label used in the IndexCharacters' locale for underflow, eg the last item in: X Y Z ... |
| private static boolean | |
| private void | |
| private List | |
| private static boolean | isOneLabelBetterThanOther(Normalizer2 nfkdNormalizer, String one, String other)
Returns true if one index character string is "better" than the other. |
| public Iterator | Returns: iterator over buckets.Implements java. |
| private String | |
| public AlphabeticIndex | Returns: this, for chainingsee class description inflowLabel)Set the inflowLabel label |
| public AlphabeticIndex | Returns: this, for chainingSet the maximum number of 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. maxLabelCount)Set a limit on the number of labels in the index. |
| public AlphabeticIndex | Returns: this, for chainingsee class description overflowLabel)Set the overflow label |
| public AlphabeticIndex | Returns: this, for chainingsee class description underflowLabel)Set the underflowLabel label |