KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > text > DecimalFormatSymbols


1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2006, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  *******************************************************************************
6  */

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 JavaDoc;
15 import java.io.ObjectInputStream JavaDoc;
16 import java.io.Serializable JavaDoc;
17 import java.text.ChoiceFormat JavaDoc;
18 import java.util.Hashtable JavaDoc;
19 import java.util.Locale JavaDoc;
20 import java.util.MissingResourceException JavaDoc;
21
22 /**
23  * This class represents the set of symbols (such as the decimal separator, the
24  * grouping separator, and so on) needed by <code>DecimalFormat</code> to format
25  * numbers. <code>DecimalFormat</code> creates for itself an instance of
26  * <code>DecimalFormatSymbols</code> from its locale data. If you need to
27  * change any of these symbols, you can get the
28  * <code>DecimalFormatSymbols</code> object from your <code>DecimalFormat</code>
29  * and modify it.
30  *
31  * <p><strong>This is an enhanced version of <code>DecimalFormatSymbols</code> that
32  * is based on the standard version in the JDK. New or changed functionality
33  * is labeled
34  * <strong><font face=helvetica color=red>NEW</font></strong>.</strong>
35  *
36  * @see java.util.Locale
37  * @see DecimalFormat
38  * @author Mark Davis
39  * @author Alan Liu
40  * @stable ICU 2.0
41  */

42
43 final public class DecimalFormatSymbols implements Cloneable JavaDoc, Serializable JavaDoc {
44
45     /**
46      * Create a DecimalFormatSymbols object for the default locale.
47      * @stable ICU 2.0
48      */

49     public DecimalFormatSymbols() {
50         initialize( ULocale.getDefault() );
51     }
52
53     /**
54      * Create a DecimalFormatSymbols object for the given locale.
55      * @param locale the locale
56      * @stable ICU 2.0
57      */

58     public DecimalFormatSymbols( Locale locale ) {
59         initialize( ULocale.forLocale(locale) );
60     }
61
62     /**
63      * Create a DecimalFormatSymbols object for the given locale.
64      * @param locale the locale
65      * @draft ICU 3.2
66      * @provisional This API might change or be removed in a future release.
67      */

68     public DecimalFormatSymbols( ULocale locale ) {
69         initialize( locale );
70     }
71
72     /**
73      * Return the character used for zero. Different for Arabic, etc.
74      * @return the character
75      * @stable ICU 2.0
76      */

77     public char getZeroDigit() {
78         return zeroDigit;
79     }
80
81     /**
82      * Set the character used for zero.
83      * @param zeroDigit the zero character.
84      * @stable ICU 2.0
85      */

86     public void setZeroDigit(char zeroDigit) {
87         this.zeroDigit = zeroDigit;
88     }
89
90     /**
91      * Return the character used to represent a significant digit in a pattern.
92      * @return the significant digit pattern character
93      * @stable ICU 3.0
94      */

95     public char getSignificantDigit() {
96         return sigDigit;
97     }
98
99     /**
100      * Set the character used to represent a significant digit in a pattern.
101      * @param sigDigit the significant digit pattern character
102      * @stable ICU 3.0
103      */

104     public void setSignificantDigit(char sigDigit) {
105         this.sigDigit = sigDigit;
106     }
107     
108     /**
109      * Return the character used for thousands separator. Different for French, etc.
110      * @return the thousands character
111      * @stable ICU 2.0
112      */

113     public char getGroupingSeparator() {
114         return groupingSeparator;
115     }
116
117     /**
118      * Set the character used for thousands separator. Different for French, etc.
119      * @param groupingSeparator the thousands character
120      * @stable ICU 2.0
121      */

122     public void setGroupingSeparator(char groupingSeparator) {
123         this.groupingSeparator = groupingSeparator;
124     }
125
126     /**
127      * Return the character used for decimal sign. Different for French, etc.
128      * @return the decimal character
129      * @stable ICU 2.0
130      */

131     public char getDecimalSeparator() {
132         return decimalSeparator;
133     }
134
135     /**
136      * Set the character used for decimal sign. Different for French, etc.
137      * @param decimalSeparator the decimal character
138      * @stable ICU 2.0
139      */

140     public void setDecimalSeparator(char decimalSeparator) {
141         this.decimalSeparator = decimalSeparator;
142     }
143
144     /**
145      * Return the character used for mille percent sign. Different for Arabic, etc.
146      * @return the mille percent character
147      * @stable ICU 2.0
148      */

149     public char getPerMill() {
150         return perMill;
151     }
152
153     /**
154      * Set the character used for mille percent sign. Different for Arabic, etc.
155      * @param perMill the mille percent character
156      * @stable ICU 2.0
157      */

158     public void setPerMill(char perMill) {
159         this.perMill = perMill;
160     }
161
162     /**
163      * Return the character used for percent sign. Different for Arabic, etc.
164      * @return the percent character
165      * @stable ICU 2.0
166      */

167     public char getPercent() {
168         return percent;
169     }
170
171     /**
172      * Set the character used for percent sign. Different for Arabic, etc.
173      * @param percent the percent character
174      * @stable ICU 2.0
175      */

176     public void setPercent(char percent) {
177         this.percent = percent;
178     }
179
180     /**
181      * Return the character used for a digit in a pattern.
182      * @return the digit pattern character
183      * @stable ICU 2.0
184      */

185     public char getDigit() {
186         return digit;
187     }
188
189     /**
190      * Set the character used for a digit in a pattern.
191      * @param digit the digit pattern character
192      * @stable ICU 2.0
193      */

194     public void setDigit(char digit) {
195         this.digit = digit;
196     }
197
198     /**
199      * Return the character used to separate positive and negative subpatterns
200      * in a pattern.
201      * @return the pattern separator character
202      * @stable ICU 2.0
203      */

204     public char getPatternSeparator() {
205         return patternSeparator;
206     }
207
208     /**
209      * Set the character used to separate positive and negative subpatterns
210      * in a pattern.
211      * @param patternSeparator the pattern separator character
212      * @stable ICU 2.0
213      */

214     public void setPatternSeparator(char patternSeparator) {
215         this.patternSeparator = patternSeparator;
216     }
217
218     /**
219      * Return the String used to represent infinity. Almost always left
220      * unchanged.
221      * @return the Infinity string
222      * @stable ICU 2.0
223      */

224      //Bug 4194173 [Richard/GCL]
225

226     public String JavaDoc getInfinity() {
227         return infinity;
228     }
229
230     /**
231      * Set the String used to represent infinity. Almost always left
232      * unchanged.
233      * @param infinity the Infinity String
234      * @stable ICU 2.0
235      */

236     public void setInfinity(String JavaDoc infinity) {
237         this.infinity = infinity;
238     }
239
240     /**
241      * Return the String used to represent NaN. Almost always left
242      * unchanged.
243      * @return the NaN String
244      * @stable ICU 2.0
245      */

246      //Bug 4194173 [Richard/GCL]
247
public String JavaDoc getNaN() {
248         return NaN;
249     }
250
251     /**
252      * Set the String used to represent NaN. Almost always left
253      * unchanged.
254      * @param NaN the NaN String
255      * @stable ICU 2.0
256      */

257     public void setNaN(String JavaDoc NaN) {
258         this.NaN = NaN;
259     }
260
261     /**
262      * Return the character used to represent minus sign. If no explicit
263      * negative format is specified, one is formed by prefixing
264      * minusSign to the positive format.
265      * @return the minus sign character
266      * @stable ICU 2.0
267      */

268     public char getMinusSign() {
269         return minusSign;
270     }
271
272     /**
273      * Set the character used to represent minus sign. If no explicit
274      * negative format is specified, one is formed by prefixing
275      * minusSign to the positive format.
276      * @param minusSign the minus sign character
277      * @stable ICU 2.0
278      */

279     public void setMinusSign(char minusSign) {
280         this.minusSign = minusSign;
281     }
282
283     /**
284      * Return the string denoting the local currency.
285      * @return the local currency String.
286      * @stable ICU 2.0
287      */

288     public String JavaDoc getCurrencySymbol()
289     {
290         return currencySymbol;
291     }
292
293     /**
294      * Set the string denoting the local currency.
295      * @param currency the local currency String.
296      * @stable ICU 2.0
297      */

298     public void setCurrencySymbol(String JavaDoc currency)
299     {
300         currencySymbol = currency;
301     }
302
303     /**
304      * Return the international string denoting the local currency.
305      * @return the international string denoting the local currency
306      * @stable ICU 2.0
307      */

308     public String JavaDoc getInternationalCurrencySymbol()
309     {
310         return intlCurrencySymbol;
311     }
312
313     /**
314      * Set the international string denoting the local currency.
315      * @param currency the international string denoting the local currency.
316      * @stable ICU 2.0
317      */

318     public void setInternationalCurrencySymbol(String JavaDoc currency)
319     {
320         intlCurrencySymbol = currency;
321     }
322
323     /**
324      * Returns the currency symbol, for JDK 1.4 compatibility only.
325      * ICU clients should use the Currency API directly.
326      * @return the currency used, or null
327      * @draft ICU 3.4
328      * @provisional This API might change or be removed in a future release.
329      */

330     public Currency getCurrency() {
331         return currency;
332     }
333     
334     /**
335      * ICU does not use the DecimalFormatSymbols for the
336      * currency any more. This API is present
337      * for API compatibility only.
338      *
339      * This also sets the currency symbol attribute to the currency's symbol
340      * in the DecimalFormatSymbols' locale, and the international currency
341      * symbol attribute to the currency's ISO 4217 currency code.
342      *
343      * @param currency the new currency to be used
344      * @throws NullPointerException if <code>currency</code> is null
345      * @see #setCurrencySymbol
346      * @see #setInternationalCurrencySymbol
347      *
348      * @draft ICU 3.4
349      * @provisional This API might change or be removed in a future release.
350      */

351     public void setCurrency(Currency currency) {
352         if (currency == null) {
353             throw new NullPointerException JavaDoc();
354         }
355         this.currency = currency;
356         intlCurrencySymbol = currency.getCurrencyCode();
357         currencySymbol = currency.getSymbol(locale);
358     }
359     
360     /**
361      * Return the monetary decimal separator.
362      * @return the monetary decimal separator character
363      * @stable ICU 2.0
364      */

365     public char getMonetaryDecimalSeparator()
366     {
367         return monetarySeparator;
368     }
369
370     /**
371      * Return the monetary decimal separator.
372      * @return the monetary decimal separator character
373      * @draft ICU 3.6
374      * @provisional This API might change or be removed in a future release.
375      */

376     public char getMonetaryGroupingSeparator()
377     {
378         return monetaryGroupingSeparator;
379     }
380     
381     /**
382      * Internal API for NumberFormat
383      * @return String currency pattern string
384      * @internal
385      */

386     String JavaDoc getCurrencyPattern(){
387         return currencyPattern;
388     }
389     /**
390      * Set the monetary decimal separator.
391      * @param sep the monetary decimal separator character
392      * @stable ICU 2.0
393      */

394     public void setMonetaryDecimalSeparator(char sep)
395     {
396         monetarySeparator = sep;
397     }
398     /**
399      * Set the monetary decimal separator.
400      * @param sep the monetary decimal separator character
401      * @draft ICU 3.6
402      * @provisional This API might change or be removed in a future release.
403      */

404     public void setMonetaryGroupingSeparator(char sep)
405     {
406         monetaryGroupingSeparator = sep;
407     }
408
409     /**
410      * <strong><font face=helvetica color=red>NEW</font></strong>
411      * Return the string used to separate the mantissa from the exponent.
412      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
413      * @return the localized exponent symbol, used in localized patterns
414      * and formatted strings
415      * @see #setExponentSeparator
416      * @stable ICU 2.0
417      */

418     public String JavaDoc getExponentSeparator()
419     {
420         return exponentSeparator;
421     }
422
423     /**
424      * <strong><font face=helvetica color=red>NEW</font></strong>
425      * Set the string used to separate the mantissa from the exponent.
426      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
427      * @param exp the localized exponent symbol, used in localized patterns
428      * and formatted strings
429      * @see #getExponentSeparator
430      * @stable ICU 2.0
431      */

432     public void setExponentSeparator(String JavaDoc exp)
433     {
434         exponentSeparator = exp;
435     }
436
437     /**
438      * <strong><font face=helvetica color=red>NEW</font></strong>
439      * Return the localized plus sign.
440      * @return the plus sign, used in localized patterns and formatted
441      * strings
442      * @see #setPlusSign
443      * @see #setMinusSign
444      * @see #getMinusSign
445      * @stable ICU 2.0
446      */

447     public char getPlusSign() {
448         return plusSign;
449     }
450
451     /**
452      * <strong><font face=helvetica color=red>NEW</font></strong>
453      * Set the localized plus sign.
454      * @param plus the plus sign, used in localized patterns and formatted
455      * strings
456      * @see #getPlusSign
457      * @see #setMinusSign
458      * @see #getMinusSign
459      * @stable ICU 2.0
460      */

461     public void setPlusSign(char plus) {
462         plusSign = plus;
463     }
464
465     /**
466      * <strong><font face=helvetica color=red>NEW</font></strong>
467      * Return the character used to pad numbers out to a specified width. This
468      * is not the pad character itself; rather, it is the special pattern
469      * character <em>preceding</em> the pad character. In the pattern
470      * "*_#,##0", '*' is the pad escape, and '_' is the pad character.
471      * @return the character
472      * @see #setPadEscape
473      * @see DecimalFormat#getFormatWidth
474      * @see DecimalFormat#getPadPosition
475      * @see DecimalFormat#getPadCharacter
476      * @stable ICU 2.0
477      */

478     public char getPadEscape() {
479         return padEscape;
480     }
481
482     /**
483      * <strong><font face=helvetica color=red>NEW</font></strong>
484      * Set the character used to pad numbers out to a specified width. This is
485      * not the pad character itself; rather, it is the special pattern character
486      * <em>preceding</em> the pad character. In the pattern "*_#,##0", '*' is
487      * the pad escape, and '_' is the pad character.
488      * @see #getPadEscape
489      * @see DecimalFormat#setFormatWidth
490      * @see DecimalFormat#setPadPosition
491      * @see DecimalFormat#setPadCharacter
492      * @stable ICU 2.0
493      */

494     public void setPadEscape(char c) {
495         padEscape = c;
496     }
497
498     /**
499      * Returns the locale for which this object was constructed.
500      * @return the locale for which this object was constructed
501      * @stable ICU 2.0
502      */

503     public Locale getLocale() {
504         return locale;
505     }
506
507     /**
508      * Returns the locale for which this object was constructed.
509      * @return the locale for which this object was constructed
510      * @draft ICU 3.2
511      * @provisional This API might change or be removed in a future release.
512      */

513     public ULocale getULocale() {
514         return ulocale;
515     }
516
517     /**
518      * Standard override.
519      * @stable ICU 2.0
520      */

521     public Object JavaDoc clone() {
522         try {
523             return (DecimalFormatSymbols) super.clone();
524             // other fields are bit-copied
525
} catch (CloneNotSupportedException JavaDoc e) {
526             ///CLOVER:OFF
527
throw new IllegalStateException JavaDoc();
528             ///CLOVER:ON
529
}
530     }
531
532     /**
533      * Override equals.
534      * @stable ICU 2.0
535      */

536     public boolean equals(Object JavaDoc 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 && // [NEW]
553
plusSign == other.plusSign && // [NEW]
554
exponentSeparator.equals(other.exponentSeparator) && // [NEW]
555
monetarySeparator == other.monetarySeparator);
556     }
557
558     /**
559      * Override hashCode
560      * @stable ICU 2.0
561      */

