]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/util/TestBagFormatter.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / util / TestBagFormatter.java
old mode 100755 (executable)
new mode 100644 (file)
index 31e9e42..791656d
-//##header\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//#else\r
-/*\r
- *******************************************************************************\r
- * Copyright (C) 2002-2009, International Business Machines Corporation and    *\r
- * others. All Rights Reserved.                                                *\r
- *******************************************************************************\r
- */\r
-package com.ibm.icu.dev.test.util;\r
-\r
-// TODO integrate this into the test framework\r
-\r
-import java.io.IOException;\r
-import java.io.PrintWriter;\r
-import java.text.Collator;\r
-import java.util.Comparator;\r
-import java.util.Iterator;\r
-import java.util.Locale;\r
-import java.util.Set;\r
-import java.util.TreeSet;\r
-\r
-import com.ibm.icu.lang.UProperty;\r
-import com.ibm.icu.lang.UScript;\r
-import com.ibm.icu.text.Transliterator;\r
-import com.ibm.icu.text.UnicodeSet;\r
-\r
-// TODO change to use test framework\r
-public class TestBagFormatter {\r
-    \r
-    static final void generatePropertyAliases(boolean showValues) {\r
-        generatePropertyAliases(showValues, ICUPropertyFactory.make());\r
-    }\r
-    \r
-    static final void generatePropertyAliases(boolean showValues, UnicodeProperty.Factory ups) {\r
-        Collator order = Collator.getInstance(Locale.ENGLISH);\r
-        TreeSet props = new TreeSet(order);\r
-        TreeSet values = new TreeSet(order);\r
-        BagFormatter bf = new BagFormatter();\r
-        props.addAll(ups.getAvailableNames());\r
-        for (int i = UnicodeProperty.BINARY; i < UnicodeProperty.LIMIT_TYPE; ++i) {\r
-            System.out.println(UnicodeProperty.getTypeName(i));\r
-            Iterator it = props.iterator();\r
-            while (it.hasNext()) {\r
-                String propAlias = (String)it.next();\r
-                UnicodeProperty up = ups.getProperty(propAlias);\r
-                int type = up.getType();\r
-                if (type != i) continue;                \r
-                System.out.println();\r
-                System.out.println(propAlias + "\t" + bf.join(up.getNameAliases()));\r
-                if (!showValues) continue;\r
-                values.clear();\r
-                if (type == UnicodeProperty.NUMERIC || type == UnicodeProperty.EXTENDED_NUMERIC) {\r
-                    UnicodeMap um = new UnicodeMap();\r
-                    um.putAll(up);\r
-                    System.out.println(um.toString(new NumberComparator()));\r
-                    continue;\r
-                }\r
-                values.clear();\r
-                values.addAll(up.getAvailableValues());\r
-                Iterator it2 = values.iterator();\r
-                while (it2.hasNext()) {\r
-                    String valueAlias = (String)it2.next();\r
-                    System.out.println("\t" + bf.join(valueAlias + "\t" + up.getValueAliases(valueAlias)));\r
-                }\r
-            }\r
-        }\r
-    }\r
-    \r
-    static class NumberComparator implements Comparator {\r
-        public int compare(Object o1, Object o2) {\r
-            if (o1 == o2) return 0;\r
-            if (o1 == null) return 1;\r
-            if (o2 == null) return -1;\r
-            double n1 = Double.parseDouble((String)o1);\r
-            double n2 = Double.parseDouble((String)o2);\r
-            return n1 < n2 ? -1 : n1 > n2 ? 1 : 0;\r
-        }\r
-    }\r
-\r
-    public static void main(String[] args) throws Exception {\r
-        System.out.println("Start");\r
-        try {\r
-            //readCharacters();\r
-            UnicodeProperty prop = ICUPropertyFactory.make().getProperty("Canonicalcombiningclass");\r
-            prop.getAvailableValues();\r
-            \r
-            generatePropertyAliases(true);\r
-            \r
-            BagFormatter bf = new BagFormatter();\r
-\r
-            UnicodeSet us = new UnicodeSet("[:gc=nd:]");  \r
-            BagFormatter.CONSOLE.println("[:gc=nd:]");\r
-            bf.showSetNames(BagFormatter.CONSOLE,us);\r
-\r
-            us = new UnicodeSet("[:numeric_value=2:]");  \r
-            BagFormatter.CONSOLE.println("[:numeric_value=2:]");\r
-            bf.showSetNames(BagFormatter.CONSOLE,us);\r
-            \r
-            us = new UnicodeSet("[:numeric_type=numeric:]");   \r
-            BagFormatter.CONSOLE.println("[:numeric_type=numeric:]");\r
-            bf.showSetNames(BagFormatter.CONSOLE,us);\r
-            \r
-            UnicodeProperty.Factory ups = ICUPropertyFactory.make();\r
-            us = ups.getSet("gc=mn", null, null); \r
-            BagFormatter.CONSOLE.println("gc=mn");\r
-            bf.showSetNames(BagFormatter.CONSOLE, us);\r
-            \r
-            if (true) return;\r
-            //showNames("Name", ".*MARK.*");\r
-            //showNames("NFD", "a.+");\r
-            //showNames("NFD", false);\r
-            //showNames("Lowercase_Mapping", false);\r
-            //TestUnicodePropertySource.test(true);\r
-            //showNames(".*\\ \\-.*");\r
-\r
-\r
-            //checkHTML();\r
-            //testIsRTL();\r
-           \r
-            //TestTokenizer.test();\r
-            //RandomCollator.generate("collationTest.txt", null);\r
-            \r
-            //TestPick.test();\r
-            //printRandoms();\r
-            //if (true) return;\r
-            //testLocales();\r
-            //if (true) return;\r
-            /*\r
-            TestCollator tc = new TestCollator();\r
-            tc.test(RuleBasedCollator.getInstance(),1000);\r
-            */\r
-            /*\r
-            StringBuffer sb = new StringBuffer();\r
-            for (int i = 0; i < 100; ++i) {\r
-                sb.setLength(0);\r
-                rc.nextRule(sb);\r
-                System.out.println(sb);\r
-            }\r
-            */\r
-        } finally {\r
-            System.out.println("End");\r
-       }\r
-\r
-    }\r
-    \r
-    static void testLocales() throws IOException {\r
-        Locale[] locales = Collator.getAvailableLocales();\r
-        Set s = new TreeSet(Collator.getInstance());\r
-        for (int i = 0; i < locales.length; ++i) {\r
-            String lang = locales[i].getLanguage();\r
-            String dlang = locales[i].getDisplayLanguage();\r
-            String country = locales[i].getCountry();\r
-            String dcountry = locales[i].getDisplayCountry();\r
-            if (country.equals("")) continue;\r
-            s.add(""\r
-                + "\t" + dcountry \r
-                + "\t" + country \r
-                + "\t" + dlang\r
-                + "\t" + lang \r
-            );\r
-        }\r
-        //CollectionFormatter cf = new CollectionFormatter();\r
-        PrintWriter pw = BagFormatter.openUTF8Writer("", "countries.txt");\r
-        Iterator it = s.iterator();\r
-        while (it.hasNext()) {\r
-            pw.println(it.next());\r
-        }\r
-        pw.close();\r
-    }\r
-    \r
-    \r
-    /*\r
-     * Use the number of significant digits to round get a rounding value.\r
-     */\r
-/*    static final double LOG10 = Math.log(10);\r
-    public static void useSignificantDigits(double value, int digits) {\r
-        double log10 = Math.log(value)/LOG10; // log[e]\r
-        \r
-    }*/\r
-    \r
-    static final UnicodeSet RTL = new UnicodeSet("[[:L:]&[[:bidi class=R:][:bidi class=AL:]]]");\r
-    \r
-    static boolean isRTL(Locale loc) {        \r
-        // in 2.8 we can use the exemplar characters, but for 2.6 we have to work around it\r
-        int[] scripts = UScript.getCode(loc);\r
-        return new UnicodeSet()\r
-            .applyIntPropertyValue(UProperty.SCRIPT, scripts == null ? UScript.LATIN : scripts[0])\r
-            .retainAll(RTL).size() != 0;\r
-    }\r
-    \r
-    static void testIsRTL() {\r
-        Locale[] locales = Locale.getAvailableLocales();\r
-        Set s = new TreeSet();\r
-        for (int i = 0; i < locales.length; ++i) {\r
-            s.add((isRTL(locales[i]) ? "R " : "L ") + locales[i].getDisplayName());\r
-        }\r
-        Iterator it = s.iterator();\r
-        while (it.hasNext()) {\r
-            System.out.println(it.next());\r
-        }\r
-    }\r
-\r
-    static final Transliterator toHTML = Transliterator.createFromRules(\r
-        "any-html",        \r
-            "'<' > '&lt;' ;" +\r
-            "'&' > '&amp;' ;" +\r
-            "'>' > '&gt;' ;" +\r
-            "'\"' > '&quot;' ; ",\r
-        Transliterator.FORWARD);\r
-    static final Transliterator fromHTML = Transliterator.createFromRules(\r
-        "html-any",        \r
-            "'<' < '&'[lL][Tt]';' ;" +\r
-            "'&' < '&'[aA][mM][pP]';' ;" +\r
-            "'>' < '&'[gG][tT]';' ;" +\r
-            "'\"' < '&'[qQ][uU][oO][tT]';' ; ",\r
-        Transliterator.REVERSE);\r
-        \r
-    static void checkHTML() {\r
-        String foo = "& n < b < \"ab\"";\r
-        String fii = toHTML.transliterate(foo);\r
-        System.out.println("in: " + foo);\r
-        System.out.println("out: " + fii);\r
-        System.out.println("in*: " + fromHTML.transliterate(fii));\r
-        System.out.println("IN*: " + fromHTML.transliterate(fii.toUpperCase()));\r
-    }\r
-    /*\r
-    static void showNames(String propAlias, boolean matches) {\r
-        BagFormatter bf = new BagFormatter();\r
-        UnicodeSet stuff;\r
-        stuff = new UnicodePropertySource.ICU()\r
-            .setPropertyAlias(propAlias)\r
-            .getPropertySet(matches, null);\r
-        System.out.println(bf.showSetNames(propAlias + " with " + matches, stuff));\r
-    }\r
-    \r
-    static void showNames(String propAlias, String pattern) {\r
-        BagFormatter bf = new BagFormatter();\r
-        UnicodeSet stuff;\r
-        stuff = new UnicodePropertySource.ICU()\r
-            .setPropertyAlias(propAlias)\r
-            .getPropertySet(Pattern.compile(pattern).matcher(""), null);\r
-        System.out.println(bf.showSetNames(propAlias + "with " + pattern, stuff));\r
-    }\r
-    */\r
-}\r
-//#endif\r
+//##header J2SE15
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//#else
+/*
+ *******************************************************************************
+ * Copyright (C) 2002-2009, International Business Machines Corporation and    *
+ * others. All Rights Reserved.                                                *
+ *******************************************************************************
+ */
+package com.ibm.icu.dev.test.util;
+
+// TODO integrate this into the test framework
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.Collator;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.ibm.icu.lang.UProperty;
+import com.ibm.icu.lang.UScript;
+import com.ibm.icu.text.Transliterator;
+import com.ibm.icu.text.UnicodeSet;
+
+// TODO change to use test framework
+public class TestBagFormatter {
+    
+    static final void generatePropertyAliases(boolean showValues) {
+        generatePropertyAliases(showValues, ICUPropertyFactory.make());
+    }
+    
+    static final void generatePropertyAliases(boolean showValues, UnicodeProperty.Factory ups) {
+        Collator order = Collator.getInstance(Locale.ENGLISH);
+        TreeSet props = new TreeSet(order);
+        TreeSet values = new TreeSet(order);
+        BagFormatter bf = new BagFormatter();
+        props.addAll(ups.getAvailableNames());
+        for (int i = UnicodeProperty.BINARY; i < UnicodeProperty.LIMIT_TYPE; ++i) {
+            System.out.println(UnicodeProperty.getTypeName(i));
+            Iterator it = props.iterator();
+            while (it.hasNext()) {
+                String propAlias = (String)it.next();
+                UnicodeProperty up = ups.getProperty(propAlias);
+                int type = up.getType();
+                if (type != i) continue;                
+                System.out.println();
+                System.out.println(propAlias + "\t" + bf.join(up.getNameAliases()));
+                if (!showValues) continue;
+                values.clear();
+                if (type == UnicodeProperty.NUMERIC || type == UnicodeProperty.EXTENDED_NUMERIC) {
+                    UnicodeMap um = new UnicodeMap();
+                    um.putAll(up);
+                    System.out.println(um.toString(new NumberComparator()));
+                    continue;
+                }
+                values.clear();
+                values.addAll(up.getAvailableValues());
+                Iterator it2 = values.iterator();
+                while (it2.hasNext()) {
+                    String valueAlias = (String)it2.next();
+                    System.out.println("\t" + bf.join(valueAlias + "\t" + up.getValueAliases(valueAlias)));
+                }
+            }
+        }
+    }
+    
+    static class NumberComparator implements Comparator {
+        public int compare(Object o1, Object o2) {
+            if (o1 == o2) return 0;
+            if (o1 == null) return 1;
+            if (o2 == null) return -1;
+            double n1 = Double.parseDouble((String)o1);
+            double n2 = Double.parseDouble((String)o2);
+            return n1 < n2 ? -1 : n1 > n2 ? 1 : 0;
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        System.out.println("Start");
+        try {
+            //readCharacters();
+            UnicodeProperty prop = ICUPropertyFactory.make().getProperty("Canonicalcombiningclass");
+            prop.getAvailableValues();
+            
+            generatePropertyAliases(true);
+            
+            BagFormatter bf = new BagFormatter();
+
+            UnicodeSet us = new UnicodeSet("[:gc=nd:]");  
+            BagFormatter.CONSOLE.println("[:gc=nd:]");
+            bf.showSetNames(BagFormatter.CONSOLE,us);
+
+            us = new UnicodeSet("[:numeric_value=2:]");  
+            BagFormatter.CONSOLE.println("[:numeric_value=2:]");
+            bf.showSetNames(BagFormatter.CONSOLE,us);
+            
+            us = new UnicodeSet("[:numeric_type=numeric:]");   
+            BagFormatter.CONSOLE.println("[:numeric_type=numeric:]");
+            bf.showSetNames(BagFormatter.CONSOLE,us);
+            
+            UnicodeProperty.Factory ups = ICUPropertyFactory.make();
+            us = ups.getSet("gc=mn", null, null); 
+            BagFormatter.CONSOLE.println("gc=mn");
+            bf.showSetNames(BagFormatter.CONSOLE, us);
+            
+            if (true) return;
+            //showNames("Name", ".*MARK.*");
+            //showNames("NFD", "a.+");
+            //showNames("NFD", false);
+            //showNames("Lowercase_Mapping", false);
+            //TestUnicodePropertySource.test(true);
+            //showNames(".*\\ \\-.*");
+
+
+            //checkHTML();
+            //testIsRTL();
+           
+            //TestTokenizer.test();
+            //RandomCollator.generate("collationTest.txt", null);
+            
+            //TestPick.test();
+            //printRandoms();
+            //if (true) return;
+            //testLocales();
+            //if (true) return;
+            /*
+            TestCollator tc = new TestCollator();
+            tc.test(RuleBasedCollator.getInstance(),1000);
+            */
+            /*
+            StringBuffer sb = new StringBuffer();
+            for (int i = 0; i < 100; ++i) {
+                sb.setLength(0);
+                rc.nextRule(sb);
+                System.out.println(sb);
+            }
+            */
+        } finally {
+            System.out.println("End");
+       }
+
+    }
+    
+    static void testLocales() throws IOException {
+        Locale[] locales = Collator.getAvailableLocales();
+        Set s = new TreeSet(Collator.getInstance());
+        for (int i = 0; i < locales.length; ++i) {
+            String lang = locales[i].getLanguage();
+            String dlang = locales[i].getDisplayLanguage();
+            String country = locales[i].getCountry();
+            String dcountry = locales[i].getDisplayCountry();
+            if (country.equals("")) continue;
+            s.add(""
+                + "\t" + dcountry 
+                + "\t" + country 
+                + "\t" + dlang
+                + "\t" + lang 
+            );
+        }
+        //CollectionFormatter cf = new CollectionFormatter();
+        PrintWriter pw = BagFormatter.openUTF8Writer("", "countries.txt");
+        Iterator it = s.iterator();
+        while (it.hasNext()) {
+            pw.println(it.next());
+        }
+        pw.close();
+    }
+    
+    
+    /*
+     * Use the number of significant digits to round get a rounding value.
+     */
+/*    static final double LOG10 = Math.log(10);
+    public static void useSignificantDigits(double value, int digits) {
+        double log10 = Math.log(value)/LOG10; // log[e]
+        
+    }*/
+    
+    static final UnicodeSet RTL = new UnicodeSet("[[:L:]&[[:bidi class=R:][:bidi class=AL:]]]");
+    
+    static boolean isRTL(Locale loc) {        
+        // in 2.8 we can use the exemplar characters, but for 2.6 we have to work around it
+        int[] scripts = UScript.getCode(loc);
+        return new UnicodeSet()
+            .applyIntPropertyValue(UProperty.SCRIPT, scripts == null ? UScript.LATIN : scripts[0])
+            .retainAll(RTL).size() != 0;
+    }
+    
+    static void testIsRTL() {
+        Locale[] locales = Locale.getAvailableLocales();
+        Set s = new TreeSet();
+        for (int i = 0; i < locales.length; ++i) {
+            s.add((isRTL(locales[i]) ? "R " : "L ") + locales[i].getDisplayName());
+        }
+        Iterator it = s.iterator();
+        while (it.hasNext()) {
+            System.out.println(it.next());
+        }
+    }
+
+    static final Transliterator toHTML = Transliterator.createFromRules(
+        "any-html",        
+            "'<' > '&lt;' ;" +
+            "'&' > '&amp;' ;" +
+            "'>' > '&gt;' ;" +
+            "'\"' > '&quot;' ; ",
+        Transliterator.FORWARD);
+    static final Transliterator fromHTML = Transliterator.createFromRules(
+        "html-any",        
+            "'<' < '&'[lL][Tt]';' ;" +
+            "'&' < '&'[aA][mM][pP]';' ;" +
+            "'>' < '&'[gG][tT]';' ;" +
+            "'\"' < '&'[qQ][uU][oO][tT]';' ; ",
+        Transliterator.REVERSE);
+        
+    static void checkHTML() {
+        String foo = "& n < b < \"ab\"";
+        String fii = toHTML.transliterate(foo);
+        System.out.println("in: " + foo);
+        System.out.println("out: " + fii);
+        System.out.println("in*: " + fromHTML.transliterate(fii));
+        System.out.println("IN*: " + fromHTML.transliterate(fii.toUpperCase()));
+    }
+    /*
+    static void showNames(String propAlias, boolean matches) {
+        BagFormatter bf = new BagFormatter();
+        UnicodeSet stuff;
+        stuff = new UnicodePropertySource.ICU()
+            .setPropertyAlias(propAlias)
+            .getPropertySet(matches, null);
+        System.out.println(bf.showSetNames(propAlias + " with " + matches, stuff));
+    }
+    
+    static void showNames(String propAlias, String pattern) {
+        BagFormatter bf = new BagFormatter();
+        UnicodeSet stuff;
+        stuff = new UnicodePropertySource.ICU()
+            .setPropertyAlias(propAlias)
+            .getPropertySet(Pattern.compile(pattern).matcher(""), null);
+        System.out.println(bf.showSetNames(propAlias + "with " + pattern, stuff));
+    }
+    */
+}
+//#endif