use of android.icu.text.Collator in project j2objc by google.
the class LocaleAliasCollationTest method TestCollation.
@Test
public void TestCollation() {
ULocale defLoc = ULocale.getDefault();
ULocale.setDefault(_DEFAULT_LOCALE);
for (int i = 0; i < _LOCALE_NUMBER; i++) {
ULocale oldLoc = _LOCALES[i][0];
ULocale newLoc = _LOCALES[i][1];
if (availableMap.get(_LOCALES[i][1]) == null) {
logln(_LOCALES[i][1] + " is not available. Skipping!");
continue;
}
Collator c1 = Collator.getInstance(oldLoc);
Collator c2 = Collator.getInstance(newLoc);
if (!c1.equals(c2)) {
errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
}
logln("Collation old:" + oldLoc + " new:" + newLoc);
}
ULocale.setDefault(defLoc);
}
use of android.icu.text.Collator in project j2objc by google.
the class ULocaleCollationTest method TestIllformedLocale.
@Test
public void TestIllformedLocale() {
ULocale french = ULocale.FRENCH;
Collator collator = Collator.getInstance(french);
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
for (String malformed : Arrays.asList("en-a", "$", "ü--a", "en--US")) {
try {
Set<ULocale> supported = Collections.singleton(new ULocale(malformed));
names.getUiList(supported, false, collator);
assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
} catch (IllformedLocaleException e) {
logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.getMessage());
}
}
}
use of android.icu.text.Collator in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RegionSearchPicker method createAdapterItem.
private List<RegionItem> createAdapterItem(Set<String> regionIds) {
final Collator collator = Collator.getInstance(getLocale());
final TreeSet<RegionItem> items = new TreeSet<>(new RegionInfoComparator(collator));
final LocaleDisplayNames localeDisplayNames = LocaleDisplayNames.getInstance(getLocale());
long i = 0;
for (String regionId : regionIds) {
String name = localeDisplayNames.regionDisplayName(regionId);
items.add(new RegionItem(i++, regionId, name));
}
return new ArrayList<>(items);
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationAPITest method TestElemIter.
/**
* This tests the CollationElementIterator related APIs.
* - creation of a CollationElementIterator object
* - == and != operators
* - iterating forward
* - reseting the iterator index
* - requesting the order properties(primary, secondary or tertiary)
*/
@Test
public void TestElemIter() {
// logln("testing sortkey begins...");
Collator col = Collator.getInstance(Locale.ENGLISH);
String testString1 = "XFILE What subset of all possible test cases has the highest probability of detecting the most errors?";
String testString2 = "Xf_ile What subset of all possible test cases has the lowest probability of detecting the least errors?";
// logln("Constructors and comparison testing....");
CollationElementIterator iterator1 = ((RuleBasedCollator) col).getCollationElementIterator(testString1);
CharacterIterator chariter = new StringCharacterIterator(testString1);
// copy ctor
CollationElementIterator iterator2 = ((RuleBasedCollator) col).getCollationElementIterator(chariter);
UCharacterIterator uchariter = UCharacterIterator.getInstance(testString2);
CollationElementIterator iterator3 = ((RuleBasedCollator) col).getCollationElementIterator(uchariter);
int offset = 0;
offset = iterator1.getOffset();
if (offset != 0) {
errln("Error in getOffset for collation element iterator");
return;
}
iterator1.setOffset(6);
iterator1.setOffset(0);
int order1, order2, order3;
order1 = iterator1.next();
doAssert(!(iterator1.equals(iterator2)), "The first iterator advance failed");
order2 = iterator2.next();
// Code coverage for dummy "not designed" hashCode() which does "assert false".
try {
// We don't expect any particular value.
iterator1.hashCode();
} catch (AssertionError ignored) {
// Expected to be thrown if assertions are enabled.
}
// In ICU 52 and earlier we had iterator1.equals(iterator2)
// but in ICU 53 this fails because the iterators differ (String vs. CharacterIterator).
// doAssert((iterator1.equals(iterator2)), "The second iterator advance failed");
doAssert(iterator1.getOffset() == iterator2.getOffset(), "The second iterator advance failed");
doAssert((order1 == order2), "The order result should be the same");
order3 = iterator3.next();
doAssert((CollationElementIterator.primaryOrder(order1) == CollationElementIterator.primaryOrder(order3)), "The primary orders should be the same");
doAssert((CollationElementIterator.secondaryOrder(order1) == CollationElementIterator.secondaryOrder(order3)), "The secondary orders should be the same");
doAssert((CollationElementIterator.tertiaryOrder(order1) == CollationElementIterator.tertiaryOrder(order3)), "The tertiary orders should be the same");
order1 = iterator1.next();
order3 = iterator3.next();
doAssert((CollationElementIterator.primaryOrder(order1) == CollationElementIterator.primaryOrder(order3)), "The primary orders should be identical");
doAssert((CollationElementIterator.tertiaryOrder(order1) != CollationElementIterator.tertiaryOrder(order3)), "The tertiary orders should be different");
order1 = iterator1.next();
order3 = iterator3.next();
// invalid test wrong in UCA
// doAssert((CollationElementIterator.secondaryOrder(order1) !=
// CollationElementIterator.secondaryOrder(order3)), "The secondary orders should not be the same");
doAssert((order1 != CollationElementIterator.NULLORDER), "Unexpected end of iterator reached");
iterator1.reset();
iterator2.reset();
iterator3.reset();
order1 = iterator1.next();
doAssert(!(iterator1.equals(iterator2)), "The first iterator advance failed");
order2 = iterator2.next();
// In ICU 52 and earlier we had iterator1.equals(iterator2)
// but in ICU 53 this fails because the iterators differ (String vs. CharacterIterator).
// doAssert((iterator1.equals(iterator2)), "The second iterator advance failed");
doAssert(iterator1.getOffset() == iterator2.getOffset(), "The second iterator advance failed");
doAssert((order1 == order2), "The order result should be the same");
order3 = iterator3.next();
doAssert((CollationElementIterator.primaryOrder(order1) == CollationElementIterator.primaryOrder(order3)), "The primary orders should be the same");
doAssert((CollationElementIterator.secondaryOrder(order1) == CollationElementIterator.secondaryOrder(order3)), "The secondary orders should be the same");
doAssert((CollationElementIterator.tertiaryOrder(order1) == CollationElementIterator.tertiaryOrder(order3)), "The tertiary orders should be the same");
order1 = iterator1.next();
order2 = iterator2.next();
order3 = iterator3.next();
doAssert((CollationElementIterator.primaryOrder(order1) == CollationElementIterator.primaryOrder(order3)), "The primary orders should be identical");
doAssert((CollationElementIterator.tertiaryOrder(order1) != CollationElementIterator.tertiaryOrder(order3)), "The tertiary orders should be different");
order1 = iterator1.next();
order3 = iterator3.next();
// obsolete invalid test, removed
// doAssert((CollationElementIterator.secondaryOrder(order1) !=
// CollationElementIterator.secondaryOrder(order3)), "The secondary orders should not be the same");
doAssert((order1 != CollationElementIterator.NULLORDER), "Unexpected end of iterator reached");
doAssert(!(iterator2.equals(iterator3)), "The iterators should be different");
logln("testing CollationElementIterator ends...");
}
use of android.icu.text.Collator in project j2objc by google.
the class CollationMonkeyTest method TestRules.
@Test
public void TestRules() {
String[] testSourceCases = { "\u0061\u0062\u007a", "\u0061\u0062\u007a" };
String[] testTargetCases = { "\u0061\u0062\u00e4", "\u0061\u0062\u0061\u0308" };
int i = 0;
logln("Demo Test 1 : Create a new table collation with rules \"& z < 0x00e4\"");
Collator col = Collator.getInstance(new Locale("en", "US"));
String baseRules = ((RuleBasedCollator) col).getRules();
String newRules = " & z < ";
newRules = baseRules + newRules + String.valueOf(0x00e4);
RuleBasedCollator myCollation = null;
try {
myCollation = new RuleBasedCollator(newRules);
} catch (Exception e) {
warnln("Demo Test 1 Table Collation object creation failed.");
return;
}
for (i = 0; i < 2; i++) {
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
}
logln("Demo Test 2 : Create a new table collation with rules \"& z < a 0x0308\"");
newRules = "";
newRules = baseRules + " & z < a" + String.valueOf(0x0308);
try {
myCollation = new RuleBasedCollator(newRules);
} catch (Exception e) {
errln("Demo Test 1 Table Collation object creation failed.");
return;
}
for (i = 0; i < 2; i++) {
doTest(myCollation, testSourceCases[i], testTargetCases[i], -1);
}
}
Aggregations