562     public int hashCode() {
563             int result = zeroDigit;
564             result = result * 37 + groupingSeparator;
565             result = result * 37 + decimalSeparator;
566             return result;
567     }
568
569     /**
570      * Initializes the symbols from the LocaleElements resource bundle.
571      * Note: The organization of LocaleElements badly needs to be
572      * cleaned up.
573      */

574     private void initialize( ULocale locale ) {
575         this.locale = locale.toLocale();
576         this.ulocale = locale;
577
578         /* try the cache first */
579         String JavaDoc[][] data = (String JavaDoc[][]) cachedLocaleData.get(locale);
580         String JavaDoc[] numberElements;
581         if (data == null) { /* cache miss */
582             data = new String JavaDoc[1][];
583             ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
584                 getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
585             data[0] = rb.getStringArray("NumberElements");
586             /* update cache */
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         // TODO: Determine actual and valid locale correctly.
595
ULocale uloc = r.getULocale();
596         setLocale(uloc, uloc);
597
598     // {dlf} clean up below now that we have our own resource data
599
decimalSeparator = numberElements[0].charAt(0);
600         groupingSeparator = numberElements[1].charAt(0);
601         // Temporary hack to support old JDK 1.1 resources
602
// patternSeparator = numberElements[2].length() > 0 ?
603
// numberElements[2].charAt(0) : ';';
604
patternSeparator = numberElements[2].charAt(0);
605         percent = numberElements[3].charAt(0);
606         zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
607
digit = numberElements[5].charAt(0);
608         minusSign = numberElements[6].charAt(0);
609         
610         // Temporary hack to support JDK versions before 1.1.6 (?)
611
// exponentSeparator = numberElements.length >= 9 ?
612
// numberElements[7] : DecimalFormat.PATTERN_EXPONENT;
613
// perMill = numberElements.length >= 9 ?
614
// numberElements[8].charAt(0) : '\u2030';
615
// infinity = numberElements.length >= 10 ?
616
// numberElements[9] : "\u221e";
617
// NaN = numberElements.length >= 11 ?
618
// numberElements[10] : "\ufffd";
619
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         // Obtain currency data from the currency API. This is strictly
629
// for backward compatibility; we don't use DecimalFormatSymbols
630
// for currency data anymore.
631
String JavaDoc 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             // If this is a ChoiceFormat currency, then format an
640
// arbitrary value; pick something != 1; more common.
641
currencySymbol = isChoiceFormat[0]
642                 ? new ChoiceFormat JavaDoc(currname).format(2.0)
643                 : currname;
644         } else {
645             intlCurrencySymbol = "XXX";
646             currencySymbol = "\u00A4"; // 'OX' currency symbol
647
}
648         // If there is a currency decimal, use it.
649
monetarySeparator = decimalSeparator;
650         monetaryGroupingSeparator = groupingSeparator;
651         Currency curr = Currency.getInstance(locale);
652         if(curr!=null){
653             String JavaDoc currencyCode = curr.getCurrencyCode();
654             if(currencyCode != null) {
655                 /* An explicit currency was requested */
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 JavaDoc ex){
667                     /* else An explicit currency was requested and is unknown or locale data is malformed. */
668                     /* decimal format API will get the correct value later on. */
669                 }
670             }
671             /* else no currency keyword used. */
672         }
673         //monetarySeparator = numberElements[11].charAt(0);
674
}
675
676     /**
677      * Read the default serializable fields, then if <code>serialVersionOnStream</code>
678      * is less than 1, initialize <code>monetarySeparator</code> to be
679      * the same as <code>decimalSeparator</code> and <code>exponential</code>
680      * to be 'E'.
681      * Finally, set serialVersionOnStream back to the maximum allowed value so that
682      * default serialization will work properly if this object is streamed out again.
683      */

