|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ibm.icu.text.AlphabeticIndex<V>
public final class AlphabeticIndex<V>
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 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 AlphabeticIndexThe 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:index = new AlphabeticIndex (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 bucket : index) { if (showAll || bucket.size() != 0) { showLabelAtTop(UI, bucket.getLabel()); } } ... // Show the buckets with their contents, skipping empty buckets for (AlphabeticIndex.Bucket bucket : index) { if (bucket.size() != 0) { showLabelInList(UI, bucket.getLabel()); for (AlphabeticIndex.Record item : bucket) { showIndexedItem(UI, item.getName(), item.getData()); }
... A-F G-N O-Z ...
Callers can also use the AlphabeticIndex to support sorting on a client that doesn't support collation.
int bucketIndex = alphabeticIndex.getBucketIndex(name); RawCollationKey collationKey = collator.getRawCollationKey(name, null);
Notes:
Nested Class Summary | |
---|---|
static class |
AlphabeticIndex.Bucket<V>
A "bucket", containing records sorted under an index string by getIndexBucketCharacters. |
static class |
AlphabeticIndex.Record<V>
A record to be sorted into buckets with getIndexBucketCharacters. |
Constructor Summary | |
---|---|
AlphabeticIndex(Locale locale)
Create the index object. |
|
AlphabeticIndex(ULocale locale)
Create the index object. |
|
AlphabeticIndex(ULocale locale,
RuleBasedCollator collator,
UnicodeSet exemplarChars)
Deprecated. This API is ICU internal only, for testing purposes and use with CLDR. |
Method Summary | |
---|---|
AlphabeticIndex<V> |
addLabels(Locale... additions)
Add more index characters (aside from what are in the locale) |
AlphabeticIndex<V> |
addLabels(ULocale... additions)
Add more index characters (aside from what are in the locale) |
AlphabeticIndex<V> |
addLabels(UnicodeSet additions)
Add more index characters (aside from what are in the locale) |
AlphabeticIndex<V> |
addRecord(CharSequence name,
V data)
Add a record (name and data) to the index. |
AlphabeticIndex<V> |
clearRecords()
Clear the index. |
Map<String,Set<String>> |
getAlreadyIn()
Deprecated. This API is ICU internal only. |
int |
getBucketCount()
Return the number of buckets in the index. |
int |
getBucketIndex(CharSequence name)
Get the bucket number for the given name. |
List<String> |
getBucketLabels()
Get the labels. |
RuleBasedCollator |
getCollator()
Get a clone of the collator used internally. |
static List<String> |
getFirstCharactersInScripts()
Deprecated. only for internal testing |
List<String> |
getFirstScriptCharacters()
Deprecated. This API is ICU internal only. |
String |
getInflowLabel()
Get the default label used for abbreviated buckets between other labels. |
int |
getMaxLabelCount()
Get the limit on the number of labels in the index. |
List<String> |
getNoDistinctSorting()
Deprecated. This API is ICU internal only. |
List<String> |
getNotAlphabetic()
Deprecated. This API is ICU internal only. |
String |
getOverflowComparisonString(String lowerLimit)
Deprecated. This API is ICU internal only. |
String |
getOverflowLabel()
Get the default label used in the IndexCharacters' locale for overflow, eg the first item in: ... |
int |
getRecordCount()
Return the number of records in the index: that is, the total number of distinct |
String |
getUnderflowLabel()
Get the default label used in the IndexCharacters' locale for underflow, eg the last item in: X Y Z ... |
Iterator<AlphabeticIndex.Bucket<V>> |
iterator()
Return an iterator over the buckets. |
AlphabeticIndex<V> |
setInflowLabel(String inflowLabel)
Set the inflowLabel label |
AlphabeticIndex<V> |
setMaxLabelCount(int maxLabelCount)
Set a limit on the number of labels in the index. |
AlphabeticIndex<V> |
setOverflowLabel(String overflowLabel)
Set the overflow label |
AlphabeticIndex<V> |
setUnderflowLabel(String underflowLabel)
Set the underflowLabel label |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AlphabeticIndex(ULocale locale)
locale
- The locale for the index.public AlphabeticIndex(Locale locale)
locale
- The locale for the index.public AlphabeticIndex(ULocale locale, RuleBasedCollator collator, UnicodeSet exemplarChars)
Method Detail |
---|
public AlphabeticIndex<V> addLabels(UnicodeSet additions)
additions
- additional characters to add to the index, such as A-Z.
public AlphabeticIndex<V> addLabels(ULocale... additions)
additions
- additional characters to add to the index, such as those in Swedish.
public AlphabeticIndex<V> addLabels(Locale... additions)
additions
- additional characters to add to the index, such as those in Swedish.
public AlphabeticIndex<V> setOverflowLabel(String overflowLabel)
overflowLabel
- see class description
public String getUnderflowLabel()
public AlphabeticIndex<V> setUnderflowLabel(String underflowLabel)
underflowLabel
- see class description
public String getOverflowLabel()
public AlphabeticIndex<V> setInflowLabel(String inflowLabel)
inflowLabel
- see class description
public String getInflowLabel()
public int getMaxLabelCount()
public AlphabeticIndex<V> setMaxLabelCount(int maxLabelCount)
public List<String> getBucketLabels()
public RuleBasedCollator getCollator()
Don't use this method across threads if you are changing the settings on the collator, at least not without synchronizing.
public AlphabeticIndex<V> addRecord(CharSequence name, V data)
name
- Name, such as a namedata
- Data, such as an address or link
public int getBucketIndex(CharSequence name)
Note that the bucket number (and sort key) are only valid for the settings of the current AlphabeticIndex; if those are changed, then the bucket number and sort key must be regenerated.
name
- Name, such as a name
public AlphabeticIndex<V> clearRecords()
public int getBucketCount()
public int getRecordCount()
public Iterator<AlphabeticIndex.Bucket<V>> iterator()
iterator
in interface Iterable<AlphabeticIndex.Bucket<V>>
public String getOverflowComparisonString(String lowerLimit)
lowerLimit
- The character below the overflow (or inflow) bucket
public List<String> getFirstScriptCharacters()
public Map<String,Set<String>> getAlreadyIn()
public List<String> getNoDistinctSorting()
public List<String> getNotAlphabetic()
public static List<String> getFirstCharactersInScripts()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |