2 //#if defined(FOUNDATION10) || defined(J2SE13)
5 *******************************************************************************
6 * Copyright (C) 2008-2009, International Business Machines Corporation and *
7 * others. All Rights Reserved. *
8 *******************************************************************************
10 package com.ibm.icu.dev.test.collator;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Iterator;
15 import java.util.List;
18 import com.ibm.icu.dev.test.TestFmwk;
19 import com.ibm.icu.text.Collator;
20 import com.ibm.icu.text.IndexCharacters;
21 import com.ibm.icu.util.ULocale;
27 public class IndexCharactersTest extends TestFmwk {
28 public static void main(String[] args) throws Exception{
29 new IndexCharactersTest().run(args);
32 public void TestBasics() {
33 ULocale[] list = ULocale.getAvailableLocales();
34 // get keywords combinations
35 // don't bother with multiple combinations at this poin
36 List keywords = new ArrayList();
39 String[] collationValues = Collator.getKeywordValues("collation");
40 for (int j = 0; j < collationValues.length; ++j) {
41 keywords.add("@collation=" + collationValues[j]);
44 for (int i = 0; i < list.length; ++i) {
45 for (Iterator it = keywords.iterator(); it.hasNext();) {
46 String collationValue = (String) it.next();
47 ULocale locale = new ULocale(list[i].toString() + collationValue);
48 if (collationValue.length() > 0 && !Collator.getFunctionalEquivalent("collation", locale).equals(locale)) {
49 //logln("Skipping " + locale);
53 if (locale.getCountry().length() != 0) {
56 IndexCharacters indexCharacters = new IndexCharacters(locale);
57 final Collection mainChars = indexCharacters.getIndexCharacters();
58 String mainCharString = mainChars.toString();
59 if (mainCharString.length() > 500) {
60 mainCharString = mainCharString.substring(0,500) + "...";
62 logln(mainChars.size() + "\t" + locale + "\t" + locale.getDisplayName(ULocale.ENGLISH));
63 logln("Index:\t" + mainCharString);
64 if (mainChars.size() > 100) {
65 errln("Index character set too large");
67 showIfNotEmpty("A sequence sorting the same is already present", indexCharacters.getAlreadyIn());
68 showIfNotEmpty("A sequence sorts the same as components", indexCharacters.getNoDistinctSorting());
69 showIfNotEmpty("A sequence has only Marks or Nonalphabetics", indexCharacters.getNotAlphabetic());
73 private void showIfNotEmpty(String title, List alreadyIn) {
74 if (alreadyIn.size() != 0) {
75 logln("\t" + title + ":\t" + alreadyIn);
78 private void showIfNotEmpty(String title, Map alreadyIn) {
79 if (alreadyIn.size() != 0) {
80 logln("\t" + title + ":\t" + alreadyIn);