684     private void readObject(ObjectInputStream JavaDoc stream)
685         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
686
687         // TODO: it looks to me {dlf} that the serialization code was never updated
688
// to handle the actual/valid ulocale fields.
689

690         stream.defaultReadObject();
691         ///CLOVER:OFF
692
// we don't have data for these old serialized forms any more
693
if (serialVersionOnStream < 1) {
694             // Didn't have monetarySeparator or exponential field;
695
// use defaults.
696
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             // Although we read the exponential field on stream to create the
704
// exponentSeparator, we don't do the reverse, since scientific
705
// notation isn't supported by the old classes, even though the
706
// symbol is there.
707
}
708         ///CLOVER:ON
709
if (serialVersionOnStream < 3) {
710             // Resurrected objects from old streams will have no
711
// locale. There is no 100% fix for this. A
712
// 90% fix is to construct a mapping of data back to
713
// locale, perhaps a hash of all our members. This is
714
// expensive and doesn't seem worth it.
715
locale = Locale.getDefault();
716         }
717         if (serialVersionOnStream < 4) {
718             // use same default behavior as for versions with no Locale
719
ulocale = ULocale.forLocale(locale);
720         }
721         if (serialVersionOnStream < 5) {
722             // use the same one for groupingSeparator
723
monetaryGroupingSeparator = groupingSeparator;
724         }
725         serialVersionOnStream = currentSerialVersion;
726
727     // recreate
728
currency = Currency.getInstance(intlCurrencySymbol);
729     }
730
731     /**
732      * Character used for zero.
733      *
734      * @serial
735      * @see #getZeroDigit
736      */

