Remove libcore AlphabeticIndex and references. This has
been replaced by ICU4J's library.
Change-Id: I1365a18609b3d5bf45ae8341792a01f4e995f5bb
diff --git a/luni/src/main/java/libcore/icu/AlphabeticIndex.java b/luni/src/main/java/libcore/icu/AlphabeticIndex.java
deleted file mode 100644
index 322384d..0000000
--- a/luni/src/main/java/libcore/icu/AlphabeticIndex.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.icu;
-
-import java.util.Locale;
-
-/**
- * Exposes icu4c's AlphabeticIndex.
- */
-public final class AlphabeticIndex {
-
- /**
- * Exposes icu4c's ImmutableIndex (new to icu 51). This exposes a read-only,
- * thread safe snapshot view of an AlphabeticIndex at the moment it was
- * created, and allows for random access to buckets by index.
- */
- public static final class ImmutableIndex {
- private long peer;
-
- private ImmutableIndex(long peer) {
- this.peer = peer;
- }
-
- @Override protected synchronized void finalize() throws Throwable {
- try {
- destroy(peer);
- peer = 0;
- } finally {
- super.finalize();
- }
- }
-
- /**
- * Returns the number of the label buckets in this index.
- */
- public int getBucketCount() {
- return getBucketCount(peer);
- }
-
- /**
- * Returns the index of the bucket in which 's' should appear.
- * Function is synchronized because underlying routine walks an iterator
- * whose state is maintained inside the index object.
- */
- public int getBucketIndex(String s) {
- return getBucketIndex(peer, s);
- }
-
- /**
- * Returns the label for the bucket at the given index (as returned by getBucketIndex).
- */
- public String getBucketLabel(int index) {
- return getBucketLabel(peer, index);
- }
-
- private static native int getBucketCount(long peer);
- private static native int getBucketIndex(long peer, String s);
- private static native String getBucketLabel(long peer, int index);
- }
-
- private long peer;
-
- /**
- * Creates a new AlphabeticIndex for the given locale.
- */
- public AlphabeticIndex(Locale locale) {
- peer = create(locale.toString());
- }
-
- @Override protected synchronized void finalize() throws Throwable {
- try {
- destroy(peer);
- peer = 0;
- } finally {
- super.finalize();
- }
- }
-
- /**
- * Returns the max number of the label buckets allowed in this index.
- */
- public synchronized int getMaxLabelCount() {
- return getMaxLabelCount(peer);
- }
-
- /**
- * Sets the max number of the label buckets in this index.
- * (ICU 51 default is 99)
- */
- public synchronized AlphabeticIndex setMaxLabelCount(int count) {
- setMaxLabelCount(peer, count);
- return this;
- }
-
- /**
- * Adds the index characters from the given 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.
- */
- public synchronized AlphabeticIndex addLabels(Locale locale) {
- addLabels(peer, locale.toString());
- return this;
- }
-
- /**
- * Adds the index characters in the range between the specified start and
- * end code points, inclusive.
- */
- public synchronized AlphabeticIndex addLabelRange(int codePointStart, int codePointEnd) {
- addLabelRange(peer, codePointStart, codePointEnd);
- return this;
- }
-
- /**
- * Returns the number of the label buckets in this index.
- */
- public synchronized int getBucketCount() {
- return getBucketCount(peer);
- }
-
- /**
- * Returns the index of the bucket in which 's' should appear.
- * Function is synchronized because underlying routine walks an iterator
- * whose state is maintained inside the index object.
- */
- public synchronized int getBucketIndex(String s) {
- return getBucketIndex(peer, s);
- }
-
- /**
- * Returns the label for the bucket at the given index (as returned by getBucketIndex).
- */
- public synchronized String getBucketLabel(int index) {
- return getBucketLabel(peer, index);
- }
-
- /**
- * Returns an ImmutableIndex created from this AlphabeticIndex.
- */
- public synchronized ImmutableIndex getImmutableIndex() {
- return new ImmutableIndex(buildImmutableIndex(peer));
- }
-
- private static native long create(String locale);
- private static native void destroy(long peer);
- private static native int getMaxLabelCount(long peer);
- private static native void setMaxLabelCount(long peer, int count);
- private static native void addLabels(long peer, String locale);
- private static native void addLabelRange(long peer, int codePointStart, int codePointEnd);
- private static native int getBucketCount(long peer);
- private static native int getBucketIndex(long peer, String s);
- private static native String getBucketLabel(long peer, int index);
- private static native long buildImmutableIndex(long peer);
-}
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 0e30da7..dc002c2 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -55,7 +55,6 @@
REGISTER(register_java_util_zip_CRC32);
REGISTER(register_java_util_zip_Deflater);
REGISTER(register_java_util_zip_Inflater);
- REGISTER(register_libcore_icu_AlphabeticIndex);
REGISTER(register_libcore_icu_ICU);
REGISTER(register_libcore_icu_NativeCollation);
REGISTER(register_libcore_icu_NativeConverter);
diff --git a/luni/src/main/native/libcore_icu_AlphabeticIndex.cpp b/luni/src/main/native/libcore_icu_AlphabeticIndex.cpp
deleted file mode 100644
index acc247b..0000000
--- a/luni/src/main/native/libcore_icu_AlphabeticIndex.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "AlphabeticIndex"
-
-#include "IcuUtilities.h"
-#include "JNIHelp.h"
-#include "JniConstants.h"
-#include "JniException.h"
-#include "ScopedIcuLocale.h"
-#include "ScopedJavaUnicodeString.h"
-#include "unicode/alphaindex.h"
-#include "unicode/uniset.h"
-
-static icu::AlphabeticIndex* fromPeer(jlong peer) {
- return reinterpret_cast<icu::AlphabeticIndex*>(static_cast<uintptr_t>(peer));
-}
-
-static jlong AlphabeticIndex_create(JNIEnv* env, jclass, jstring javaLocaleName) {
- UErrorCode status = U_ZERO_ERROR;
- ScopedIcuLocale icuLocale(env, javaLocaleName);
- if (!icuLocale.valid()) {
- return 0;
- }
- icu::AlphabeticIndex* ai = new icu::AlphabeticIndex(icuLocale.locale(), status);
- if (maybeThrowIcuException(env, "AlphabeticIndex", status)) {
- return 0;
- }
- return reinterpret_cast<uintptr_t>(ai);
-}
-
-static void AlphabeticIndex_destroy(JNIEnv*, jclass, jlong peer) {
- delete fromPeer(peer);
-}
-
-static jint AlphabeticIndex_getMaxLabelCount(JNIEnv*, jclass, jlong peer) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- return ai->getMaxLabelCount();
-}
-
-static void AlphabeticIndex_setMaxLabelCount(JNIEnv* env, jclass, jlong peer, jint count) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- UErrorCode status = U_ZERO_ERROR;
- ai->setMaxLabelCount(count, status);
- maybeThrowIcuException(env, "AlphabeticIndex::setMaxLabelCount", status);
-}
-
-static void AlphabeticIndex_addLabels(JNIEnv* env, jclass, jlong peer, jstring javaLocaleName) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- ScopedIcuLocale icuLocale(env, javaLocaleName);
- if (!icuLocale.valid()) {
- return;
- }
- UErrorCode status = U_ZERO_ERROR;
- ai->addLabels(icuLocale.locale(), status);
- maybeThrowIcuException(env, "AlphabeticIndex::addLabels", status);
-}
-
-static void AlphabeticIndex_addLabelRange(JNIEnv* env, jclass, jlong peer,
- jint codePointStart, jint codePointEnd) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- UErrorCode status = U_ZERO_ERROR;
- ai->addLabels(icu::UnicodeSet(codePointStart, codePointEnd), status);
- maybeThrowIcuException(env, "AlphabeticIndex::addLabels", status);
-}
-
-static jint AlphabeticIndex_getBucketCount(JNIEnv* env, jclass, jlong peer) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- UErrorCode status = U_ZERO_ERROR;
- jint result = ai->getBucketCount(status);
- if (maybeThrowIcuException(env, "AlphabeticIndex::getBucketCount", status)) {
- return -1;
- }
- return result;
-}
-
-static jint AlphabeticIndex_getBucketIndex(JNIEnv* env, jclass, jlong peer, jstring javaString) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- ScopedJavaUnicodeString string(env, javaString);
- if (!string.valid()) {
- return -1;
- }
- UErrorCode status = U_ZERO_ERROR;
- jint result = ai->getBucketIndex(string.unicodeString(), status);
- if (maybeThrowIcuException(env, "AlphabeticIndex::getBucketIndex", status)) {
- return -1;
- }
- return result;
-}
-
-static jstring AlphabeticIndex_getBucketLabel(JNIEnv* env, jclass, jlong peer, jint index) {
- if (index < 0) {
- jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Invalid index: %d", index);
- return NULL;
- }
-
- // Iterate to the nth bucket.
- icu::AlphabeticIndex* ai = fromPeer(peer);
- UErrorCode status = U_ZERO_ERROR;
- ai->resetBucketIterator(status);
- if (maybeThrowIcuException(env, "AlphabeticIndex::resetBucketIterator", status)) {
- return NULL;
- }
- for (jint i = 0; i <= index; ++i) {
- if (!ai->nextBucket(status)) {
- jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Invalid index: %d", index);
- return NULL;
- }
- if (maybeThrowIcuException(env, "AlphabeticIndex::nextBucket", status)) {
- return NULL;
- }
- }
-
- // Return "" for the underflow/inflow/overflow buckets.
- if (ai->getBucketLabelType() != U_ALPHAINDEX_NORMAL) {
- return env->NewStringUTF("");
- }
-
- const icu::UnicodeString& label(ai->getBucketLabel());
- return env->NewString(label.getBuffer(), label.length());
-}
-
-static jlong AlphabeticIndex_buildImmutableIndex(JNIEnv* env, jclass, jlong peer) {
- icu::AlphabeticIndex* ai = fromPeer(peer);
- UErrorCode status = U_ZERO_ERROR;
- icu::AlphabeticIndex::ImmutableIndex* ii = ai->buildImmutableIndex(status);
- if (maybeThrowIcuException(env, "AlphabeticIndex::buildImmutableIndex", status)) {
- return 0;
- }
- return reinterpret_cast<uintptr_t>(ii);
-}
-
-static icu::AlphabeticIndex::ImmutableIndex* immutableIndexFromPeer(jlong peer) {
- return reinterpret_cast<icu::AlphabeticIndex::ImmutableIndex*>(static_cast<uintptr_t>(peer));
-}
-
-static jint ImmutableIndex_getBucketCount(JNIEnv*, jclass, jlong peer) {
- icu::AlphabeticIndex::ImmutableIndex* ii = immutableIndexFromPeer(peer);
- return ii->getBucketCount();
-}
-
-static jint ImmutableIndex_getBucketIndex(JNIEnv* env, jclass, jlong peer, jstring javaString) {
- icu::AlphabeticIndex::ImmutableIndex* ii = immutableIndexFromPeer(peer);
- ScopedJavaUnicodeString string(env, javaString);
- if (!string.valid()) {
- return -1;
- }
- UErrorCode status = U_ZERO_ERROR;
- jint result = ii->getBucketIndex(string.unicodeString(), status);
- if (maybeThrowIcuException(env, "AlphabeticIndex::ImmutableIndex::getBucketIndex", status)) {
- return -1;
- }
- return result;
-}
-
-static jstring ImmutableIndex_getBucketLabel(JNIEnv* env, jclass, jlong peer, jint index) {
- icu::AlphabeticIndex::ImmutableIndex* ii = immutableIndexFromPeer(peer);
- const icu::AlphabeticIndex::Bucket* bucket = ii->getBucket(index);
- if (bucket == NULL) {
- jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Invalid index: %d", index);
- return NULL;
- }
-
- // Return "" for the underflow/inflow/overflow buckets.
- if (bucket->getLabelType() != U_ALPHAINDEX_NORMAL) {
- return env->NewStringUTF("");
- }
-
- const icu::UnicodeString& label(bucket->getLabel());
- return env->NewString(label.getBuffer(), label.length());
-}
-
-static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(AlphabeticIndex, create, "(Ljava/lang/String;)J"),
- NATIVE_METHOD(AlphabeticIndex, destroy, "(J)V"),
- NATIVE_METHOD(AlphabeticIndex, getMaxLabelCount, "(J)I"),
- NATIVE_METHOD(AlphabeticIndex, setMaxLabelCount, "(JI)V"),
- NATIVE_METHOD(AlphabeticIndex, addLabels, "(JLjava/lang/String;)V"),
- NATIVE_METHOD(AlphabeticIndex, addLabelRange, "(JII)V"),
- NATIVE_METHOD(AlphabeticIndex, getBucketCount, "(J)I"),
- NATIVE_METHOD(AlphabeticIndex, getBucketIndex, "(JLjava/lang/String;)I"),
- NATIVE_METHOD(AlphabeticIndex, getBucketLabel, "(JI)Ljava/lang/String;"),
- NATIVE_METHOD(AlphabeticIndex, buildImmutableIndex, "(J)J"),
-};
-static JNINativeMethod gImmutableIndexMethods[] = {
- NATIVE_METHOD(ImmutableIndex, getBucketCount, "(J)I"),
- NATIVE_METHOD(ImmutableIndex, getBucketIndex, "(JLjava/lang/String;)I"),
- NATIVE_METHOD(ImmutableIndex, getBucketLabel, "(JI)Ljava/lang/String;"),
-};
-void register_libcore_icu_AlphabeticIndex(JNIEnv* env) {
- jniRegisterNativeMethods(env, "libcore/icu/AlphabeticIndex", gMethods, NELEM(gMethods));
- jniRegisterNativeMethods(env, "libcore/icu/AlphabeticIndex$ImmutableIndex", gImmutableIndexMethods, NELEM(gImmutableIndexMethods));
-}
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index ec39596..45bafbb 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -35,7 +35,6 @@
java_util_zip_CRC32.cpp \
java_util_zip_Deflater.cpp \
java_util_zip_Inflater.cpp \
- libcore_icu_AlphabeticIndex.cpp \
libcore_icu_ICU.cpp \
libcore_icu_NativeCollation.cpp \
libcore_icu_NativeConverter.cpp \
diff --git a/luni/src/test/java/libcore/icu/AlphabeticIndexTest.java b/luni/src/test/java/libcore/icu/AlphabeticIndexTest.java
deleted file mode 100644
index 6c7452d..0000000
--- a/luni/src/test/java/libcore/icu/AlphabeticIndexTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.icu;
-
-import java.util.Locale;
-
-public class AlphabeticIndexTest extends junit.framework.TestCase {
- private static AlphabeticIndex.ImmutableIndex createIndex(Locale locale) {
- return new AlphabeticIndex(locale).addLabels(Locale.US).getImmutableIndex();
- }
-
- private static void assertHasLabel(AlphabeticIndex.ImmutableIndex ii, String string, String expectedLabel) {
- int index = ii.getBucketIndex(string);
- String label = ii.getBucketLabel(index);
- assertEquals(expectedLabel, label);
- }
-
- public void test_en() throws Exception {
- // English [A-Z]
- AlphabeticIndex.ImmutableIndex en = createIndex(Locale.ENGLISH);
- assertHasLabel(en, "Allen", "A");
- assertHasLabel(en, "allen", "A");
- }
-
- public void test_ja() throws Exception {
- AlphabeticIndex.ImmutableIndex ja = createIndex(Locale.JAPANESE);
-
- // Japanese
- // sorts hiragana/katakana, Kanji/Chinese, English, other
- // …, あ, か, さ, た, な, は, ま, や, ら, わ, …
- // hiragana "a"
- assertHasLabel(ja, "Allen", "A");
- assertHasLabel(ja, "\u3041", "\u3042");
- // katakana "a"
- assertHasLabel(ja, "\u30a1", "\u3042");
-
- // Kanji (sorts to inflow section)
- assertHasLabel(ja, "\u65e5", "");
-
- // http://bugs.icu-project.org/trac/ticket/10423 / http://b/10809397
- assertHasLabel(ja, "\u95c7", "");
- assertHasLabel(ja, "\u308f", "わ");
-
- // English
- assertHasLabel(ja, "Smith", "S");
-
- // Chinese (sorts to inflow section)
- assertHasLabel(ja, "\u6c88" /* Shen/Chen */, "");
-
- // Korean Hangul (sorts to overflow section)
- assertHasLabel(ja, "\u1100", "");
- }
-
- public void test_ko() throws Exception {
- // Korean (sorts Korean, then English)
- // …, ᄀ, ᄂ, ᄃ, ᄅ, ᄆ, ᄇ, ᄉ, ᄋ, ᄌ, ᄎ, ᄏ, ᄐ, ᄑ, ᄒ, …
- AlphabeticIndex.ImmutableIndex ko = createIndex(Locale.KOREAN);
- assertHasLabel(ko, "\u1100", "\u3131");
- assertHasLabel(ko, "\u3131", "\u3131");
- assertHasLabel(ko, "\u1101", "\u3131");
- assertHasLabel(ko, "\u1161", "\u314e");
- }
-
- public void test_cs() throws Exception {
- // Czech
- // …, [A-C], Č,[D-H], CH, [I-R], Ř, S, Š, [T-Z], Ž, …
- AlphabeticIndex.ImmutableIndex cs = createIndex(new Locale("cs"));
- assertHasLabel(cs, "Cena", "C");
- assertHasLabel(cs, "Čáp", "\u010c");
- assertHasLabel(cs, "Ruda", "R");
- assertHasLabel(cs, "Řada", "\u0158");
- assertHasLabel(cs, "Selka", "S");
- assertHasLabel(cs, "Šála", "\u0160");
- assertHasLabel(cs, "Zebra", "Z");
- assertHasLabel(cs, "Žába", "\u017d");
- assertHasLabel(cs, "Chata", "CH");
- }
-
- public void test_fr() throws Exception {
- // French: [A-Z] (no accented chars)
- AlphabeticIndex.ImmutableIndex fr = createIndex(Locale.FRENCH);
- assertHasLabel(fr, "Øfer", "O");
- assertHasLabel(fr, "Œster", "O");
- }
-
- public void test_da() throws Exception {
- // Danish: [A-Z], Æ, Ø, Å
- AlphabeticIndex.ImmutableIndex da = createIndex(new Locale("da"));
- assertHasLabel(da, "Ænes", "\u00c6");
- assertHasLabel(da, "Øfer", "\u00d8");
- assertHasLabel(da, "Œster", "\u00d8");
- assertHasLabel(da, "Ågård", "\u00c5");
- }
-
- public void test_de() throws Exception {
- // German: [A-Z] (no ß or umlauted characters in standard alphabet)
- AlphabeticIndex.ImmutableIndex de = createIndex(Locale.GERMAN);
- assertHasLabel(de, "ßind", "S");
- // We no longer split out "S", "Sch", and "St".
- assertHasLabel(de, "Sacher", "S");
- assertHasLabel(de, "Schiller", "S");
- assertHasLabel(de, "Steiff", "S");
- }
-
- public void test_th() throws Exception {
- // Thai (sorts English then Thai)
- // …, ก, ข, ฃ, ค, ฅ, ฆ, ง, จ, ฉ, ช, ซ, ฌ, ญ, ฎ, ฏ, ฐ, ฑ, ฒ, ณ, ด, ต, ถ, ท, ธ, น, บ, ป, ผ, ฝ, พ, ฟ, ภ, ม, ย, ร, ฤ, ล, ฦ, ว, ศ, ษ, ส, ห, ฬ, อ, ฮ, …,
- AlphabeticIndex.ImmutableIndex th = createIndex(new Locale("th"));
- assertHasLabel(th, "\u0e2d\u0e07\u0e04\u0e4c\u0e40\u0e25\u0e47\u0e01", "\u0e2d");
- assertHasLabel(th, "\u0e2a\u0e34\u0e07\u0e2b\u0e40\u0e2a\u0e19\u0e35", "\u0e2a");
- }
-
- public void test_ar() throws Exception {
- // Arabic (sorts English then Arabic)
- // …, ا, ب, ت, ث, ج, ح, خ, د, ذ, ر, ز, س, ش, ص, ض, ط, ظ, ع, غ, ف, ق, ك, ل, م, ن, ه, و, ي, …
- AlphabeticIndex.ImmutableIndex ar = createIndex(new Locale("ar"));
- assertHasLabel(ar, "\u0646\u0648\u0631", /* Noor */ "\u0646");
- }
-
- public void test_he() throws Exception {
- // Hebrew (sorts English then Hebrew)
- // …, א, ב, ג, ד, ה, ו, ז, ח, ט, י, כ, ל, מ, נ, ס, ע, פ, צ, ק, ר, ש, ת, …
- AlphabeticIndex.ImmutableIndex he = createIndex(new Locale("he"));
- assertHasLabel(he, "\u05e4\u05e8\u05d9\u05d3\u05de\u05df", "\u05e4");
- }
-
- public void test_zh_CN() throws Exception {
- // Simplified Chinese (default collator Pinyin): [A-Z]
- AlphabeticIndex.ImmutableIndex zh_CN = createIndex(new Locale("zh", "CN"));
-
- // Jia/Gu: should be, usually, 'J' for name collator and 'G' for apps/other
- assertHasLabel(zh_CN, "\u8d3e", "J");
-
- // Shen/Chen (simplified): should usually be 'S' for names and 'C' for apps/other.
- // icu4c does not specialize for names and defaults to 'C'.
- // Some OEMs prefer to default to 'S'.
- // We allow either to pass CTS since neither choice is right all the time.
- // assertHasLabel(zh_CN, "\u6c88", "C");
- String shenChenLabel = zh_CN.getBucketLabel(zh_CN.getBucketIndex("\u6c88"));
- assertTrue(shenChenLabel.equals("C") || shenChenLabel.equals("S"));
-
- // Shen/Chen (traditional)
- assertHasLabel(zh_CN, "\u700b", "S");
- }
-
- public void test_zh_HK() throws Exception {
- // Traditional Chinese (strokes).
- // …, [1-33, 35, 36, 39, 48]劃, …
- // Shen/Chen
- AlphabeticIndex.ImmutableIndex zh_HK = createIndex(new Locale("zh", "HK"));
- assertHasLabel(zh_HK, "\u6c88", "7\u5283");
- assertHasLabel(zh_HK, "\u700b", "18\u5283");
- // Jia/Gu
- assertHasLabel(zh_HK, "\u8d3e", "10\u5283");
- }
-
- public void test_constructor_NPE() throws Exception {
- try {
- new AlphabeticIndex(null);
- fail();
- } catch (NullPointerException expected) {
- }
- }
-
- public void test_addLabels_NPE() throws Exception {
- AlphabeticIndex ai = new AlphabeticIndex(Locale.US);
- try {
- ai.addLabels(null);
- fail();
- } catch (NullPointerException expected) {
- }
- }
-
- // ICU 51 default max label count is 99. Test to make sure can create an
- // index with a larger number of labels.
- public void test_setMaxLabelCount() throws Exception {
- final int MAX_LABEL_COUNT = 500;
- AlphabeticIndex ai = new AlphabeticIndex(Locale.US)
- .setMaxLabelCount(MAX_LABEL_COUNT)
- .addLabels(Locale.JAPANESE)
- .addLabels(Locale.KOREAN)
- .addLabels(new Locale("th"))
- .addLabels(new Locale("ar"))
- .addLabels(new Locale("he"))
- .addLabels(new Locale("el"))
- .addLabels(new Locale("ru"));
- assertEquals(MAX_LABEL_COUNT, ai.getMaxLabelCount());
- assertEquals(208, ai.getBucketCount());
- AlphabeticIndex.ImmutableIndex ii = ai.getImmutableIndex();
- assertEquals(ai.getBucketCount(), ii.getBucketCount());
- }
-
- public void test_getBucketIndex_NPE() throws Exception {
- AlphabeticIndex.ImmutableIndex ii = createIndex(Locale.US);
- try {
- ii.getBucketIndex(null);
- fail();
- } catch (NullPointerException expected) {
- }
- }
-
- public void test_getBucketLabel_invalid() throws Exception {
- AlphabeticIndex.ImmutableIndex ii = createIndex(Locale.US);
- try {
- ii.getBucketLabel(-1);
- fail();
- } catch (IllegalArgumentException expected) {
- }
-
- try {
- ii.getBucketLabel(123456);
- fail();
- } catch (IllegalArgumentException expected) {
- }
- }
-}