1 7 8 package com.ibm.icu.util; 9 10 import java.util.HashMap ; 11 12 17 public final class VersionInfo 18 { 19 21 25 public static final VersionInfo UNICODE_1_0; 26 30 public static final VersionInfo UNICODE_1_0_1; 31 35 public static final VersionInfo UNICODE_1_1_0; 36 40 public static final VersionInfo UNICODE_1_1_5; 41 45 public static final VersionInfo UNICODE_2_0; 46 50 public static final VersionInfo UNICODE_2_1_2; 51 55 public static final VersionInfo UNICODE_2_1_5; 56 60 public static final VersionInfo UNICODE_2_1_8; 61 65 public static final VersionInfo UNICODE_2_1_9; 66 70 public static final VersionInfo UNICODE_3_0; 71 75 public static final VersionInfo UNICODE_3_0_1; 76 80 public static final VersionInfo UNICODE_3_1_0; 81 85 public static final VersionInfo UNICODE_3_1_1; 86 90 public static final VersionInfo UNICODE_3_2; 91 92 96 public static final VersionInfo UNICODE_4_0; 97 98 103 public static final VersionInfo UNICODE_4_0_1; 104 105 110 public static final VersionInfo UNICODE_4_1; 111 112 117 public static final VersionInfo UNICODE_5_0; 118 119 123 public static final VersionInfo ICU_VERSION; 124 125 130 public static final String ICU_DATA_VERSION = "36b"; 131 132 136 public static final VersionInfo UCOL_RUNTIME_VERSION; 137 138 142 public static final VersionInfo UCOL_BUILDER_VERSION; 143 144 148 public static final VersionInfo UCOL_TAILORINGS_VERSION; 149 150 151 153 166 public static VersionInfo getInstance(String version) 167 { 168 int length = version.length(); 169 int array[] = {0, 0, 0, 0}; 170 int count = 0; 171 int index = 0; 172 173 while (count < 4 && index < length) { 174 char c = version.charAt(index); 175 if (c == '.') { 176 count ++; 177 } 178 else { 179 c -= '0'; 180 if (c < 0 || c > 9) { 181 throw new IllegalArgumentException (INVALID_VERSION_NUMBER_); 182 } 183 array[count] *= 10; 184 array[count] += c; 185 } 186 index ++; 187 } 188 if (index != length) { 189 throw new IllegalArgumentException ( 190 "Invalid version number: String '" + version + "' exceeds version format"); 191 } 192 for (int i = 0; i < 4; i ++) { 193 if (array[i] < 0 || array[i] > 255) { 194 throw new IllegalArgumentException (INVALID_VERSION_NUMBER_); 195 } 196 } 197 198 return getInstance(array[0], array[1], array[2], array[3]); 199 } 200 201 211 public static VersionInfo getInstance(int major, int minor, int milli, 212 int micro) 213 { 214 if (major < 0 || major > 255 || minor < 0 || minor > 255 || 217 milli < 0 || milli > 255 || micro < 0 || micro > 255) { 218 throw new IllegalArgumentException (INVALID_VERSION_NUMBER_); 219 } 220 int version = getInt(major, minor, milli, micro); 221 Integer key = new Integer (version); 222 Object result = MAP_.get(key); 223 if (result == null) { 224 result = new VersionInfo(version); 225 MAP_.put(key, result); 226 } 227 return (VersionInfo)result; 228 } 229 230 240 public static VersionInfo getInstance(int major, int minor, int milli) 241 { 242 return getInstance(major, minor, milli, 0); 243 } 244 245 254 public static VersionInfo getInstance(int major, int minor) 255 { 256 return getInstance(major, minor, 0, 0); 257 } 258 259 267 public static VersionInfo getInstance(int major) 268 { 269 return getInstance(major, 0, 0, 0); 270 } 271 272 private static VersionInfo javaVersion; 273 274 278 public static VersionInfo javaVersion() { 279 if (javaVersion == null) { 280 String s = System.getProperty("java.version"); 281 286 char[] chars = s.toCharArray(); 287 int r = 0, w = 0, count = 0; 288 boolean numeric = false; while (r < chars.length) { 290 char c = chars[r++]; 291 if (c < '0' || c > '9') { 292 if (numeric) { 293 if (count == 3) { 294 break; 296 } 297 numeric = false; 298 chars[w++] = '.'; 299 ++count; 300 } 301 } else { 302 numeric = true; 303 chars[w++] = c; 304 } 305 } 306 while (w > 0 && chars[w-1] == '.') { 307 --w; 308 } 309 310 String vs = new String (chars, 0, w); 311 312 javaVersion = VersionInfo.getInstance(vs); 313 } 314 return javaVersion; 315 } 316 317 323 public String toString() 324 { 325 StringBuffer result = new StringBuffer (7); 326 result.append(getMajor()); 327 result.append('.'); 328 result.append(getMinor()); 329 result.append('.'); 330 result.append(getMilli()); 331 result.append('.'); 332 result.append(getMicro()); 333 return result.toString(); 334 } 335 336 341 public int getMajor() 342 { 343 return (m_version_ >> 24) & LAST_BYTE_MASK_ ; 344 } 345 346 351 public int getMinor() 352 { 353 return (m_version_ >> 16) & LAST_BYTE_MASK_ ; 354 } 355 356 361 public int getMilli() 362 { 363 return (m_version_ >> 8) & LAST_BYTE_MASK_ ; 364 } 365 366 371 public int getMicro() 372 { 373 return m_version_ & LAST_BYTE_MASK_ ; 374 } 375 376 383 public boolean equals(Object other) 384 { 385 return other == this; 386 } 387 388 399 public int compareTo(VersionInfo other) 400 { 401 return m_version_ - other.m_version_; 402 } 403 404 406 412 private int m_version_; 413 416 private static final HashMap MAP_ = new HashMap (); 417 420 private static final int LAST_BYTE_MASK_ = 0xFF; 421 424 private static final String INVALID_VERSION_NUMBER_ = 425 "Invalid version number: Version number may be negative or greater than 255"; 426 427 429 432 static { 433 UNICODE_1_0 = getInstance(1, 0, 0, 0); 434 UNICODE_1_0_1 = getInstance(1, 0, 1, 0); 435 UNICODE_1_1_0 = getInstance(1, 1, 0, 0); 436 UNICODE_1_1_5 = getInstance(1, 1, 5, 0); 437 UNICODE_2_0 = getInstance(2, 0, 0, 0); 438 UNICODE_2_1_2 = getInstance(2, 1, 2, 0); 439 UNICODE_2_1_5 = getInstance(2, 1, 5, 0); 440 UNICODE_2_1_8 = getInstance(2, 1, 8, 0); 441 UNICODE_2_1_9 = getInstance(2, 1, 9, 0); 442 UNICODE_3_0 = getInstance(3, 0, 0, 0); 443 UNICODE_3_0_1 = getInstance(3, 0, 1, 0); 444 UNICODE_3_1_0 = getInstance(3, 1, 0, 0); 445 UNICODE_3_1_1 = getInstance(3, 1, 1, 0); 446 UNICODE_3_2 = getInstance(3, 2, 0, 0); 447 UNICODE_4_0 = getInstance(4, 0, 0, 0); 448 UNICODE_4_0_1 = getInstance(4, 0, 1, 0); 449 UNICODE_4_1 = getInstance(4, 1, 0, 0); 450 UNICODE_5_0 = getInstance(4, 1, 0, 0); 451 ICU_VERSION = getInstance(3, 6, 1, 0); 452 UCOL_RUNTIME_VERSION = getInstance(6); 453 UCOL_BUILDER_VERSION = getInstance(7); 454 UCOL_TAILORINGS_VERSION = getInstance(1); 455 } 456 457 459 463 private VersionInfo(int compactversion) 464 { 465 m_version_ = compactversion; 466 } 467 468 475 private static int getInt(int major, int minor, int milli, int micro) 476 { 477 return (major << 24) | (minor << 16) | (milli << 8) | micro; 478 } 479 } 480 | Popular Tags |