737     private char zeroDigit;
738
739     /**
740      * Character used for thousands separator.
741      *
742      * @serial
743      * @see #getGroupingSeparator
744      */

745     private char groupingSeparator;
746
747     /**
748      * Character used for decimal sign.
749      *
750      * @serial
751      * @see #getDecimalSeparator
752      */

753     private char decimalSeparator;
754
755     /**
756      * Character used for mille percent sign.
757      *
758      * @serial
759      * @see #getPerMill
760      */

761     private char perMill;
762
763     /**
764      * Character used for percent sign.
765      * @serial
766      * @see #getPercent
767      */

768     private char percent;
769
770     /**
771      * Character used for a digit in a pattern.
772      *
773      * @serial
774      * @see #getDigit
775      */

776     private char digit;
777
778     /**
779      * Character used for a significant digit in a pattern.
780      *
781      * @serial
782      * @see #getSignificantDigit
783      */

784     private char sigDigit;
785
786     /**
787      * Character used to separate positive and negative subpatterns
788      * in a pattern.
789      *
790      * @serial
791      * @see #getPatternSeparator
792      */

793     private char patternSeparator;
794
795     /**
796      * Character used to represent infinity.
797      * @serial
798      * @see #getInfinity
799      */

800     private String JavaDoc infinity;
801
802     /**
803      * Character used to represent NaN.
804      * @serial
805      * @see #getNaN
806      */

