1 7 8 20 21 package java.text; 22 23 import java.io.IOException ; 24 import java.io.ObjectInputStream ; 25 import java.io.Serializable ; 26 import java.util.Currency ; 27 import java.util.Hashtable ; 28 import java.util.Locale ; 29 import java.util.ResourceBundle ; 30 import sun.text.resources.LocaleData; 31 32 46 47 final public class DecimalFormatSymbols implements Cloneable , Serializable { 48 49 52 public DecimalFormatSymbols() { 53 initialize( Locale.getDefault() ); 54 } 55 56 61 public DecimalFormatSymbols( Locale locale ) { 62 initialize( locale ); 63 } 64 65 68 public char getZeroDigit() { 69 return zeroDigit; 70 } 71 72 75 public void setZeroDigit(char zeroDigit) { 76 this.zeroDigit = zeroDigit; 77 } 78 79 82 public char getGroupingSeparator() { 83 return groupingSeparator; 84 } 85 86 89 public void setGroupingSeparator(char groupingSeparator) { 90 this.groupingSeparator = groupingSeparator; 91 } 92 93 96 public char getDecimalSeparator() { 97 return decimalSeparator; 98 } 99 100 103 public void setDecimalSeparator(char decimalSeparator) { 104 this.decimalSeparator = decimalSeparator; 105 } 106 107 110 public char getPerMill() { 111 return perMill; 112 } 113 114 117 public void setPerMill(char perMill) { 118 this.perMill = perMill; 119 } 120 121 124 public char getPercent() { 125 return percent; 126 } 127 128 131 public void setPercent(char percent) { 132 this.percent = percent; 133 } 134 135 138 public char getDigit() { 139 return digit; 140 } 141 142 145 public void setDigit(char digit) { 146 this.digit = digit; 147 } 148 149 153 public char getPatternSeparator() { 154 return patternSeparator; 155 } 156 157 161 public void setPatternSeparator(char patternSeparator) { 162 this.patternSeparator = patternSeparator; 163 } 164 165 169 public String getInfinity() { 170 return infinity; 171 } 172 173 177 public void setInfinity(String infinity) { 178 this.infinity = infinity; 179 } 180 181 185 public String getNaN() { 186 return NaN; 187 } 188 189 193 public void setNaN(String NaN) { 194 this.NaN = NaN; 195 } 196 197 202 public char getMinusSign() { 203 return minusSign; 204 } 205 206 211 public void setMinusSign(char minusSign) { 212 this.minusSign = minusSign; 213 } 214 215 220 public String getCurrencySymbol() 221 { 222 return currencySymbol; 223 } 224 225 230 public void setCurrencySymbol(String currency) 231 { 232 currencySymbol = currency; 233 } 234 235 240 public String getInternationalCurrencySymbol() 241 { 242 return intlCurrencySymbol; 243 } 244 245 260 public void setInternationalCurrencySymbol(String currencyCode) 261 { 262 intlCurrencySymbol = currencyCode; 263 currency = null; 264 if (currencyCode != null) { 265 try { 266 currency = Currency.getInstance(currencyCode); 267 currencySymbol = currency.getSymbol(); 268 } catch (IllegalArgumentException e) { 269 } 270 } 271 } 272 273 281 public Currency getCurrency() { 282 return currency; 283 } 284 285 297 public void setCurrency(Currency currency) { 298 if (currency == null) { 299 throw new NullPointerException (); 300 } 301 this.currency = currency; 302 intlCurrencySymbol = currency.getCurrencyCode(); 303 currencySymbol = currency.getSymbol(locale); 304 } 305 306 307 311 public char getMonetaryDecimalSeparator() 312 { 313 return monetarySeparator; 314 } 315 316 320 public void setMonetaryDecimalSeparator(char sep) 321 { 322 monetarySeparator = sep; 323 } 324 325 329 332 char getExponentialSymbol() 333 { 334 return exponential; 335 } 336 337 340 void setExponentialSymbol(char exp) 341 { 342 exponential = exp; 343 } 344 345 346 350 353 public Object clone() { 354 try { 355 return (DecimalFormatSymbols )super.clone(); 356 } catch (CloneNotSupportedException e) { 358 throw new InternalError (); 359 } 360 } 361 362 365 public boolean equals(Object obj) { 366 if (obj == null) return false; 367 if (this == obj) return true; 368 if (getClass() != obj.getClass()) return false; 369 DecimalFormatSymbols other = (DecimalFormatSymbols ) obj; 370 return (zeroDigit == other.zeroDigit && 371 groupingSeparator == other.groupingSeparator && 372 decimalSeparator == other.decimalSeparator && 373 percent == other.percent && 374 perMill == other.perMill && 375 digit == other.digit && 376 minusSign == other.minusSign && 377 patternSeparator == other.patternSeparator && 378 infinity.equals(other.infinity) && 379 NaN.equals(other.NaN) && 380 currencySymbol.equals(other.currencySymbol) && 381 intlCurrencySymbol.equals(other.intlCurrencySymbol) && 382 currency == other.currency && 383 monetarySeparator == other.monetarySeparator && 384 locale.equals(other.locale)); 385 } 386 387 390 public int hashCode() { 391 int result = zeroDigit; 392 result = result * 37 + groupingSeparator; 393 result = result * 37 + decimalSeparator; 394 return result; 395 } 396 397 400 private void initialize( Locale locale ) { 401 this.locale = locale; 402 403 boolean needCacheUpdate = false; 405 Object [] data = (Object []) cachedLocaleData.get(locale); 406 if (data == null) { 407 data = new Object [3]; 408 ResourceBundle rb = LocaleData.getLocaleElements(locale); 409 data[0] = rb.getStringArray("NumberElements"); 410 needCacheUpdate = true; 411 } 412 413 String [] numberElements = (String []) data[0];; 414 415 decimalSeparator = numberElements[0].charAt(0); 416 groupingSeparator = numberElements[1].charAt(0); 417 patternSeparator = numberElements[2].charAt(0); 418 percent = numberElements[3].charAt(0); 419 zeroDigit = numberElements[4].charAt(0); digit = numberElements[5].charAt(0); 421 minusSign = numberElements[6].charAt(0); 422 exponential = numberElements[7].charAt(0); 423 perMill = numberElements[8].charAt(0); 424 infinity = numberElements[9]; 425 NaN = numberElements[10]; 426 427 if (!"".equals(locale.getCountry())) { 432 try { 433 currency = Currency.getInstance(locale); 434 } catch (IllegalArgumentException e) { 435 } 437 } 438 if (currency != null) { 439 intlCurrencySymbol = currency.getCurrencyCode(); 440 if (data[1] != null && data[1] == intlCurrencySymbol) { 441 currencySymbol = (String ) data[2]; 442 } else { 443 currencySymbol = currency.getSymbol(locale); 444 data[1] = intlCurrencySymbol; 445 data[2] = currencySymbol; 446 needCacheUpdate = true; 447 } 448 } else { 449 intlCurrencySymbol = "XXX"; 451 try { 452 currency = Currency.getInstance(intlCurrencySymbol); 453 } catch (IllegalArgumentException e) { 454 } 455 currencySymbol = "\u00A4"; 456 } 457 monetarySeparator = decimalSeparator; 461 462 if (needCacheUpdate) { 463 cachedLocaleData.put(locale, data); 464 } 465 } 466 467 482 private void readObject(ObjectInputStream stream) 483 throws IOException , ClassNotFoundException { 484 stream.defaultReadObject(); 485 if (serialVersionOnStream < 1) { 486 monetarySeparator = decimalSeparator; 489 exponential = 'E'; 490 } 491 if (serialVersionOnStream < 2) { 492 locale = new Locale (""); 494 } 495 serialVersionOnStream = currentSerialVersion; 496 497 if (intlCurrencySymbol != null) { 498 try { 499 currency = Currency.getInstance(intlCurrencySymbol); 500 } catch (IllegalArgumentException e) { 501 } 502 } 503 } 504 505 511 private char zeroDigit; 512 513 519 private char groupingSeparator; 520 521 527 private char decimalSeparator; 528 529 535 private char perMill; 536 537 542 private char percent; 543 544 550 private char digit; 551 552 559 private char patternSeparator; 560 561 566 private String infinity; 567 568 573 private String NaN; 574 575 580 private char minusSign; 581 582 587 private String currencySymbol; 588 589 594 private String intlCurrencySymbol; 595 596 602 private char monetarySeparator; 604 615 private char exponential; 617 623 private Locale locale; 624 625 private transient Currency currency; 627 628 static final long serialVersionUID = 5772796243397350300L; 630 631 private static final int currentSerialVersion = 2; 637 638 656 private int serialVersionOnStream = currentSerialVersion; 657 658 662 private static final Hashtable cachedLocaleData = new Hashtable (3); 663 } 664 | Popular Tags |