ICU-9842 Alphabetic Index constructor with collator, ICU4J
X-SVN-Rev: 33146
This commit is contained in:
parent
6d924df20b
commit
f18976290a
@ -245,6 +245,24 @@ public final class AlphabeticIndex<V> implements Iterable<Bucket<V>> {
|
||||
this(ULocale.forLocale(locale));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an AlphabeticIndex that uses a specific collator.
|
||||
*
|
||||
* The index will be created with no labels; the addLabels() function must be called
|
||||
* after creation to add the desired labels to the index.
|
||||
*
|
||||
* The index will work directly with the supplied collator. If the caller will need to
|
||||
* continue working with the collator it should be cloned first, so that the
|
||||
* collator provided to the AlphabeticIndex remains unchanged after creation of the index.
|
||||
*
|
||||
* @param collator The collator to use to order the contents of this index.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
public AlphabeticIndex(RuleBasedCollator collator) {
|
||||
this(null, collator, new UnicodeSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only, for testing purposes and use with CLDR.
|
||||
|
@ -869,8 +869,8 @@ public class AlphabeticIndexTest extends TestFmwk {
|
||||
public void TestHaniFirst() {
|
||||
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
|
||||
coll.setReorderCodes(UScript.HAN);
|
||||
// TODO: Use the new public API that constructs an index from a collator.
|
||||
AlphabeticIndex index = new AlphabeticIndex(ULocale.ROOT, coll, new UnicodeSet());
|
||||
AlphabeticIndex index = new AlphabeticIndex(coll);
|
||||
assertEquals("getBucketCount()", 1, index.getBucketCount()); // ... (underflow only)
|
||||
index.addLabels(ULocale.ENGLISH);
|
||||
assertEquals("getBucketCount()", 28, index.getBucketCount()); // ... A-Z ...
|
||||
int bucketIndex = index.getBucketIndex("\u897f");
|
||||
@ -892,8 +892,9 @@ public class AlphabeticIndexTest extends TestFmwk {
|
||||
public void TestPinyinFirst() {
|
||||
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.CHINESE);
|
||||
coll.setReorderCodes(UScript.HAN);
|
||||
// TODO: Use the new public API that constructs an index from a collator.
|
||||
AlphabeticIndex index = new AlphabeticIndex(ULocale.CHINESE, coll, null);
|
||||
AlphabeticIndex index = new AlphabeticIndex(coll);
|
||||
assertEquals("getBucketCount()", 1, index.getBucketCount()); // ... (underflow only)
|
||||
index.addLabels(ULocale.CHINESE);
|
||||
assertEquals("getBucketCount()", 28, index.getBucketCount()); // ... A-Z ...
|
||||
int bucketIndex = index.getBucketIndex("\u897f");
|
||||
assertEquals("getBucketIndex(U+897F)", 'X' - 'A' + 1, bucketIndex);
|
||||
@ -954,8 +955,7 @@ public class AlphabeticIndexTest extends TestFmwk {
|
||||
*/
|
||||
public void TestNoLabels() {
|
||||
RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
|
||||
// TODO: Use the new public API that constructs an index from a collator.
|
||||
AlphabeticIndex<Integer> index = new AlphabeticIndex<Integer>(ULocale.ROOT, coll, new UnicodeSet());
|
||||
AlphabeticIndex<Integer> index = new AlphabeticIndex<Integer>(coll);
|
||||
index.addRecord("\u897f", 0);
|
||||
index.addRecord("i", 0);
|
||||
index.addRecord("\u03B1", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user