807     private String JavaDoc NaN;
808
809     /**
810      * Character used to represent minus sign.
811      * @serial
812      * @see #getMinusSign
813      */

814     private char minusSign;
815
816     /**
817      * String denoting the local currency, e.g. "$".
818      * @serial
819      * @see #getCurrencySymbol
820      */

821     private String JavaDoc currencySymbol;
822
823     /**
824      * International string denoting the local currency, e.g. "USD".
825      * @serial
826      * @see #getInternationalCurrencySymbol
827      */

828     private String JavaDoc intlCurrencySymbol;
829
830     /**
831      * The decimal separator used when formatting currency values.
832      * @serial
833      * @see #getMonetaryDecimalSeparator
834      */

835     private char monetarySeparator; // Field new in JDK 1.1.6
836

837     /**
838      * The decimal separator used when formatting currency values.
839      * @serial
840      * @see #getMonetaryGroupingSeparator
841      */

842     private char monetaryGroupingSeparator; // Field new in JDK 1.1.6
843

844     /**
845      * The character used to distinguish the exponent in a number formatted
846      * in exponential notation, e.g. 'E' for a number such as "1.23E45".
847      * <p>
848      * Note that this field has been superseded by <code>exponentSeparator</code>.
849      * It is retained for backward compatibility.
850      *
851      * @serial
852      */

853     private char exponential; // Field new in JDK 1.1.6
854

855     /**
856      * The string used to separate the mantissa from the exponent.
857      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
858      * <p>
859      * Note that this supersedes the <code>exponential</code> field.
860      *
861      * @serial
862      * @since AlphaWorks
863      */

864     private String JavaDoc exponentSeparator;
865
866     /**
867      * <strong><font face=helvetica color=red>NEW</font></strong>
868      * The character used to indicate a padding character in a format,
869      * e.g., '*' in a pattern such as "$*_#,##0.00".
870      * @serial
871      * @since AlphaWorks
872      */

873     private char padEscape;
874
875     /**
876      * <strong><font face=helvetica color=red>NEW</font></strong>
877      * The character used to indicate a plus sign.
878      * @serial
879      * @since AlphaWorks
880      */

881     private char plusSign;
882
883     /**
884      * The locale for which this object was constructed. Set to the
885      * default locale for objects resurrected from old streams.
886      * @since ICU 2.2
887      */

888     private Locale locale;
889
890     /**
891      * The requested ULocale. We keep the old locale for serialization compatibility.
892      * @since IDU 3.2
893      */

