]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/collator/IndexCharactersTest.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / collator / IndexCharactersTest.java
1 //##header J2SE15
2 //#if defined(FOUNDATION10) || defined(J2SE13)
3 //#else
4 /*
5  *******************************************************************************
6  * Copyright (C) 2008-2009, International Business Machines Corporation and    *
7  * others. All Rights Reserved.                                                *
8  *******************************************************************************
9  */
10 package com.ibm.icu.dev.test.collator;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Map;
17
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;
22
23 /**
24  * @author markdavis
25  *
26  */
27 public class IndexCharactersTest extends TestFmwk {
28     public static void main(String[] args) throws Exception{
29         new IndexCharactersTest().run(args);
30     }
31
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();
37         keywords.add("");
38
39         String[] collationValues = Collator.getKeywordValues("collation");
40         for (int j = 0; j < collationValues.length; ++j) {
41             keywords.add("@collation=" + collationValues[j]);
42         }
43         
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);
50                     continue;
51                 }
52
53                 if (locale.getCountry().length() != 0) {
54                     continue;
55                 }
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) + "...";
61                 }
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");
66                 }
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());
70             }
71         }
72     }
73     private void showIfNotEmpty(String title, List alreadyIn) {
74         if (alreadyIn.size() != 0) {
75             logln("\t" + title + ":\t" + alreadyIn);
76         }
77     }
78     private void showIfNotEmpty(String title, Map alreadyIn) {
79         if (alreadyIn.size() != 0) {
80             logln("\t" + title + ":\t" + alreadyIn);
81         }
82     }
83 }
84 //#endif