use of android.icu.impl.Row.R4 in project j2objc by google.
the class AlphabeticIndexTest method TestClientSupport.
@Test
public void TestClientSupport() {
for (String localeString : new String[] { "zh" }) {
// KEY_LOCALES, new String[] {"zh"}
ULocale ulocale = new ULocale(localeString);
AlphabeticIndex<Double> alphabeticIndex = new AlphabeticIndex<Double>(ulocale).addLabels(Locale.ENGLISH);
RuleBasedCollator collator = alphabeticIndex.getCollator();
String[][] tests;
if (!localeString.equals("zh")) {
tests = new String[][] { SimpleTests };
} else {
tests = new String[][] { SimpleTests, hackPinyin, simplifiedNames };
}
for (String[] shortTest : tests) {
double testValue = 100;
alphabeticIndex.clearRecords();
for (String name : shortTest) {
alphabeticIndex.addRecord(name, testValue++);
}
if (DEBUG)
showIndex(alphabeticIndex, false);
// make my own copy
testValue = 100;
List<String> myBucketLabels = alphabeticIndex.getBucketLabels();
ArrayList<Set<R4<RawCollationKey, String, Integer, Double>>> myBucketContents = new ArrayList<Set<R4<RawCollationKey, String, Integer, Double>>>(myBucketLabels.size());
for (int i = 0; i < myBucketLabels.size(); ++i) {
myBucketContents.add(new TreeSet<R4<RawCollationKey, String, Integer, Double>>());
}
for (String name : shortTest) {
int bucketIndex = alphabeticIndex.getBucketIndex(name);
if (bucketIndex > myBucketContents.size()) {
// call again for debugging
alphabeticIndex.getBucketIndex(name);
}
Set<R4<RawCollationKey, String, Integer, Double>> myBucket = myBucketContents.get(bucketIndex);
RawCollationKey rawCollationKey = collator.getRawCollationKey(name, null);
R4<RawCollationKey, String, Integer, Double> row = Row.of(rawCollationKey, name, name.length(), testValue++);
myBucket.add(row);
}
if (DEBUG)
showIndex(myBucketLabels, myBucketContents, false);
// now compare
int index = 0;
boolean gotError = false;
for (AlphabeticIndex.Bucket<Double> bucket : alphabeticIndex) {
String bucketLabel = bucket.getLabel();
String myLabel = myBucketLabels.get(index);
if (!bucketLabel.equals(myLabel)) {
gotError |= !assertEquals(ulocale + "\tBucket Labels (" + index + ")", bucketLabel, myLabel);
}
Set<R4<RawCollationKey, String, Integer, Double>> myBucket = myBucketContents.get(index);
Iterator<R4<RawCollationKey, String, Integer, Double>> myBucketIterator = myBucket.iterator();
int recordIndex = 0;
for (Record<Double> record : bucket) {
String myName = null;
if (myBucketIterator.hasNext()) {
R4<RawCollationKey, String, Integer, Double> myRecord = myBucketIterator.next();
myName = myRecord.get1();
}
if (!record.getName().equals(myName)) {
gotError |= !assertEquals(ulocale + "\t" + bucketLabel + "\t" + "Record Names (" + index + "." + recordIndex++ + ")", record.getName(), myName);
}
}
while (myBucketIterator.hasNext()) {
R4<RawCollationKey, String, Integer, Double> myRecord = myBucketIterator.next();
String myName = myRecord.get1();
gotError |= !assertEquals(ulocale + "\t" + bucketLabel + "\t" + "Record Names (" + index + "." + recordIndex++ + ")", null, myName);
}
index++;
}
if (gotError) {
showIndex(myBucketLabels, myBucketContents, false);
showIndex(alphabeticIndex, false);
}
}
}
}
Aggregations