894     private ULocale ulocale;
895
896     // Proclaim JDK 1.1 FCS compatibility
897
private static final long serialVersionUID = 5772796243397350300L;
898
899     // The internal serial version which says which version was written
900
// - 0 (default) for version up to JDK 1.1.5
901
// - 1 for version from JDK 1.1.6, which includes two new fields:
902
// monetarySeparator and exponential.
903
// - 2 for version from AlphaWorks, which includes 3 new fields:
904
// padEscape, exponentSeparator, and plusSign.
905
// - 3 for ICU 2.2, which includes the locale field
906
// - 4 for ICU 3.2, which includes the ULocale field
907
// - 5 for ICU 3.6, which includes the monetaryGroupingSeparator field
908
private static final int currentSerialVersion = 5;
909     
910     /**
911      * Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
912      * Possible values are:
913      * <ul>
914      * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
915      *
916      * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which includes
917      * two new fields: <code>monetarySeparator</code> and <code>exponential</code>.
918      * <li><b>2</b>: Version for AlphaWorks. Adds padEscape, exponentSeparator,
919      * and plusSign.
920      * </ul>
921      * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format
922      * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
923      * is always written.
924      *
925      * @serial
926      */

927     private int serialVersionOnStream = currentSerialVersion;
928
929     /**
930      * cache to hold the NumberElements of a Locale.
931      */

932     private static final Hashtable JavaDoc cachedLocaleData = new Hashtable JavaDoc(3);
933     
934     /**
935      *
936      */

937     private String JavaDoc currencyPattern = null;
938     
939     // -------- BEGIN ULocale boilerplate --------
940

941     /**
942      * Return the locale that was used to create this object, or null.
943      * This may may differ from the locale requested at the time of
944      * this object's creation. For example, if an object is created
945      * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
946      * drawn from <tt>en</tt> (the <i>actual</i> locale), and
947      * <tt>en_US</tt> may be the most specific locale that exists (the
948      * <i>valid</i> locale).
949      *
950      * <p>Note: This method will be implemented in ICU 3.0; ICU 2.8
951      * contains a partial preview implementation. The * <i>actual</i>
952      * locale is returned correctly, but the <i>valid</i> locale is
953      * not, in most cases.
954      * @param type type of information requested, either {@link
955      * com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
956      * com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
957      * @return the information specified by <i>type</i>, or null if
958      * this object was not constructed from locale data.
959      * @see com.ibm.icu.util.ULocale
960      * @see com.ibm.icu.util.ULocale#VALID_LOCALE
961      * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
962      * @draft ICU 2.8 (retain)
963      * @provisional This API might change or be removed in a future release.
964      */

965     public final ULocale getLocale(ULocale.Type type) {
966         return type == ULocale.ACTUAL_LOCALE ?
967             this.actualLocale : this.validLocale;
968     }
969
970     /**
971      * Set information about the locales that were used to create this
972      * object. If the object was not constructed from locale data,
973      * both arguments should be set to null. Otherwise, neither
974      * should be null. The actual locale must be at the same level or
975      * less specific than the valid locale. This method is intended
976      * for use by factories or other entities that create objects of
977      * this class.
978      * @param valid the most specific locale containing any resource
979      * data, or null
980      * @param actual the locale containing data used to construct this
981      * object, or null
982      * @see com.ibm.icu.util.ULocale
983      * @see com.ibm.icu.util.ULocale#VALID_LOCALE
984      * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
985      * @internal
986      */

987     final void setLocale(ULocale valid, ULocale actual) {
988         // Change the following to an assertion later
989
if ((valid == null) != (actual == null)) {
990             ///CLOVER:OFF
991
throw new IllegalArgumentException JavaDoc();
992             ///CLOVER:ON
993
}
994         // Another check we could do is that the actual locale is at
995
// the same level or less specific than the valid locale.
996
this.validLocale = valid;
997         this.actualLocale = actual;
998     }
999
1000    /**
1001     * The most specific locale containing any resource data, or null.
1002     * @see com.ibm.icu.util.ULocale
1003     * @internal
1004     */

1005    private ULocale validLocale;
1006
1007    /**
1008     * The locale containing data used to construct this object, or
1009     * null.
1010     * @see com.ibm.icu.util.ULocale
1011     * @internal
1012     */

1013    private ULocale actualLocale;
1014
1015    // not serialized, reconstructed from intlCurrencyCode
1016
private transient Currency currency;
1017
1018    // -------- END ULocale boilerplate --------
1019
}
1020
Popular Tags