1/** 2******************************************************************************* 3* Copyright (C) 1996-2010, International Business Machines Corporation and * 4* others. All Rights Reserved. * 5******************************************************************************* 6*/ 7 8package com.ibm.icu.dev.test.lang; 9 10import java.io.FileWriter; 11import java.io.PrintWriter; 12import java.util.HashMap; 13import java.util.Map; 14 15import com.ibm.icu.lang.UCharacter; 16import com.ibm.icu.lang.UCharacterCategory; 17 18/** 19* A class to compare the difference in methods between java.lang.Character and 20* UCharacter 21* @author Syn Wee Quek 22* @since oct 06 2000 23* @see com.ibm.icu.lang.UCharacter 24*/ 25 26public final class UCharacterCompare 27{ 28 // private variables ================================================ 29 30 private static Map<String, Integer> m_hashtable_ = new HashMap<String, Integer>(); 31 32 // public methods ====================================================== 33 34 /** 35 * Main testing method 36 */ 37 public static void main(String arg[]) { 38 System.out.println("Starting character compare"); 39 try { 40 FileWriter f; 41 if (arg.length == 0) 42 f = new FileWriter("compare.txt"); 43 else 44 f = new FileWriter(arg[0]); 45 PrintWriter p = new PrintWriter(f); 46 p.print("char character name "); 47 p.println("method name ucharacter character"); 48 for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) { 49 System.out.println("character \\u" + Integer.toHexString(i)); 50 if (UCharacter.isDefined(i) != Character.isDefined(i)) 51 trackDifference(p, i, "isDefined()", "" + UCharacter.isDefined(i), "" + Character.isDefined(i)); 52 else { 53 if (UCharacter.digit(i, 10) != Character.digit(i, 10)) 54 trackDifference(p, i, "digit()", "" + UCharacter.digit(i, 10), "" + Character.digit(i, 10)); 55 if (UCharacter.getNumericValue(i) != Character.getNumericValue(i)) 56 trackDifference(p, i, "getNumericValue()", "" + UCharacter.getNumericValue(i), "" 57 + Character.getNumericValue(i)); 58 if (!compareType(UCharacter.getType(i), Character.getType(i))) 59 trackDifference(p, i, "getType()", "" + UCharacter.getType(i), "" + Character.getType(i)); 60 if (UCharacter.isDigit(i) != Character.isDigit(i)) 61 trackDifference(p, i, "isDigit()", "" + UCharacter.isDigit(i), "" + Character.isDigit(i)); 62 if (UCharacter.isISOControl(i) != Character.isISOControl(i)) 63 trackDifference(p, i, "isISOControl()", "" + UCharacter.isISOControl(i), "" 64 + Character.isISOControl(i)); 65 if (UCharacter.isLetter(i) != Character.isLetter(i)) 66 trackDifference(p, i, "isLetter()", "" + UCharacter.isLetter(i), "" + Character.isLetter(i)); 67 if (UCharacter.isLetterOrDigit(i) != Character.isLetterOrDigit(i)) 68 trackDifference(p, i, "isLetterOrDigit()", "" + UCharacter.isLetterOrDigit(i), "" 69 + Character.isLetterOrDigit(i)); 70 if (UCharacter.isLowerCase(i) != Character.isLowerCase(i)) 71 trackDifference(p, i, "isLowerCase()", "" + UCharacter.isLowerCase(i), "" 72 + Character.isLowerCase(i)); 73 if (UCharacter.isWhitespace(i) != Character.isWhitespace(i)) 74 trackDifference(p, i, "isWhitespace()", "" + UCharacter.isWhitespace(i), "" 75 + Character.isWhitespace(i)); 76 if (UCharacter.isSpaceChar(i) != Character.isSpaceChar(i)) 77 trackDifference(p, i, "isSpaceChar()", "" + UCharacter.isSpaceChar(i), "" 78 + Character.isSpaceChar(i)); 79 if (UCharacter.isTitleCase(i) != Character.isTitleCase(i)) 80 trackDifference(p, i, "isTitleChar()", "" + UCharacter.isTitleCase(i), "" 81 + Character.isTitleCase(i)); 82 if (UCharacter.isUnicodeIdentifierPart(i) != Character.isUnicodeIdentifierPart(i)) 83 trackDifference(p, i, "isUnicodeIdentifierPart()", "" + UCharacter.isUnicodeIdentifierPart(i), 84 "" + Character.isUnicodeIdentifierPart(i)); 85 if (UCharacter.isUnicodeIdentifierStart(i) != Character.isUnicodeIdentifierStart(i)) 86 trackDifference(p, i, "isUnicodeIdentifierStart()", 87 "" + UCharacter.isUnicodeIdentifierStart(i), "" + Character.isUnicodeIdentifierStart(i)); 88 if (UCharacter.isIdentifierIgnorable(i) != Character.isIdentifierIgnorable(i)) 89 trackDifference(p, i, "isIdentifierIgnorable()", "" + UCharacter.isIdentifierIgnorable(i), "" 90 + Character.isIdentifierIgnorable(i)); 91 if (UCharacter.isUpperCase(i) != Character.isUpperCase(i)) 92 trackDifference(p, i, "isUpperCase()", "" + UCharacter.isUpperCase(i), "" 93 + Character.isUpperCase(i)); 94 if (UCharacter.toLowerCase(i) != Character.toLowerCase(i)) 95 trackDifference(p, i, "toLowerCase()", Integer.toHexString(UCharacter.toLowerCase(i)), Integer 96 .toHexString(Character.toLowerCase(i))); 97 if (!UCharacter.toString(i).equals(new Character(i).toString())) 98 trackDifference(p, i, "toString()", UCharacter.toString(i), new Character(i).toString()); 99 if (UCharacter.toTitleCase(i) != Character.toTitleCase(i)) 100 trackDifference(p, i, "toTitleCase()", Integer.toHexString(UCharacter.toTitleCase(i)), Integer 101 .toHexString(Character.toTitleCase(i))); 102 if (UCharacter.toUpperCase(i) != Character.toUpperCase(i)) 103 trackDifference(p, i, "toUpperCase()", Integer.toHexString(UCharacter.toUpperCase(i)), Integer 104 .toHexString(Character.toUpperCase(i))); 105 } 106 } 107 summary(p); 108 p.close(); 109 } catch (Exception e) { 110 e.printStackTrace(); 111 } 112 } 113 114 // private methods =================================================== 115 116 /** 117 * Comparing types 118 * 119 * @param uchartype 120 * UCharacter type 121 * @param jchartype 122 * java.lang.Character type 123 */ 124 private static boolean compareType(int uchartype, int jchartype) { 125 if (uchartype == UCharacterCategory.UNASSIGNED && jchartype == Character.UNASSIGNED) 126 return true; 127 if (uchartype == UCharacterCategory.UPPERCASE_LETTER && jchartype == Character.UPPERCASE_LETTER) 128 return true; 129 if (uchartype == UCharacterCategory.LOWERCASE_LETTER && jchartype == Character.LOWERCASE_LETTER) 130 return true; 131 if (uchartype == UCharacterCategory.TITLECASE_LETTER && jchartype == Character.TITLECASE_LETTER) 132 return true; 133 if (uchartype == UCharacterCategory.MODIFIER_LETTER && jchartype == Character.MODIFIER_LETTER) 134 return true; 135 if (uchartype == UCharacterCategory.OTHER_LETTER && jchartype == Character.OTHER_LETTER) 136 return true; 137 if (uchartype == UCharacterCategory.NON_SPACING_MARK && jchartype == Character.NON_SPACING_MARK) 138 return true; 139 if (uchartype == UCharacterCategory.ENCLOSING_MARK && jchartype == Character.ENCLOSING_MARK) 140 return true; 141 if (uchartype == UCharacterCategory.COMBINING_SPACING_MARK && jchartype == Character.COMBINING_SPACING_MARK) 142 return true; 143 if (uchartype == UCharacterCategory.DECIMAL_DIGIT_NUMBER && jchartype == Character.DECIMAL_DIGIT_NUMBER) 144 return true; 145 if (uchartype == UCharacterCategory.LETTER_NUMBER && jchartype == Character.LETTER_NUMBER) 146 return true; 147 if (uchartype == UCharacterCategory.OTHER_NUMBER && jchartype == Character.OTHER_NUMBER) 148 return true; 149 if (uchartype == UCharacterCategory.SPACE_SEPARATOR && jchartype == Character.SPACE_SEPARATOR) 150 return true; 151 if (uchartype == UCharacterCategory.LINE_SEPARATOR && jchartype == Character.LINE_SEPARATOR) 152 return true; 153 if (uchartype == UCharacterCategory.PARAGRAPH_SEPARATOR && jchartype == Character.PARAGRAPH_SEPARATOR) 154 return true; 155 if (uchartype == UCharacterCategory.CONTROL && jchartype == Character.CONTROL) 156 return true; 157 if (uchartype == UCharacterCategory.FORMAT && jchartype == Character.FORMAT) 158 return true; 159 if (uchartype == UCharacterCategory.PRIVATE_USE && jchartype == Character.PRIVATE_USE) 160 return true; 161 if (uchartype == UCharacterCategory.SURROGATE && jchartype == Character.SURROGATE) 162 return true; 163 if (uchartype == UCharacterCategory.DASH_PUNCTUATION && jchartype == Character.DASH_PUNCTUATION) 164 return true; 165 if (uchartype == UCharacterCategory.START_PUNCTUATION && jchartype == Character.START_PUNCTUATION) 166 return true; 167 if (uchartype == UCharacterCategory.END_PUNCTUATION && jchartype == Character.END_PUNCTUATION) 168 return true; 169 if (uchartype == UCharacterCategory.CONNECTOR_PUNCTUATION && jchartype == Character.CONNECTOR_PUNCTUATION) 170 return true; 171 if (uchartype == UCharacterCategory.OTHER_PUNCTUATION && jchartype == Character.OTHER_PUNCTUATION) 172 return true; 173 if (uchartype == UCharacterCategory.MATH_SYMBOL && jchartype == Character.MATH_SYMBOL) 174 return true; 175 if (uchartype == UCharacterCategory.CURRENCY_SYMBOL && jchartype == Character.CURRENCY_SYMBOL) 176 return true; 177 if (uchartype == UCharacterCategory.MODIFIER_SYMBOL && jchartype == Character.MODIFIER_SYMBOL) 178 return true; 179 if (uchartype == UCharacterCategory.OTHER_SYMBOL && jchartype == Character.OTHER_SYMBOL) 180 return true; 181 if (uchartype == UCharacterCategory.INITIAL_PUNCTUATION && jchartype == Character.START_PUNCTUATION) 182 return true; 183 if (uchartype == UCharacterCategory.FINAL_PUNCTUATION && jchartype == Character.END_PUNCTUATION) 184 return true; 185 /* 186 * if (uchartype == UCharacterCategory.GENERAL_OTHER_TYPES && jchartype == Character.GENERAL_OTHER_TYPES) return 187 * true; 188 */ 189 return false; 190 } 191 192 /** 193 * Difference writing to file 194 * 195 * @param f 196 * file outputstream 197 * @param ch 198 * code point 199 * @param method 200 * for testing 201 * @param ucharval 202 * UCharacter value after running method 203 * @param charval 204 * Character value after running method 205 */ 206 private static void trackDifference(PrintWriter f, int ch, String method, String ucharval, String charval) 207 throws Exception { 208 if (m_hashtable_.containsKey(method)) { 209 Integer value = m_hashtable_.get(method); 210 m_hashtable_.put(method, new Integer(value.intValue() + 1)); 211 } else 212 m_hashtable_.put(method, new Integer(1)); 213 214 String temp = Integer.toHexString(ch); 215 StringBuffer s = new StringBuffer(temp); 216 for (int i = 0; i < 6 - temp.length(); i++) 217 s.append(' '); 218 temp = UCharacter.getExtendedName(ch); 219 if (temp == null) 220 temp = " "; 221 s.append(temp); 222 for (int i = 0; i < 73 - temp.length(); i++) 223 s.append(' '); 224 225 s.append(method); 226 for (int i = 0; i < 27 - method.length(); i++) 227 s.append(' '); 228 s.append(ucharval); 229 for (int i = 0; i < 11 - ucharval.length(); i++) 230 s.append(' '); 231 s.append(charval); 232 f.println(s.toString()); 233 } 234 235 /** 236 * Does up a summary of the differences 237 * 238 * @param f 239 * file outputstream 240 */ 241 private static void summary(PrintWriter f) { 242 f.println("=================================================="); 243 f.println("Summary of differences"); 244 for (String s : m_hashtable_.keySet()) { 245 StringBuilder method = new StringBuilder(s); 246 int count = (m_hashtable_.get(s)).intValue(); 247 for (int i = 30 - method.length(); i > 0; i--) 248 method.append(' '); 249 f.println(method + " " + count); 250 } 251 } 252} 253 254