Source Code Cross Referenced for DecimalFormatSymbols.java in  » 6.0-JDK-Core » text » java » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » text » java.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        /*
027         * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
028         * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
029         *
030         *   The original version of this source code and documentation is copyrighted
031         * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
032         * materials are provided under terms of a License Agreement between Taligent
033         * and Sun. This technology is protected by multiple US and International
034         * patents. This notice and attribution to Taligent may not be removed.
035         *   Taligent is a registered trademark of Taligent, Inc.
036         *
037         */
038
039        package java.text;
040
041        import java.io.IOException;
042        import java.io.ObjectInputStream;
043        import java.io.Serializable;
044        import java.text.spi.DecimalFormatSymbolsProvider;
045        import java.util.Currency;
046        import java.util.Hashtable;
047        import java.util.Locale;
048        import java.util.ResourceBundle;
049        import java.util.spi.LocaleServiceProvider;
050        import sun.util.LocaleServiceProviderPool;
051        import sun.util.resources.LocaleData;
052
053        /**
054         * This class represents the set of symbols (such as the decimal separator,
055         * the grouping separator, and so on) needed by <code>DecimalFormat</code>
056         * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
057         * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
058         * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
059         * your <code>DecimalFormat</code> and modify it.
060         *
061         * @see          java.util.Locale
062         * @see          DecimalFormat
063         * @version      1.52, 05/05/07
064         * @author       Mark Davis
065         * @author       Alan Liu
066         */
067
068        public class DecimalFormatSymbols implements  Cloneable, Serializable {
069
070            /**
071             * Create a DecimalFormatSymbols object for the default locale.
072             * This constructor can only construct instances for the locales 
073             * supported by the Java runtime environment, not for those 
074             * supported by installed 
075             * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
076             * implementations. For full locale coverage, use the 
077             * {@link #getInstance(Locale) getInstance} method.
078             */
079            public DecimalFormatSymbols() {
080                initialize(Locale.getDefault());
081            }
082
083            /**
084             * Create a DecimalFormatSymbols object for the given locale.
085             * This constructor can only construct instances for the locales 
086             * supported by the Java runtime environment, not for those 
087             * supported by installed 
088             * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
089             * implementations. For full locale coverage, use the 
090             * {@link #getInstance(Locale) getInstance} method.
091             *
092             * @exception NullPointerException if <code>locale</code> is null
093             */
094            public DecimalFormatSymbols(Locale locale) {
095                initialize(locale);
096            }
097
098            /**
099             * Returns an array of all locales for which the
100             * <code>getInstance</code> methods of this class can return
101             * localized instances.
102             * The returned array represents the union of locales supported by the Java 
103             * runtime and by installed 
104             * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
105             * implementations.  It must contain at least a <code>Locale</code>
106             * instance equal to {@link java.util.Locale#US Locale.US}.
107             *
108             * @return An array of locales for which localized
109             *         <code>DecimalFormatSymbols</code> instances are available.
110             * @since 1.6
111             */
112            public static Locale[] getAvailableLocales() {
113                LocaleServiceProviderPool pool = LocaleServiceProviderPool
114                        .getPool(DecimalFormatSymbolsProvider.class);
115                return pool.getAvailableLocales();
116            }
117
118            /**
119             * Gets the <code>DecimalFormatSymbols</code> instance for the default 
120             * locale.  This method provides access to <code>DecimalFormatSymbols</code>
121             * instances for locales supported by the Java runtime itself as well 
122             * as for those supported by installed 
123             * {@link java.text.spi.DecimalFormatSymbolsProvider 
124             * DecimalFormatSymbolsProvider} implementations.
125             * @return a <code>DecimalFormatSymbols</code> instance.
126             * @since 1.6
127             */
128            public static final DecimalFormatSymbols getInstance() {
129                return getInstance(Locale.getDefault());
130            }
131
132            /**
133             * Gets the <code>DecimalFormatSymbols</code> instance for the specified 
134             * locale.  This method provides access to <code>DecimalFormatSymbols</code>
135             * instances for locales supported by the Java runtime itself as well 
136             * as for those supported by installed 
137             * {@link java.text.spi.DecimalFormatSymbolsProvider 
138             * DecimalFormatSymbolsProvider} implementations.
139             * @param locale the desired locale.
140             * @return a <code>DecimalFormatSymbols</code> instance.
141             * @exception NullPointerException if <code>locale</code> is null
142             * @since 1.6
143             */
144            public static final DecimalFormatSymbols getInstance(Locale locale) {
145
146                // Check whether a provider can provide an implementation that's closer 
147                // to the requested locale than what the Java runtime itself can provide.
148                LocaleServiceProviderPool pool = LocaleServiceProviderPool
149                        .getPool(DecimalFormatSymbolsProvider.class);
150                if (pool.hasProviders()) {
151                    DecimalFormatSymbols providersInstance = pool
152                            .getLocalizedObject(
153                                    DecimalFormatSymbolsGetter.INSTANCE, locale);
154                    if (providersInstance != null) {
155                        return providersInstance;
156                    }
157                }
158
159                return new DecimalFormatSymbols(locale);
160            }
161
162            /**
163             * Gets the character used for zero. Different for Arabic, etc.
164             */
165            public char getZeroDigit() {
166                return zeroDigit;
167            }
168
169            /**
170             * Sets the character used for zero. Different for Arabic, etc.
171             */
172            public void setZeroDigit(char zeroDigit) {
173                this .zeroDigit = zeroDigit;
174            }
175
176            /**
177             * Gets the character used for thousands separator. Different for French, etc.
178             */
179            public char getGroupingSeparator() {
180                return groupingSeparator;
181            }
182
183            /**
184             * Sets the character used for thousands separator. Different for French, etc.
185             */
186            public void setGroupingSeparator(char groupingSeparator) {
187                this .groupingSeparator = groupingSeparator;
188            }
189
190            /**
191             * Gets the character used for decimal sign. Different for French, etc.
192             */
193            public char getDecimalSeparator() {
194                return decimalSeparator;
195            }
196
197            /**
198             * Sets the character used for decimal sign. Different for French, etc.
199             */
200            public void setDecimalSeparator(char decimalSeparator) {
201                this .decimalSeparator = decimalSeparator;
202            }
203
204            /**
205             * Gets the character used for per mille sign. Different for Arabic, etc.
206             */
207            public char getPerMill() {
208                return perMill;
209            }
210
211            /**
212             * Sets the character used for per mille sign. Different for Arabic, etc.
213             */
214            public void setPerMill(char perMill) {
215                this .perMill = perMill;
216            }
217
218            /**
219             * Gets the character used for percent sign. Different for Arabic, etc.
220             */
221            public char getPercent() {
222                return percent;
223            }
224
225            /**
226             * Sets the character used for percent sign. Different for Arabic, etc.
227             */
228            public void setPercent(char percent) {
229                this .percent = percent;
230            }
231
232            /**
233             * Gets the character used for a digit in a pattern.
234             */
235            public char getDigit() {
236                return digit;
237            }
238
239            /**
240             * Sets the character used for a digit in a pattern.
241             */
242            public void setDigit(char digit) {
243                this .digit = digit;
244            }
245
246            /**
247             * Gets the character used to separate positive and negative subpatterns
248             * in a pattern.
249             */
250            public char getPatternSeparator() {
251                return patternSeparator;
252            }
253
254            /**
255             * Sets the character used to separate positive and negative subpatterns
256             * in a pattern.
257             */
258            public void setPatternSeparator(char patternSeparator) {
259                this .patternSeparator = patternSeparator;
260            }
261
262            /**
263             * Gets the string used to represent infinity. Almost always left
264             * unchanged.
265             */
266            public String getInfinity() {
267                return infinity;
268            }
269
270            /**
271             * Sets the string used to represent infinity. Almost always left
272             * unchanged.
273             */
274            public void setInfinity(String infinity) {
275                this .infinity = infinity;
276            }
277
278            /**
279             * Gets the string used to represent "not a number". Almost always left
280             * unchanged.
281             */
282            public String getNaN() {
283                return NaN;
284            }
285
286            /**
287             * Sets the string used to represent "not a number". Almost always left
288             * unchanged.
289             */
290            public void setNaN(String NaN) {
291                this .NaN = NaN;
292            }
293
294            /**
295             * Gets the character used to represent minus sign. If no explicit
296             * negative format is specified, one is formed by prefixing
297             * minusSign to the positive format.
298             */
299            public char getMinusSign() {
300                return minusSign;
301            }
302
303            /**
304             * Sets the character used to represent minus sign. If no explicit
305             * negative format is specified, one is formed by prefixing
306             * minusSign to the positive format.
307             */
308            public void setMinusSign(char minusSign) {
309                this .minusSign = minusSign;
310            }
311
312            /**
313             * Returns the currency symbol for the currency of these
314             * DecimalFormatSymbols in their locale.
315             * @since 1.2
316             */
317            public String getCurrencySymbol() {
318                return currencySymbol;
319            }
320
321            /**
322             * Sets the currency symbol for the currency of these
323             * DecimalFormatSymbols in their locale.
324             * @since 1.2
325             */
326            public void setCurrencySymbol(String currency) {
327                currencySymbol = currency;
328            }
329
330            /**
331             * Returns the ISO 4217 currency code of the currency of these
332             * DecimalFormatSymbols.
333             * @since 1.2
334             */
335            public String getInternationalCurrencySymbol() {
336                return intlCurrencySymbol;
337            }
338
339            /**
340             * Sets the ISO 4217 currency code of the currency of these
341             * DecimalFormatSymbols.
342             * If the currency code is valid (as defined by
343             * {@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),
344             * this also sets the currency attribute to the corresponding Currency
345             * instance and the currency symbol attribute to the currency's symbol
346             * in the DecimalFormatSymbols' locale. If the currency code is not valid,
347             * then the currency attribute is set to null and the currency symbol
348             * attribute is not modified.
349             *
350             * @see #setCurrency
351             * @see #setCurrencySymbol
352             * @since 1.2
353             */
354            public void setInternationalCurrencySymbol(String currencyCode) {
355                intlCurrencySymbol = currencyCode;
356                currency = null;
357                if (currencyCode != null) {
358                    try {
359                        currency = Currency.getInstance(currencyCode);
360                        currencySymbol = currency.getSymbol();
361                    } catch (IllegalArgumentException e) {
362                    }
363                }
364            }
365
366            /**
367             * Gets the currency of these DecimalFormatSymbols. May be null if the
368             * currency symbol attribute was previously set to a value that's not
369             * a valid ISO 4217 currency code.
370             *
371             * @return the currency used, or null
372             * @since 1.4
373             */
374            public Currency getCurrency() {
375                return currency;
376            }
377
378            /**
379             * Sets the currency of these DecimalFormatSymbols.
380             * This also sets the currency symbol attribute to the currency's symbol
381             * in the DecimalFormatSymbols' locale, and the international currency
382             * symbol attribute to the currency's ISO 4217 currency code.
383             *
384             * @param currency the new currency to be used
385             * @exception NullPointerException if <code>currency</code> is null
386             * @since 1.4
387             * @see #setCurrencySymbol
388             * @see #setInternationalCurrencySymbol
389             */
390            public void setCurrency(Currency currency) {
391                if (currency == null) {
392                    throw new NullPointerException();
393                }
394                this .currency = currency;
395                intlCurrencySymbol = currency.getCurrencyCode();
396                currencySymbol = currency.getSymbol(locale);
397            }
398
399            /**
400             * Returns the monetary decimal separator.
401             * @since 1.2
402             */
403            public char getMonetaryDecimalSeparator() {
404                return monetarySeparator;
405            }
406
407            /**
408             * Sets the monetary decimal separator.
409             * @since 1.2
410             */
411            public void setMonetaryDecimalSeparator(char sep) {
412                monetarySeparator = sep;
413            }
414
415            //------------------------------------------------------------
416            // BEGIN   Package Private methods ... to be made public later
417            //------------------------------------------------------------
418
419            /**
420             * Returns the character used to separate the mantissa from the exponent.
421             */
422            char getExponentialSymbol() {
423                return exponential;
424            }
425
426            /**
427             * Returns the string used to separate the mantissa from the exponent.
428             * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
429             *
430             * @return the exponent separator string
431             * @see #setExponentSeparator(java.lang.String)
432             * @since 1.6
433             */
434            public String getExponentSeparator() {
435                return exponentialSeparator;
436            }
437
438            /**
439             * Sets the character used to separate the mantissa from the exponent.
440             */
441            void setExponentialSymbol(char exp) {
442                exponential = exp;
443            }
444
445            /**
446             * Sets the string used to separate the mantissa from the exponent.
447             * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
448             *
449             * @param exp the exponent separator string
450             * @exception NullPointerException if <code>exp</code> is null
451             * @see #getExponentSeparator()
452             * @since 1.6
453             */
454            public void setExponentSeparator(String exp) {
455                if (exp == null) {
456                    throw new NullPointerException();
457                }
458                exponentialSeparator = exp;
459            }
460
461            //------------------------------------------------------------
462            // END     Package Private methods ... to be made public later
463            //------------------------------------------------------------
464
465            /**
466             * Standard override.
467             */
468            public Object clone() {
469                try {
470                    return (DecimalFormatSymbols) super .clone();
471                    // other fields are bit-copied
472                } catch (CloneNotSupportedException e) {
473                    throw new InternalError();
474                }
475            }
476
477            /**
478             * Override equals.
479             */
480            public boolean equals(Object obj) {
481                if (obj == null)
482                    return false;
483                if (this  == obj)
484                    return true;
485                if (getClass() != obj.getClass())
486                    return false;
487                DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
488                return (zeroDigit == other.zeroDigit
489                        && groupingSeparator == other.groupingSeparator
490                        && decimalSeparator == other.decimalSeparator
491                        && percent == other.percent
492                        && perMill == other.perMill
493                        && digit == other.digit
494                        && minusSign == other.minusSign
495                        && patternSeparator == other.patternSeparator
496                        && infinity.equals(other.infinity)
497                        && NaN.equals(other.NaN)
498                        && currencySymbol.equals(other.currencySymbol)
499                        && intlCurrencySymbol.equals(other.intlCurrencySymbol)
500                        && currency == other.currency
501                        && monetarySeparator == other.monetarySeparator
502                        && exponentialSeparator
503                                .equals(other.exponentialSeparator) && locale
504                        .equals(other.locale));
505            }
506
507            /**
508             * Override hashCode.
509             */
510            public int hashCode() {
511                int result = zeroDigit;
512                result = result * 37 + groupingSeparator;
513                result = result * 37 + decimalSeparator;
514                return result;
515            }
516
517            /**
518             * Initializes the symbols from the FormatData resource bundle.
519             */
520            private void initialize(Locale locale) {
521                this .locale = locale;
522
523                // get resource bundle data - try the cache first
524                boolean needCacheUpdate = false;
525                Object[] data = (Object[]) cachedLocaleData.get(locale);
526                if (data == null) { /* cache miss */
527                    data = new Object[3];
528                    ResourceBundle rb = LocaleData.getNumberFormatData(locale);
529                    data[0] = rb.getStringArray("NumberElements");
530                    needCacheUpdate = true;
531                }
532
533                String[] numberElements = (String[]) data[0];
534
535                decimalSeparator = numberElements[0].charAt(0);
536                groupingSeparator = numberElements[1].charAt(0);
537                patternSeparator = numberElements[2].charAt(0);
538                percent = numberElements[3].charAt(0);
539                zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
540                digit = numberElements[5].charAt(0);
541                minusSign = numberElements[6].charAt(0);
542                exponential = numberElements[7].charAt(0);
543                exponentialSeparator = numberElements[7]; //string representation new since 1.6
544                perMill = numberElements[8].charAt(0);
545                infinity = numberElements[9];
546                NaN = numberElements[10];
547
548                // Try to obtain the currency used in the locale's country.
549                // Check for empty country string separately because it's a valid
550                // country ID for Locale (and used for the C locale), but not a valid
551                // ISO 3166 country code, and exceptions are expensive.
552                if (!"".equals(locale.getCountry())) {
553                    try {
554                        currency = Currency.getInstance(locale);
555                    } catch (IllegalArgumentException e) {
556                        // use default values below for compatibility
557                    }
558                }
559                if (currency != null) {
560                    intlCurrencySymbol = currency.getCurrencyCode();
561                    if (data[1] != null && data[1] == intlCurrencySymbol) {
562                        currencySymbol = (String) data[2];
563                    } else {
564                        currencySymbol = currency.getSymbol(locale);
565                        data[1] = intlCurrencySymbol;
566                        data[2] = currencySymbol;
567                        needCacheUpdate = true;
568                    }
569                } else {
570                    // default values
571                    intlCurrencySymbol = "XXX";
572                    try {
573                        currency = Currency.getInstance(intlCurrencySymbol);
574                    } catch (IllegalArgumentException e) {
575                    }
576                    currencySymbol = "\u00A4";
577                }
578                // Currently the monetary decimal separator is the same as the
579                // standard decimal separator for all locales that we support.
580                // If that changes, add a new entry to NumberElements.
581                monetarySeparator = decimalSeparator;
582
583                if (needCacheUpdate) {
584                    cachedLocaleData.put(locale, data);
585                }
586            }
587
588            /**
589             * Reads the default serializable fields, provides default values for objects
590             * in older serial versions, and initializes non-serializable fields.
591             * If <code>serialVersionOnStream</code>
592             * is less than 1, initializes <code>monetarySeparator</code> to be
593             * the same as <code>decimalSeparator</code> and <code>exponential</code>
594             * to be 'E'.
595             * If <code>serialVersionOnStream</code> is less than 2,
596             * initializes <code>locale</code>to the root locale, and initializes 
597             * If <code>serialVersionOnStream</code> is less than 3, it initializes 
598             * <code>exponentialSeparator</code> using <code>exponential</code>.
599             * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
600             * default serialization will work properly if this object is streamed out again.
601             * Initializes the currency from the intlCurrencySymbol field.
602             *
603             * @since JDK 1.1.6
604             */
605            private void readObject(ObjectInputStream stream)
606                    throws IOException, ClassNotFoundException {
607                stream.defaultReadObject();
608                if (serialVersionOnStream < 1) {
609                    // Didn't have monetarySeparator or exponential field;
610                    // use defaults.
611                    monetarySeparator = decimalSeparator;
612                    exponential = 'E';
613                }
614                if (serialVersionOnStream < 2) {
615                    // didn't have locale; use root locale
616                    locale = Locale.ROOT;
617                }
618                if (serialVersionOnStream < 3) {
619                    // didn't have exponentialSeparator. Create one using exponential
620                    exponentialSeparator = Character.toString(exponential);
621                }
622                serialVersionOnStream = currentSerialVersion;
623
624                if (intlCurrencySymbol != null) {
625                    try {
626                        currency = Currency.getInstance(intlCurrencySymbol);
627                    } catch (IllegalArgumentException e) {
628                    }
629                }
630            }
631
632            /**
633             * Character used for zero.
634             *
635             * @serial
636             * @see #getZeroDigit
637             */
638            private char zeroDigit;
639
640            /**
641             * Character used for thousands separator.
642             *
643             * @serial
644             * @see #getGroupingSeparator
645             */
646            private char groupingSeparator;
647
648            /**
649             * Character used for decimal sign.
650             *
651             * @serial
652             * @see #getDecimalSeparator
653             */
654            private char decimalSeparator;
655
656            /**
657             * Character used for per mille sign.
658             *
659             * @serial
660             * @see #getPerMill
661             */
662            private char perMill;
663
664            /**
665             * Character used for percent sign.
666             * @serial
667             * @see #getPercent
668             */
669            private char percent;
670
671            /**
672             * Character used for a digit in a pattern.
673             *
674             * @serial
675             * @see #getDigit
676             */
677            private char digit;
678
679            /**
680             * Character used to separate positive and negative subpatterns
681             * in a pattern.
682             *
683             * @serial
684             * @see #getPatternSeparator
685             */
686            private char patternSeparator;
687
688            /**
689             * String used to represent infinity.
690             * @serial
691             * @see #getInfinity
692             */
693            private String infinity;
694
695            /**
696             * String used to represent "not a number".
697             * @serial
698             * @see #getNaN
699             */
700            private String NaN;
701
702            /**
703             * Character used to represent minus sign.
704             * @serial
705             * @see #getMinusSign
706             */
707            private char minusSign;
708
709            /**
710             * String denoting the local currency, e.g. "$".
711             * @serial
712             * @see #getCurrencySymbol
713             */
714            private String currencySymbol;
715
716            /**
717             * ISO 4217 currency code denoting the local currency, e.g. "USD".
718             * @serial
719             * @see #getInternationalCurrencySymbol
720             */
721            private String intlCurrencySymbol;
722
723            /**
724             * The decimal separator used when formatting currency values.
725             * @serial
726             * @since JDK 1.1.6
727             * @see #getMonetaryDecimalSeparator
728             */
729            private char monetarySeparator; // Field new in JDK 1.1.6
730
731            /**
732             * The character used to distinguish the exponent in a number formatted
733             * in exponential notation, e.g. 'E' for a number such as "1.23E45".
734             * <p>
735             * Note that the public API provides no way to set this field,
736             * even though it is supported by the implementation and the stream format.
737             * The intent is that this will be added to the API in the future.
738             *
739             * @serial
740             * @since JDK 1.1.6
741             */
742            private char exponential; // Field new in JDK 1.1.6
743
744            /**
745             * The string used to separate the mantissa from the exponent.
746             * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
747             * <p>
748             * If both <code>exponential</code> and <code>exponentialSeparator</code>
749             * exist, this <code>exponentialSeparator</code> has the precedence.
750             *
751             * @serial
752             * @since 1.6
753             */
754            private String exponentialSeparator; // Field new in JDK 1.6
755
756            /**
757             * The locale of these currency format symbols.
758             *
759             * @serial
760             * @since 1.4
761             */
762            private Locale locale;
763
764            // currency; only the ISO code is serialized.
765            private transient Currency currency;
766
767            // Proclaim JDK 1.1 FCS compatibility
768            static final long serialVersionUID = 5772796243397350300L;
769
770            // The internal serial version which says which version was written
771            // - 0 (default) for version up to JDK 1.1.5
772            // - 1 for version from JDK 1.1.6, which includes two new fields:
773            //     monetarySeparator and exponential.
774            // - 2 for version from J2SE 1.4, which includes locale field.
775            // - 3 for version from J2SE 1.6, which includes exponentialSeparator field.
776            private static final int currentSerialVersion = 3;
777
778            /**
779             * Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
780             * Possible values are:
781             * <ul>
782             * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
783             *
784             * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include
785             *      two new fields: <code>monetarySeparator</code> and <code>exponential</code>.
786             * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a
787             *      new <code>locale</code> field.
788             * <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a
789             *      new <code>exponentialSeparator</code> field.
790             * </ul>
791             * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format
792             * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
793             * is always written.
794             *
795             * @serial
796             * @since JDK 1.1.6
797             */
798            private int serialVersionOnStream = currentSerialVersion;
799
800            /**
801             * cache to hold the NumberElements and the Currency
802             * of a Locale.
803             */
804            private static final Hashtable cachedLocaleData = new Hashtable(3);
805
806            /**
807             * Obtains a DecimalFormatSymbols instance from a DecimalFormatSymbolsProvider 
808             * implementation.
809             */
810            private static class DecimalFormatSymbolsGetter
811                    implements 
812                    LocaleServiceProviderPool.LocalizedObjectGetter<DecimalFormatSymbolsProvider, DecimalFormatSymbols> {
813                private static final DecimalFormatSymbolsGetter INSTANCE = new DecimalFormatSymbolsGetter();
814
815                public DecimalFormatSymbols getObject(
816                        DecimalFormatSymbolsProvider decimalFormatSymbolsProvider,
817                        Locale locale, String key, Object... params) {
818                    assert params.length == 0;
819                    return decimalFormatSymbolsProvider.getInstance(locale);
820                }
821            }
822        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.