1 /* 2 ********************************************************************** 3 * Copyright (c) 2006-2007, Google and others. All Rights Reserved. 4 ********************************************************************** 5 * Author: Mark Davis 6 ********************************************************************** 7 */ 8 package org.unicode.cldr.unittest; 9 10 import java.util.Map; 11 import java.util.Set; 12 import java.util.TreeMap; 13 import java.util.TreeSet; 14 15 import org.unicode.cldr.util.IntMap; 16 import org.unicode.cldr.util.IntMap.BasicIntMapFactory; 17 import org.unicode.cldr.util.IntMap.CompactStringIntMapFactory; 18 import org.unicode.cldr.util.IntMap.IntMapFactory; 19 20 import com.ibm.icu.lang.UCharacter; 21 import com.ibm.icu.text.NumberFormat; 22 import com.ibm.icu.text.UnicodeSet; 23 import com.ibm.icu.text.UnicodeSetIterator; 24 import com.ibm.icu.util.ULocale; 25 26 public class TestIntMap { 27 static NumberFormat format = NumberFormat.getInstance(); 28 main(String[] args)29 public static void main(String[] args) { 30 Object[] factories = { new BasicIntMapFactory<String>(), 31 new CompactStringIntMapFactory() }; 32 Set<String> samples = new TreeSet<String>(); 33 for (String langCode : ULocale.getISOLanguages()) { 34 samples.add(ULocale.getDisplayLanguage(langCode, ULocale.JAPANESE)); 35 } 36 checkSamples(factories, samples); 37 UnicodeSet testSet = new UnicodeSet( 38 "[[:assigned:] - [:ideographic:] - [:Co:] - [:Cs:] - [:script=Hang:]]"); // & 39 // [\\u0000-\\u0FFF] 40 41 samples.clear(); 42 for (UnicodeSetIterator it = new UnicodeSetIterator(testSet); it.next();) { 43 String name = UCharacter.getExtendedName(it.codepoint); 44 if (name != null) { 45 samples.add(name); 46 } 47 } 48 checkSamples(factories, samples); 49 } 50 checkSamples(Object[] factories, Set<String> samples)51 private static void checkSamples(Object[] factories, Set<String> samples) { 52 int bytes = 0; 53 for (String string : samples) { 54 System.out.println(string); 55 bytes += string.length() * 2; 56 } 57 System.out.println("String count: " + format.format(samples.size()) 58 + "\t bytes: " + format.format(bytes)); 59 for (Object factoryObject : factories) { 60 IntMap<String> map = ((IntMapFactory<String>) factoryObject) 61 .make(samples); 62 Map<String, Integer> values = map 63 .getValueMap(new TreeMap<String, Integer>()); 64 System.out.println(map.getClass().getName() + "\t" 65 + format.format(map.approximateStorage())); 66 if (!values.keySet().equals(samples)) { 67 System.out.println("Missing Values!"); 68 } 69 } 70 } 71 }