1 7 package com.ibm.icu.text; 8 9 import com.ibm.icu.impl.ICUResourceBundle; 10 import com.ibm.icu.util.Currency; 11 import com.ibm.icu.util.ULocale; 12 import com.ibm.icu.util.UResourceBundle; 13 14 import java.io.IOException ; 15 import java.io.ObjectInputStream ; 16 import java.io.Serializable ; 17 import java.text.ChoiceFormat ; 18 import java.util.Hashtable ; 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 22 42 43 final public class DecimalFormatSymbols implements Cloneable , Serializable { 44 45 49 public DecimalFormatSymbols() { 50 initialize( ULocale.getDefault() ); 51 } 52 53 58 public DecimalFormatSymbols( Locale locale ) { 59 initialize( ULocale.forLocale(locale) ); 60 } 61 62 68 public DecimalFormatSymbols( ULocale locale ) { 69 initialize( locale ); 70 } 71 72 77 public char getZeroDigit() { 78 return zeroDigit; 79 } 80 81 86 public void setZeroDigit(char zeroDigit) { 87 this.zeroDigit = zeroDigit; 88 } 89 90 95 public char getSignificantDigit() { 96 return sigDigit; 97 } 98 99 104 public void setSignificantDigit(char sigDigit) { 105 this.sigDigit = sigDigit; 106 } 107 108 113 public char getGroupingSeparator() { 114 return groupingSeparator; 115 } 116 117 122 public void setGroupingSeparator(char groupingSeparator) { 123 this.groupingSeparator = groupingSeparator; 124 } 125 126 131 public char getDecimalSeparator() { 132 return decimalSeparator; 133 } 134 135 140 public void setDecimalSeparator(char decimalSeparator) { 141 this.decimalSeparator = decimalSeparator; 142 } 143 144 149 public char getPerMill() { 150 return perMill; 151 } 152 153 158 public void setPerMill(char perMill) { 159 this.perMill = perMill; 160 } 161 162 167 public char getPercent() { 168 return percent; 169 } 170 171 176 public void setPercent(char percent) { 177 this.percent = percent; 178 } 179 180 185 public char getDigit() { 186 return digit; 187 } 188 189 194 public void setDigit(char digit) { 195 this.digit = digit; 196 } 197 198 204 public char getPatternSeparator() { 205 return patternSeparator; 206 } 207 208 214 public void setPatternSeparator(char patternSeparator) { 215 this.patternSeparator = patternSeparator; 216 } 217 218 224 226 public String getInfinity() { 227 return infinity; 228 } 229 230 236 public void setInfinity(String infinity) { 237 this.infinity = infinity; 238 } 239 240 246 public String getNaN() { 248 return NaN; 249 } 250 251 257 public void setNaN(String NaN) { 258 this.NaN = NaN; 259 } 260 261 268 public char getMinusSign() { 269 return minusSign; 270 } 271 272 279 public void setMinusSign(char minusSign) { 280 this.minusSign = minusSign; 281 } 282 283 288 public String getCurrencySymbol() 289 { 290 return currencySymbol; 291 } 292 293 298 public void setCurrencySymbol(String currency) 299 { 300 currencySymbol = currency; 301 } 302 303 308 public String getInternationalCurrencySymbol() 309 { 310 return intlCurrencySymbol; 311 } 312 313 318 public void setInternationalCurrencySymbol(String currency) 319 { 320 intlCurrencySymbol = currency; 321 } 322 323 330 public Currency getCurrency() { 331 return currency; 332 } 333 334 351 public void setCurrency(Currency currency) { 352 if (currency == null) { 353 throw new NullPointerException (); 354 } 355 this.currency = currency; 356 intlCurrencySymbol = currency.getCurrencyCode(); 357 currencySymbol = currency.getSymbol(locale); 358 } 359 360 365 public char getMonetaryDecimalSeparator() 366 { 367 return monetarySeparator; 368 } 369 370 376 public char getMonetaryGroupingSeparator() 377 { 378 return monetaryGroupingSeparator; 379 } 380 381 386 String getCurrencyPattern(){ 387 return currencyPattern; 388 } 389 394 public void setMonetaryDecimalSeparator(char sep) 395 { 396 monetarySeparator = sep; 397 } 398 404 public void setMonetaryGroupingSeparator(char sep) 405 { 406 monetaryGroupingSeparator = sep; 407 } 408 409 418 public String getExponentSeparator() 419 { 420 return exponentSeparator; 421 } 422 423 432 public void setExponentSeparator(String exp) 433 { 434 exponentSeparator = exp; 435 } 436 437 447 public char getPlusSign() { 448 return plusSign; 449 } 450 451 461 public void setPlusSign(char plus) { 462 plusSign = plus; 463 } 464 465 478 public char getPadEscape() { 479 return padEscape; 480 } 481 482 494 public void setPadEscape(char c) { 495 padEscape = c; 496 } 497 498 503 public Locale getLocale() { 504 return locale; 505 } 506 507 513 public ULocale getULocale() { 514 return ulocale; 515 } 516 517 521 public Object clone() { 522 try { 523 return (DecimalFormatSymbols) super.clone(); 524 } catch (CloneNotSupportedException e) { 526 throw new IllegalStateException (); 528 } 530 } 531 532 536 public boolean equals(Object obj) { 537 if (obj == null) return false; 538 if (this == obj) return true; 539 DecimalFormatSymbols other = (DecimalFormatSymbols) obj; 540 return (zeroDigit == other.zeroDigit && 541 groupingSeparator == other.groupingSeparator && 542 decimalSeparator == other.decimalSeparator && 543 percent == other.percent && 544 perMill == other.perMill && 545 digit == other.digit && 546 minusSign == other.minusSign && 547 patternSeparator == other.patternSeparator && 548 infinity.equals(other.infinity) && 549 NaN.equals(other.NaN) && 550 currencySymbol.equals(other.currencySymbol) && 551 intlCurrencySymbol.equals(other.intlCurrencySymbol) && 552 padEscape == other.padEscape && plusSign == other.plusSign && exponentSeparator.equals(other.exponentSeparator) && monetarySeparator == other.monetarySeparator); 556 } 557 558 562 public int hashCode() { 563 int result = zeroDigit; 564 result = result * 37 + groupingSeparator; 565 result = result * 37 + decimalSeparator; 566 return result; 567 } 568 569 574 private void initialize( ULocale locale ) { 575 this.locale = locale.toLocale(); 576 this.ulocale = locale; 577 578 579 String [][] data = (String [][]) cachedLocaleData.get(locale); 580 String [] numberElements; 581 if (data == null) { 582 data = new String [1][]; 583 ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle. 584 getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 585 data[0] = rb.getStringArray("NumberElements"); 586 587 cachedLocaleData.put(locale, data); 588 } 589 numberElements = data[0]; 590 591 ICUResourceBundle r = (ICUResourceBundle)UResourceBundle. 592 getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 593 594 ULocale uloc = r.getULocale(); 596 setLocale(uloc, uloc); 597 598 decimalSeparator = numberElements[0].charAt(0); 600 groupingSeparator = numberElements[1].charAt(0); 601 patternSeparator = numberElements[2].charAt(0); 605 percent = numberElements[3].charAt(0); 606 zeroDigit = numberElements[4].charAt(0); digit = numberElements[5].charAt(0); 608 minusSign = numberElements[6].charAt(0); 609 610 exponentSeparator = numberElements[7]; 620 perMill = numberElements[8].charAt(0); 621 infinity = numberElements[9]; 622 NaN = numberElements[10]; 623 624 plusSign =numberElements[11].charAt(0); 625 padEscape = DecimalFormat.PATTERN_PAD_ESCAPE; 626 sigDigit = DecimalFormat.PATTERN_SIGNIFICANT_DIGIT; 627 628 String currname = null; 632 currency = Currency.getInstance(locale); 633 if (currency != null) { 634 intlCurrencySymbol = currency.getCurrencyCode(); 635 boolean[] isChoiceFormat = new boolean[1]; 636 currname = currency.getName(locale, 637 Currency.SYMBOL_NAME, 638 isChoiceFormat); 639 currencySymbol = isChoiceFormat[0] 642 ? new ChoiceFormat (currname).format(2.0) 643 : currname; 644 } else { 645 intlCurrencySymbol = "XXX"; 646 currencySymbol = "\u00A4"; } 648 monetarySeparator = decimalSeparator; 650 monetaryGroupingSeparator = groupingSeparator; 651 Currency curr = Currency.getInstance(locale); 652 if(curr!=null){ 653 String currencyCode = curr.getCurrencyCode(); 654 if(currencyCode != null) { 655 656 ICUResourceBundle resource = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 657 ICUResourceBundle currency = resource.getWithFallback("Currencies"); 658 try{ 659 currency = currency.getWithFallback(currencyCode); 660 if(currency.getSize()>2) { 661 currency = currency.get(2); 662 currencyPattern = currency.getString(0); 663 monetarySeparator = currency.getString(1).charAt(0); 664 monetaryGroupingSeparator = currency.getString(2).charAt(0); 665 } 666 }catch(MissingResourceException ex){ 667 668 669 } 670 } 671 672 } 673 } 675 676 684 private void readObject(ObjectInputStream stream) 685 throws IOException , ClassNotFoundException { 686 687 690 stream.defaultReadObject(); 691 if (serialVersionOnStream < 1) { 694 monetarySeparator = decimalSeparator; 697 exponential = 'E'; 698 } 699 if (serialVersionOnStream < 2) { 700 padEscape = DecimalFormat.PATTERN_PAD_ESCAPE; 701 plusSign = DecimalFormat.PATTERN_PLUS_SIGN; 702 exponentSeparator = String.valueOf(exponential); 703 } 708 if (serialVersionOnStream < 3) { 710 locale = Locale.getDefault(); 716 } 717 if (serialVersionOnStream < 4) { 718 ulocale = ULocale.forLocale(locale); 720 } 721 if (serialVersionOnStream < 5) { 722 monetaryGroupingSeparator = groupingSeparator; 724 } 725 serialVersionOnStream = currentSerialVersion; 726 727 currency = Currency.getInstance(intlCurrencySymbol); 729 } 730 731 737 private char zeroDigit; 738 739 745 private char groupingSeparator; 746 747 753 private char decimalSeparator; 754 755 761 private char perMill; 762 763 768 private char percent; 769 770 776 private char digit; 777 778 784 private char sigDigit; 785 786 793 private char patternSeparator; 794 795 800 private String infinity; 801 802 807 private String NaN; 808 809 814 private char minusSign; 815 816 821 private String currencySymbol; 822 823 828 private String intlCurrencySymbol; 829 830 835 private char monetarySeparator; 837 842 private char monetaryGroupingSeparator; 844 853 private char exponential; 855 864 private String exponentSeparator; 865 866 873 private char padEscape; 874 875 881 private char plusSign; 882 883 888 private Locale locale; 889 890 894 private ULocale ulocale; 895 896 private static final long serialVersionUID = 5772796243397350300L; 898 899 private static final int currentSerialVersion = 5; 909 910 927 private int serialVersionOnStream = currentSerialVersion; 928 929 932 private static final Hashtable cachedLocaleData = new Hashtable (3); 933 934 937 private String currencyPattern = null; 938 939 941 965 public final ULocale getLocale(ULocale.Type type) { 966 return type == ULocale.ACTUAL_LOCALE ? 967 this.actualLocale : this.validLocale; 968 } 969 970 987 final void setLocale(ULocale valid, ULocale actual) { 988 if ((valid == null) != (actual == null)) { 990 throw new IllegalArgumentException (); 992 } 994 this.validLocale = valid; 997 this.actualLocale = actual; 998 } 999 1000 1005 private ULocale validLocale; 1006 1007 1013 private ULocale actualLocale; 1014 1015 private transient Currency currency; 1017 1018 } 1020 | Popular Tags |