< prev index next >

src/java.base/share/classes/java/text/DecimalFormatSymbols.java

Print this page
rev 54198 : [mq]: 8220224
   1 /*
   2  * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  *   The original version of this source code and documentation is copyrighted
  31  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  32  * materials are provided under terms of a License Agreement between Taligent
  33  * and Sun. This technology is protected by multiple US and International
  34  * patents. This notice and attribution to Taligent may not be removed.
  35  *   Taligent is a registered trademark of Taligent, Inc.
  36  *
  37  */
  38 
  39 package java.text;
  40 

  41 import java.io.IOException;
  42 import java.io.ObjectInputStream;
  43 import java.io.Serializable;
  44 import java.text.spi.DecimalFormatSymbolsProvider;
  45 import java.util.Currency;
  46 import java.util.Locale;

  47 import sun.util.locale.provider.CalendarDataUtility;
  48 import sun.util.locale.provider.LocaleProviderAdapter;
  49 import sun.util.locale.provider.LocaleServiceProviderPool;
  50 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  51 
  52 /**
  53  * This class represents the set of symbols (such as the decimal separator,
  54  * the grouping separator, and so on) needed by <code>DecimalFormat</code>
  55  * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
  56  * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
  57  * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
  58  * your <code>DecimalFormat</code> and modify it.
  59  *
  60  * <p>If the locale contains "rg" (region override)
  61  * <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,
  62  * the symbols are overridden for the designated region.
  63  *
  64  * @see          java.util.Locale
  65  * @see          DecimalFormat
  66  * @author       Mark Davis
  67  * @author       Alan Liu
  68  * @since 1.1
  69  */
  70 
  71 public class DecimalFormatSymbols implements Cloneable, Serializable {
  72 
  73     /**
  74      * Create a DecimalFormatSymbols object for the default
  75      * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
  76      * This constructor can only construct instances for the locales
  77      * supported by the Java runtime environment, not for those
  78      * supported by installed


  90     }
  91 
  92     /**
  93      * Create a DecimalFormatSymbols object for the given locale.
  94      * This constructor can only construct instances for the locales
  95      * supported by the Java runtime environment, not for those
  96      * supported by installed
  97      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
  98      * implementations. For full locale coverage, use the
  99      * {@link #getInstance(Locale) getInstance} method.
 100      * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 101      * for the numbering system, the instance is initialized with the specified numbering
 102      * system if the JRE implementation supports it. For example,
 103      * <pre>
 104      * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 105      * </pre>
 106      * This may return a {@code NumberFormat} instance with the Thai numbering system,
 107      * instead of the Latin numbering system.
 108      *
 109      * @param locale the desired locale
 110      * @exception NullPointerException if <code>locale</code> is null
 111      */
 112     public DecimalFormatSymbols( Locale locale ) {
 113         initialize( locale );
 114     }
 115 
 116     /**
 117      * Returns an array of all locales for which the
 118      * <code>getInstance</code> methods of this class can return
 119      * localized instances.
 120      * The returned array represents the union of locales supported by the Java
 121      * runtime and by installed
 122      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
 123      * implementations.  It must contain at least a <code>Locale</code>
 124      * instance equal to {@link java.util.Locale#US Locale.US}.
 125      *
 126      * @return an array of locales for which localized
 127      *         <code>DecimalFormatSymbols</code> instances are available.
 128      * @since 1.6
 129      */
 130     public static Locale[] getAvailableLocales() {
 131         LocaleServiceProviderPool pool =
 132             LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
 133         return pool.getAvailableLocales();
 134     }
 135 
 136     /**
 137      * Gets the <code>DecimalFormatSymbols</code> instance for the default
 138      * locale.  This method provides access to <code>DecimalFormatSymbols</code>
 139      * instances for locales supported by the Java runtime itself as well
 140      * as for those supported by installed
 141      * {@link java.text.spi.DecimalFormatSymbolsProvider
 142      * DecimalFormatSymbolsProvider} implementations.
 143      * <p>This is equivalent to calling
 144      * {@link #getInstance(Locale)
 145      *     getInstance(Locale.getDefault(Locale.Category.FORMAT))}.
 146      * @see java.util.Locale#getDefault(java.util.Locale.Category)
 147      * @see java.util.Locale.Category#FORMAT
 148      * @return a <code>DecimalFormatSymbols</code> instance.
 149      * @since 1.6
 150      */
 151     public static final DecimalFormatSymbols getInstance() {
 152         return getInstance(Locale.getDefault(Locale.Category.FORMAT));
 153     }
 154 
 155     /**
 156      * Gets the <code>DecimalFormatSymbols</code> instance for the specified
 157      * locale.  This method provides access to <code>DecimalFormatSymbols</code>
 158      * instances for locales supported by the Java runtime itself as well
 159      * as for those supported by installed
 160      * {@link java.text.spi.DecimalFormatSymbolsProvider
 161      * DecimalFormatSymbolsProvider} implementations.
 162      * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 163      * for the numbering system, the instance is initialized with the specified numbering
 164      * system if the JRE implementation supports it. For example,
 165      * <pre>
 166      * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 167      * </pre>
 168      * This may return a {@code NumberFormat} instance with the Thai numbering system,
 169      * instead of the Latin numbering system.
 170      *
 171      * @param locale the desired locale.
 172      * @return a <code>DecimalFormatSymbols</code> instance.
 173      * @exception NullPointerException if <code>locale</code> is null
 174      * @since 1.6
 175      */
 176     public static final DecimalFormatSymbols getInstance(Locale locale) {
 177         LocaleProviderAdapter adapter;
 178         adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
 179         DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
 180         DecimalFormatSymbols dfsyms = provider.getInstance(locale);
 181         if (dfsyms == null) {
 182             provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
 183             dfsyms = provider.getInstance(locale);
 184         }
 185         return dfsyms;
 186     }
 187 
 188     /**
 189      * Gets the character used for zero. Different for Arabic, etc.
 190      *
 191      * @return the character used for zero
 192      */
 193     public char getZeroDigit() {


 238     public void setDecimalSeparator(char decimalSeparator) {
 239         this.decimalSeparator = decimalSeparator;
 240     }
 241 
 242     /**
 243      * Gets the character used for per mille sign. Different for Arabic, etc.
 244      *
 245      * @return the character used for per mille sign
 246      */
 247     public char getPerMill() {
 248         return perMill;
 249     }
 250 
 251     /**
 252      * Sets the character used for per mille sign. Different for Arabic, etc.
 253      *
 254      * @param perMill the character used for per mille sign
 255      */
 256     public void setPerMill(char perMill) {
 257         this.perMill = perMill;



































 258     }
 259 
 260     /**
 261      * Gets the character used for percent sign. Different for Arabic, etc.
 262      *
 263      * @return the character used for percent sign
 264      */
 265     public char getPercent() {
 266         return percent;
 267     }
 268 
 269     /**
 270      * Sets the character used for percent sign. Different for Arabic, etc.
 271      *
 272      * @param percent the character used for percent sign
 273      */
 274     public void setPercent(char percent) {
 275         this.percent = percent;



































 276     }
 277 
 278     /**
 279      * Gets the character used for a digit in a pattern.
 280      *
 281      * @return the character used for a digit in a pattern
 282      */
 283     public char getDigit() {
 284         return digit;
 285     }
 286 
 287     /**
 288      * Sets the character used for a digit in a pattern.
 289      *
 290      * @param digit the character used for a digit in a pattern
 291      */
 292     public void setDigit(char digit) {
 293         this.digit = digit;
 294     }
 295 


 356     /**
 357      * Gets the character used to represent minus sign. If no explicit
 358      * negative format is specified, one is formed by prefixing
 359      * minusSign to the positive format.
 360      *
 361      * @return the character representing minus sign
 362      */
 363     public char getMinusSign() {
 364         return minusSign;
 365     }
 366 
 367     /**
 368      * Sets the character used to represent minus sign. If no explicit
 369      * negative format is specified, one is formed by prefixing
 370      * minusSign to the positive format.
 371      *
 372      * @param minusSign the character representing minus sign
 373      */
 374     public void setMinusSign(char minusSign) {
 375         this.minusSign = minusSign;








































 376     }
 377 
 378     /**
 379      * Returns the currency symbol for the currency of these
 380      * DecimalFormatSymbols in their locale.
 381      *
 382      * @return the currency symbol
 383      * @since 1.2
 384      */
 385     public String getCurrencySymbol()
 386     {
 387         initializeCurrency(locale);
 388         return currencySymbol;
 389     }
 390 
 391     /**
 392      * Sets the currency symbol for the currency of these
 393      * DecimalFormatSymbols in their locale.
 394      *
 395      * @param currency the currency symbol


 447     /**
 448      * Gets the currency of these DecimalFormatSymbols. May be null if the
 449      * currency symbol attribute was previously set to a value that's not
 450      * a valid ISO 4217 currency code.
 451      *
 452      * @return the currency used, or null
 453      * @since 1.4
 454      */
 455     public Currency getCurrency() {
 456         initializeCurrency(locale);
 457         return currency;
 458     }
 459 
 460     /**
 461      * Sets the currency of these DecimalFormatSymbols.
 462      * This also sets the currency symbol attribute to the currency's symbol
 463      * in the DecimalFormatSymbols' locale, and the international currency
 464      * symbol attribute to the currency's ISO 4217 currency code.
 465      *
 466      * @param currency the new currency to be used
 467      * @exception NullPointerException if <code>currency</code> is null
 468      * @since 1.4
 469      * @see #setCurrencySymbol
 470      * @see #setInternationalCurrencySymbol
 471      */
 472     public void setCurrency(Currency currency) {
 473         if (currency == null) {
 474             throw new NullPointerException();
 475         }
 476         initializeCurrency(locale);
 477         this.currency = currency;
 478         intlCurrencySymbol = currency.getCurrencyCode();
 479         currencySymbol = currency.getSymbol(locale);
 480     }
 481 
 482 
 483     /**
 484      * Returns the monetary decimal separator.
 485      *
 486      * @return the monetary decimal separator
 487      * @since 1.2


 523      * @since 1.6
 524      */
 525     public String getExponentSeparator()
 526     {
 527         return exponentialSeparator;
 528     }
 529 
 530     /**
 531      * Sets the character used to separate the mantissa from the exponent.
 532      */
 533     void setExponentialSymbol(char exp)
 534     {
 535         exponential = exp;
 536     }
 537 
 538     /**
 539      * Sets the string used to separate the mantissa from the exponent.
 540      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
 541      *
 542      * @param exp the exponent separator string
 543      * @exception NullPointerException if <code>exp</code> is null
 544      * @see #getExponentSeparator()
 545      * @since 1.6
 546      */
 547     public void setExponentSeparator(String exp)
 548     {
 549         if (exp == null) {
 550             throw new NullPointerException();
 551         }
 552         exponentialSeparator = exp;
 553     }
 554 
 555 
 556     //------------------------------------------------------------
 557     // END     Package Private methods ... to be made public later
 558     //------------------------------------------------------------
 559 
 560     /**
 561      * Standard override.
 562      */
 563     @Override


 566             return (DecimalFormatSymbols)super.clone();
 567             // other fields are bit-copied
 568         } catch (CloneNotSupportedException e) {
 569             throw new InternalError(e);
 570         }
 571     }
 572 
 573     /**
 574      * Override equals.
 575      */
 576     @Override
 577     public boolean equals(Object obj) {
 578         if (obj == null) return false;
 579         if (this == obj) return true;
 580         if (getClass() != obj.getClass()) return false;
 581         DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
 582         return (zeroDigit == other.zeroDigit &&
 583         groupingSeparator == other.groupingSeparator &&
 584         decimalSeparator == other.decimalSeparator &&
 585         percent == other.percent &&

 586         perMill == other.perMill &&

 587         digit == other.digit &&
 588         minusSign == other.minusSign &&

 589         patternSeparator == other.patternSeparator &&
 590         infinity.equals(other.infinity) &&
 591         NaN.equals(other.NaN) &&
 592         getCurrencySymbol().equals(other.getCurrencySymbol()) && // possible currency init occurs here
 593         intlCurrencySymbol.equals(other.intlCurrencySymbol) &&
 594         currency == other.currency &&
 595         monetarySeparator == other.monetarySeparator &&
 596         exponentialSeparator.equals(other.exponentialSeparator) &&
 597         locale.equals(other.locale));
 598     }
 599 
 600     /**
 601      * Override hashCode.
 602      */
 603     @Override
 604     public int hashCode() {
 605             int result = zeroDigit;
 606             result = result * 37 + groupingSeparator;
 607             result = result * 37 + decimalSeparator;
 608             return result;


 614     private void initialize( Locale locale ) {
 615         this.locale = locale;
 616 
 617         // check for region override
 618         Locale override = locale.getUnicodeLocaleType("nu") == null ?
 619             CalendarDataUtility.findRegionOverride(locale) :
 620             locale;
 621 
 622         // get resource bundle data
 623         LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, override);
 624         // Avoid potential recursions
 625         if (!(adapter instanceof ResourceBundleBasedAdapter)) {
 626             adapter = LocaleProviderAdapter.getResourceBundleBased();
 627         }
 628         Object[] data = adapter.getLocaleResources(override).getDecimalFormatSymbolsData();
 629         String[] numberElements = (String[]) data[0];
 630 
 631         decimalSeparator = numberElements[0].charAt(0);
 632         groupingSeparator = numberElements[1].charAt(0);
 633         patternSeparator = numberElements[2].charAt(0);
 634         percent = numberElements[3].charAt(0);

 635         zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
 636         digit = numberElements[5].charAt(0);
 637         minusSign = numberElements[6].charAt(0);

 638         exponential = numberElements[7].charAt(0);
 639         exponentialSeparator = numberElements[7]; //string representation new since 1.6
 640         perMill = numberElements[8].charAt(0);

 641         infinity  = numberElements[9];
 642         NaN = numberElements[10];
 643 
 644         // maybe filled with previously cached values, or null.
 645         intlCurrencySymbol = (String) data[1];
 646         currencySymbol = (String) data[2];
 647 
 648         // Currently the monetary decimal separator is the same as the
 649         // standard decimal separator for all locales that we support.
 650         // If that changes, add a new entry to NumberElements.
 651         monetarySeparator = decimalSeparator;
 652     }
 653 
 654     /**










 655      * Lazy initialization for currency related fields
 656      */
 657     private void initializeCurrency(Locale locale) {
 658         if (currencyInitialized) {
 659             return;
 660         }
 661 
 662         // Try to obtain the currency used in the locale's country.
 663         // Check for empty country string separately because it's a valid
 664         // country ID for Locale (and used for the C locale), but not a valid
 665         // ISO 3166 country code, and exceptions are expensive.
 666         if (!locale.getCountry().isEmpty()) {
 667             try {
 668                 currency = Currency.getInstance(locale);
 669             } catch (IllegalArgumentException e) {
 670                 // use default values below for compatibility
 671             }
 672         }
 673 
 674         if (currency != null) {


 687                 currencySymbol = currency.getSymbol(locale);
 688                 data[1] = intlCurrencySymbol;
 689                 data[2] = currencySymbol;
 690             }
 691         } else {
 692             // default values
 693             intlCurrencySymbol = "XXX";
 694             try {
 695                 currency = Currency.getInstance(intlCurrencySymbol);
 696             } catch (IllegalArgumentException e) {
 697             }
 698             currencySymbol = "\u00A4";
 699         }
 700 
 701         currencyInitialized = true;
 702     }
 703 
 704     /**
 705      * Reads the default serializable fields, provides default values for objects
 706      * in older serial versions, and initializes non-serializable fields.
 707      * If <code>serialVersionOnStream</code>
 708      * is less than 1, initializes <code>monetarySeparator</code> to be
 709      * the same as <code>decimalSeparator</code> and <code>exponential</code>
 710      * to be 'E'.
 711      * If <code>serialVersionOnStream</code> is less than 2,
 712      * initializes <code>locale</code>to the root locale, and initializes
 713      * If <code>serialVersionOnStream</code> is less than 3, it initializes
 714      * <code>exponentialSeparator</code> using <code>exponential</code>.
 715      * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that




 716      * default serialization will work properly if this object is streamed out again.
 717      * Initializes the currency from the intlCurrencySymbol field.
 718      *


 719      * @since  1.1.6
 720      */
 721     private void readObject(ObjectInputStream stream)
 722             throws IOException, ClassNotFoundException {
 723         stream.defaultReadObject();
 724         if (serialVersionOnStream < 1) {
 725             // Didn't have monetarySeparator or exponential field;
 726             // use defaults.
 727             monetarySeparator = decimalSeparator;
 728             exponential       = 'E';
 729         }
 730         if (serialVersionOnStream < 2) {
 731             // didn't have locale; use root locale
 732             locale = Locale.ROOT;
 733         }
 734         if (serialVersionOnStream < 3) {
 735             // didn't have exponentialSeparator. Create one using exponential
 736             exponentialSeparator = Character.toString(exponential);
 737         }

















 738         serialVersionOnStream = currentSerialVersion;
 739 
 740         if (intlCurrencySymbol != null) {
 741             try {
 742                  currency = Currency.getInstance(intlCurrencySymbol);
 743             } catch (IllegalArgumentException e) {
 744             }
 745             currencyInitialized = true;
 746         }
 747     }
 748 
 749     /**
 750      * Character used for zero.
 751      *
 752      * @serial
 753      * @see #getZeroDigit
 754      */
 755     private  char    zeroDigit;
 756 
 757     /**


 845      */
 846     private  char    monetarySeparator; // Field new in JDK 1.1.6
 847 
 848     /**
 849      * The character used to distinguish the exponent in a number formatted
 850      * in exponential notation, e.g. 'E' for a number such as "1.23E45".
 851      * <p>
 852      * Note that the public API provides no way to set this field,
 853      * even though it is supported by the implementation and the stream format.
 854      * The intent is that this will be added to the API in the future.
 855      *
 856      * @serial
 857      * @since  1.1.6
 858      */
 859     private  char    exponential;       // Field new in JDK 1.1.6
 860 
 861     /**
 862      * The string used to separate the mantissa from the exponent.
 863      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
 864      * <p>
 865      * If both <code>exponential</code> and <code>exponentialSeparator</code>
 866      * exist, this <code>exponentialSeparator</code> has the precedence.
 867      *
 868      * @serial
 869      * @since 1.6
 870      */
 871     private  String    exponentialSeparator;       // Field new in JDK 1.6
 872 
 873     /**
 874      * The locale of these currency format symbols.
 875      *
 876      * @serial
 877      * @since 1.4
 878      */
 879     private Locale locale;
 880 

































 881     // currency; only the ISO code is serialized.
 882     private transient Currency currency;
 883     private transient volatile boolean currencyInitialized;
 884 
 885     // Proclaim JDK 1.1 FCS compatibility
 886     static final long serialVersionUID = 5772796243397350300L;
 887 
 888     // The internal serial version which says which version was written
 889     // - 0 (default) for version up to JDK 1.1.5
 890     // - 1 for version from JDK 1.1.6, which includes two new fields:
 891     //     monetarySeparator and exponential.
 892     // - 2 for version from J2SE 1.4, which includes locale field.
 893     // - 3 for version from J2SE 1.6, which includes exponentialSeparator field.
 894     private static final int currentSerialVersion = 3;


 895 
 896     /**
 897      * Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
 898      * Possible values are:
 899      * <ul>
 900      * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
 901      *
 902      * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include
 903      *      two new fields: <code>monetarySeparator</code> and <code>exponential</code>.
 904      * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a
 905      *      new <code>locale</code> field.
 906      * <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a
 907      *      new <code>exponentialSeparator</code> field.



 908      * </ul>
 909      * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format
 910      * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
 911      * is always written.
 912      *
 913      * @serial
 914      * @since  1.1.6
 915      */
 916     private int serialVersionOnStream = currentSerialVersion;
 917 }
   1 /*
   2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  *   The original version of this source code and documentation is copyrighted
  31  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  32  * materials are provided under terms of a License Agreement between Taligent
  33  * and Sun. This technology is protected by multiple US and International
  34  * patents. This notice and attribution to Taligent may not be removed.
  35  *   Taligent is a registered trademark of Taligent, Inc.
  36  *
  37  */
  38 
  39 package java.text;
  40 
  41 import java.io.InvalidObjectException;
  42 import java.io.IOException;
  43 import java.io.ObjectInputStream;
  44 import java.io.Serializable;
  45 import java.text.spi.DecimalFormatSymbolsProvider;
  46 import java.util.Currency;
  47 import java.util.Locale;
  48 import java.util.Objects;
  49 import sun.util.locale.provider.CalendarDataUtility;
  50 import sun.util.locale.provider.LocaleProviderAdapter;
  51 import sun.util.locale.provider.LocaleServiceProviderPool;
  52 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  53 
  54 /**
  55  * This class represents the set of symbols (such as the decimal separator,
  56  * the grouping separator, and so on) needed by {@code DecimalFormat}
  57  * to format numbers. {@code DecimalFormat} creates for itself an instance of
  58  * {@code DecimalFormatSymbols} from its locale data.  If you need to change any
  59  * of these symbols, you can get the {@code DecimalFormatSymbols} object from
  60  * your {@code DecimalFormat} and modify it.
  61  *
  62  * <p>If the locale contains "rg" (region override)
  63  * <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,
  64  * the symbols are overridden for the designated region.
  65  *
  66  * @see          java.util.Locale
  67  * @see          DecimalFormat
  68  * @author       Mark Davis
  69  * @author       Alan Liu
  70  * @since 1.1
  71  */
  72 
  73 public class DecimalFormatSymbols implements Cloneable, Serializable {
  74 
  75     /**
  76      * Create a DecimalFormatSymbols object for the default
  77      * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
  78      * This constructor can only construct instances for the locales
  79      * supported by the Java runtime environment, not for those
  80      * supported by installed


  92     }
  93 
  94     /**
  95      * Create a DecimalFormatSymbols object for the given locale.
  96      * This constructor can only construct instances for the locales
  97      * supported by the Java runtime environment, not for those
  98      * supported by installed
  99      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
 100      * implementations. For full locale coverage, use the
 101      * {@link #getInstance(Locale) getInstance} method.
 102      * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 103      * for the numbering system, the instance is initialized with the specified numbering
 104      * system if the JRE implementation supports it. For example,
 105      * <pre>
 106      * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 107      * </pre>
 108      * This may return a {@code NumberFormat} instance with the Thai numbering system,
 109      * instead of the Latin numbering system.
 110      *
 111      * @param locale the desired locale
 112      * @exception NullPointerException if {@code locale} is null
 113      */
 114     public DecimalFormatSymbols( Locale locale ) {
 115         initialize( locale );
 116     }
 117 
 118     /**
 119      * Returns an array of all locales for which the
 120      * {@code getInstance} methods of this class can return
 121      * localized instances.
 122      * The returned array represents the union of locales supported by the Java
 123      * runtime and by installed
 124      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
 125      * implementations.  It must contain at least a {@code Locale}
 126      * instance equal to {@link java.util.Locale#US Locale.US}.
 127      *
 128      * @return an array of locales for which localized
 129      *         {@code DecimalFormatSymbols} instances are available.
 130      * @since 1.6
 131      */
 132     public static Locale[] getAvailableLocales() {
 133         LocaleServiceProviderPool pool =
 134             LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
 135         return pool.getAvailableLocales();
 136     }
 137 
 138     /**
 139      * Gets the {@code DecimalFormatSymbols} instance for the default
 140      * locale.  This method provides access to {@code DecimalFormatSymbols}
 141      * instances for locales supported by the Java runtime itself as well
 142      * as for those supported by installed
 143      * {@link java.text.spi.DecimalFormatSymbolsProvider
 144      * DecimalFormatSymbolsProvider} implementations.
 145      * <p>This is equivalent to calling
 146      * {@link #getInstance(Locale)
 147      *     getInstance(Locale.getDefault(Locale.Category.FORMAT))}.
 148      * @see java.util.Locale#getDefault(java.util.Locale.Category)
 149      * @see java.util.Locale.Category#FORMAT
 150      * @return a {@code DecimalFormatSymbols} instance.
 151      * @since 1.6
 152      */
 153     public static final DecimalFormatSymbols getInstance() {
 154         return getInstance(Locale.getDefault(Locale.Category.FORMAT));
 155     }
 156 
 157     /**
 158      * Gets the {@code DecimalFormatSymbols} instance for the specified
 159      * locale.  This method provides access to {@code DecimalFormatSymbols}
 160      * instances for locales supported by the Java runtime itself as well
 161      * as for those supported by installed
 162      * {@link java.text.spi.DecimalFormatSymbolsProvider
 163      * DecimalFormatSymbolsProvider} implementations.
 164      * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 165      * for the numbering system, the instance is initialized with the specified numbering
 166      * system if the JRE implementation supports it. For example,
 167      * <pre>
 168      * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 169      * </pre>
 170      * This may return a {@code NumberFormat} instance with the Thai numbering system,
 171      * instead of the Latin numbering system.
 172      *
 173      * @param locale the desired locale.
 174      * @return a {@code DecimalFormatSymbols} instance.
 175      * @exception NullPointerException if {@code locale} is null
 176      * @since 1.6
 177      */
 178     public static final DecimalFormatSymbols getInstance(Locale locale) {
 179         LocaleProviderAdapter adapter;
 180         adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
 181         DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
 182         DecimalFormatSymbols dfsyms = provider.getInstance(locale);
 183         if (dfsyms == null) {
 184             provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
 185             dfsyms = provider.getInstance(locale);
 186         }
 187         return dfsyms;
 188     }
 189 
 190     /**
 191      * Gets the character used for zero. Different for Arabic, etc.
 192      *
 193      * @return the character used for zero
 194      */
 195     public char getZeroDigit() {


 240     public void setDecimalSeparator(char decimalSeparator) {
 241         this.decimalSeparator = decimalSeparator;
 242     }
 243 
 244     /**
 245      * Gets the character used for per mille sign. Different for Arabic, etc.
 246      *
 247      * @return the character used for per mille sign
 248      */
 249     public char getPerMill() {
 250         return perMill;
 251     }
 252 
 253     /**
 254      * Sets the character used for per mille sign. Different for Arabic, etc.
 255      *
 256      * @param perMill the character used for per mille sign
 257      */
 258     public void setPerMill(char perMill) {
 259         this.perMill = perMill;
 260         this.perMillText = Character.toString(perMill);
 261     }
 262 
 263     /**
 264      * Gets the string used for per mille sign. Different for Arabic, etc.
 265      *
 266      * @return the string used for per mille sign
 267      * @since 13
 268      */
 269     String getPerMillText() {
 270         return perMillText;
 271     }
 272 
 273     /**
 274      * Sets the string used for per mille sign. Different for Arabic, etc.
 275      *
 276      * Setting the {@code perMillText} affects the return value of
 277      * {@link #getPerMill()}, in which the first non-format character of
 278      * {@code perMillText} is returned.
 279      *
 280      * @param perMillText the string used for per mille sign
 281      * @throws NullPointerException if {@code perMillText} is null
 282      * @throws IllegalArgumentException if {@code perMillText} is an empty string
 283      * @see #getPerMill()
 284      * @see #getPerMillText()
 285      * @since 13
 286      */
 287     void setPerMillText(String perMillText) {
 288         Objects.requireNonNull(perMillText);
 289         if (perMillText.isEmpty()) {
 290             throw new IllegalArgumentException("Empty argument string");
 291         }
 292 
 293         this.perMillText = perMillText;
 294         this.perMill = findNonFormatChar(perMillText, '\u2030');
 295     }
 296 
 297     /**
 298      * Gets the character used for percent sign. Different for Arabic, etc.
 299      *
 300      * @return the character used for percent sign
 301      */
 302     public char getPercent() {
 303         return percent;
 304     }
 305 
 306     /**
 307      * Sets the character used for percent sign. Different for Arabic, etc.
 308      *
 309      * @param percent the character used for percent sign
 310      */
 311     public void setPercent(char percent) {
 312         this.percent = percent;
 313         this.percentText = Character.toString(percent);
 314     }
 315 
 316     /**
 317      * Gets the string used for percent sign. Different for Arabic, etc.
 318      *
 319      * @return the string used for percent sign
 320      * @since 13
 321      */
 322     String getPercentText() {
 323         return percentText;
 324     }
 325 
 326     /**
 327      * Sets the string used for percent sign. Different for Arabic, etc.
 328      *
 329      * Setting the {@code percentText} affects the return value of
 330      * {@link #getPercent()}, in which the first non-format character of
 331      * {@code percentText} is returned.
 332      *
 333      * @param percentText the string used for percent sign
 334      * @throws NullPointerException if {@code percentText} is null
 335      * @throws IllegalArgumentException if {@code percentText} is an empty string
 336      * @see #getPercent()
 337      * @see #getPercentText()
 338      * @since 13
 339      */
 340     void setPercentText(String percentText) {
 341         Objects.requireNonNull(percentText);
 342         if (percentText.isEmpty()) {
 343             throw new IllegalArgumentException("Empty argument string");
 344         }
 345 
 346         this.percentText = percentText;
 347         this.percent = findNonFormatChar(percentText, '%');
 348     }
 349 
 350     /**
 351      * Gets the character used for a digit in a pattern.
 352      *
 353      * @return the character used for a digit in a pattern
 354      */
 355     public char getDigit() {
 356         return digit;
 357     }
 358 
 359     /**
 360      * Sets the character used for a digit in a pattern.
 361      *
 362      * @param digit the character used for a digit in a pattern
 363      */
 364     public void setDigit(char digit) {
 365         this.digit = digit;
 366     }
 367 


 428     /**
 429      * Gets the character used to represent minus sign. If no explicit
 430      * negative format is specified, one is formed by prefixing
 431      * minusSign to the positive format.
 432      *
 433      * @return the character representing minus sign
 434      */
 435     public char getMinusSign() {
 436         return minusSign;
 437     }
 438 
 439     /**
 440      * Sets the character used to represent minus sign. If no explicit
 441      * negative format is specified, one is formed by prefixing
 442      * minusSign to the positive format.
 443      *
 444      * @param minusSign the character representing minus sign
 445      */
 446     public void setMinusSign(char minusSign) {
 447         this.minusSign = minusSign;
 448         this.minusSignText = Character.toString(minusSign);
 449     }
 450 
 451     /**
 452      * Gets the string used to represent minus sign. If no explicit
 453      * negative format is specified, one is formed by prefixing
 454      * minusSignText to the positive format.
 455      *
 456      * @return the string representing minus sign
 457      * @since 13
 458      */
 459     String getMinusSignText() {
 460         return minusSignText;
 461     }
 462 
 463     /**
 464      * Sets the string used to represent minus sign. If no explicit
 465      * negative format is specified, one is formed by prefixing
 466      * minusSignText to the positive format.
 467      *
 468      * Setting the {@code minusSignText} affects the return value of
 469      * {@link #getMinusSign()}, in which the first non-format character of
 470      * {@code minusSignText} is returned.
 471      *
 472      * @param minusSignText the character representing minus sign
 473      * @throws NullPointerException if {@code minusSignText} is null
 474      * @throws IllegalArgumentException if {@code minusSignText} is an
 475      *  empty string
 476      * @see #getMinusSign()
 477      * @see #getMinusSignText()
 478      * @since 13
 479      */
 480     void setMinusSignText(String minusSignText) {
 481         Objects.requireNonNull(minusSignText);
 482         if (minusSignText.isEmpty()) {
 483             throw new IllegalArgumentException("Empty argument string");
 484         }
 485 
 486         this.minusSignText = minusSignText;
 487         this.minusSign = findNonFormatChar(minusSignText, '-');
 488     }
 489 
 490     /**
 491      * Returns the currency symbol for the currency of these
 492      * DecimalFormatSymbols in their locale.
 493      *
 494      * @return the currency symbol
 495      * @since 1.2
 496      */
 497     public String getCurrencySymbol()
 498     {
 499         initializeCurrency(locale);
 500         return currencySymbol;
 501     }
 502 
 503     /**
 504      * Sets the currency symbol for the currency of these
 505      * DecimalFormatSymbols in their locale.
 506      *
 507      * @param currency the currency symbol


 559     /**
 560      * Gets the currency of these DecimalFormatSymbols. May be null if the
 561      * currency symbol attribute was previously set to a value that's not
 562      * a valid ISO 4217 currency code.
 563      *
 564      * @return the currency used, or null
 565      * @since 1.4
 566      */
 567     public Currency getCurrency() {
 568         initializeCurrency(locale);
 569         return currency;
 570     }
 571 
 572     /**
 573      * Sets the currency of these DecimalFormatSymbols.
 574      * This also sets the currency symbol attribute to the currency's symbol
 575      * in the DecimalFormatSymbols' locale, and the international currency
 576      * symbol attribute to the currency's ISO 4217 currency code.
 577      *
 578      * @param currency the new currency to be used
 579      * @exception NullPointerException if {@code currency} is null
 580      * @since 1.4
 581      * @see #setCurrencySymbol
 582      * @see #setInternationalCurrencySymbol
 583      */
 584     public void setCurrency(Currency currency) {
 585         if (currency == null) {
 586             throw new NullPointerException();
 587         }
 588         initializeCurrency(locale);
 589         this.currency = currency;
 590         intlCurrencySymbol = currency.getCurrencyCode();
 591         currencySymbol = currency.getSymbol(locale);
 592     }
 593 
 594 
 595     /**
 596      * Returns the monetary decimal separator.
 597      *
 598      * @return the monetary decimal separator
 599      * @since 1.2


 635      * @since 1.6
 636      */
 637     public String getExponentSeparator()
 638     {
 639         return exponentialSeparator;
 640     }
 641 
 642     /**
 643      * Sets the character used to separate the mantissa from the exponent.
 644      */
 645     void setExponentialSymbol(char exp)
 646     {
 647         exponential = exp;
 648     }
 649 
 650     /**
 651      * Sets the string used to separate the mantissa from the exponent.
 652      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
 653      *
 654      * @param exp the exponent separator string
 655      * @exception NullPointerException if {@code exp} is null
 656      * @see #getExponentSeparator()
 657      * @since 1.6
 658      */
 659     public void setExponentSeparator(String exp)
 660     {
 661         if (exp == null) {
 662             throw new NullPointerException();
 663         }
 664         exponentialSeparator = exp;
 665     }
 666 
 667 
 668     //------------------------------------------------------------
 669     // END     Package Private methods ... to be made public later
 670     //------------------------------------------------------------
 671 
 672     /**
 673      * Standard override.
 674      */
 675     @Override


 678             return (DecimalFormatSymbols)super.clone();
 679             // other fields are bit-copied
 680         } catch (CloneNotSupportedException e) {
 681             throw new InternalError(e);
 682         }
 683     }
 684 
 685     /**
 686      * Override equals.
 687      */
 688     @Override
 689     public boolean equals(Object obj) {
 690         if (obj == null) return false;
 691         if (this == obj) return true;
 692         if (getClass() != obj.getClass()) return false;
 693         DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
 694         return (zeroDigit == other.zeroDigit &&
 695         groupingSeparator == other.groupingSeparator &&
 696         decimalSeparator == other.decimalSeparator &&
 697         percent == other.percent &&
 698         percentText.equals(other.percentText) &&
 699         perMill == other.perMill &&
 700         perMillText.equals(other.perMillText) &&
 701         digit == other.digit &&
 702         minusSign == other.minusSign &&
 703         minusSignText.equals(other.minusSignText) &&
 704         patternSeparator == other.patternSeparator &&
 705         infinity.equals(other.infinity) &&
 706         NaN.equals(other.NaN) &&
 707         getCurrencySymbol().equals(other.getCurrencySymbol()) && // possible currency init occurs here
 708         intlCurrencySymbol.equals(other.intlCurrencySymbol) &&
 709         currency == other.currency &&
 710         monetarySeparator == other.monetarySeparator &&
 711         exponentialSeparator.equals(other.exponentialSeparator) &&
 712         locale.equals(other.locale));
 713     }
 714 
 715     /**
 716      * Override hashCode.
 717      */
 718     @Override
 719     public int hashCode() {
 720             int result = zeroDigit;
 721             result = result * 37 + groupingSeparator;
 722             result = result * 37 + decimalSeparator;
 723             return result;


 729     private void initialize( Locale locale ) {
 730         this.locale = locale;
 731 
 732         // check for region override
 733         Locale override = locale.getUnicodeLocaleType("nu") == null ?
 734             CalendarDataUtility.findRegionOverride(locale) :
 735             locale;
 736 
 737         // get resource bundle data
 738         LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, override);
 739         // Avoid potential recursions
 740         if (!(adapter instanceof ResourceBundleBasedAdapter)) {
 741             adapter = LocaleProviderAdapter.getResourceBundleBased();
 742         }
 743         Object[] data = adapter.getLocaleResources(override).getDecimalFormatSymbolsData();
 744         String[] numberElements = (String[]) data[0];
 745 
 746         decimalSeparator = numberElements[0].charAt(0);
 747         groupingSeparator = numberElements[1].charAt(0);
 748         patternSeparator = numberElements[2].charAt(0);
 749         percentText = numberElements[3];
 750         percent = findNonFormatChar(percentText, '%');
 751         zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
 752         digit = numberElements[5].charAt(0);
 753         minusSignText = numberElements[6];
 754         minusSign = findNonFormatChar(minusSignText, '-');
 755         exponential = numberElements[7].charAt(0);
 756         exponentialSeparator = numberElements[7]; //string representation new since 1.6
 757         perMillText = numberElements[8];
 758         perMill = findNonFormatChar(perMillText, '\u2030');
 759         infinity  = numberElements[9];
 760         NaN = numberElements[10];
 761 
 762         // maybe filled with previously cached values, or null.
 763         intlCurrencySymbol = (String) data[1];
 764         currencySymbol = (String) data[2];
 765 
 766         // Currently the monetary decimal separator is the same as the
 767         // standard decimal separator for all locales that we support.
 768         // If that changes, add a new entry to NumberElements.
 769         monetarySeparator = decimalSeparator;
 770     }
 771 
 772     /**
 773      * Obtains non-format single character from String
 774      */
 775     private char findNonFormatChar(String src, char defChar) {
 776         return (char)src.chars()
 777             .filter(c -> Character.getType(c) != Character.FORMAT)
 778             .findFirst()
 779             .orElse(defChar);
 780     }
 781 
 782     /**
 783      * Lazy initialization for currency related fields
 784      */
 785     private void initializeCurrency(Locale locale) {
 786         if (currencyInitialized) {
 787             return;
 788         }
 789 
 790         // Try to obtain the currency used in the locale's country.
 791         // Check for empty country string separately because it's a valid
 792         // country ID for Locale (and used for the C locale), but not a valid
 793         // ISO 3166 country code, and exceptions are expensive.
 794         if (!locale.getCountry().isEmpty()) {
 795             try {
 796                 currency = Currency.getInstance(locale);
 797             } catch (IllegalArgumentException e) {
 798                 // use default values below for compatibility
 799             }
 800         }
 801 
 802         if (currency != null) {


 815                 currencySymbol = currency.getSymbol(locale);
 816                 data[1] = intlCurrencySymbol;
 817                 data[2] = currencySymbol;
 818             }
 819         } else {
 820             // default values
 821             intlCurrencySymbol = "XXX";
 822             try {
 823                 currency = Currency.getInstance(intlCurrencySymbol);
 824             } catch (IllegalArgumentException e) {
 825             }
 826             currencySymbol = "\u00A4";
 827         }
 828 
 829         currencyInitialized = true;
 830     }
 831 
 832     /**
 833      * Reads the default serializable fields, provides default values for objects
 834      * in older serial versions, and initializes non-serializable fields.
 835      * If {@code serialVersionOnStream}
 836      * is less than 1, initializes {@code monetarySeparator} to be
 837      * the same as {@code decimalSeparator} and {@code exponential}
 838      * to be 'E'.
 839      * If {@code serialVersionOnStream} is less than 2,
 840      * initializes {@code locale}to the root locale, and initializes
 841      * If {@code serialVersionOnStream} is less than 3, it initializes
 842      * {@code exponentialSeparator} using {@code exponential}.
 843      * If {@code serialVersionOnStream} is less than 4, it initializes
 844      * {@code perMillText}, {@code percentText}, and
 845      * {@code minusSignText} using {@code perMill}, {@code percent}, and
 846      * {@code minusSign} respectively.
 847      * Sets {@code serialVersionOnStream} back to the maximum allowed value so that
 848      * default serialization will work properly if this object is streamed out again.
 849      * Initializes the currency from the intlCurrencySymbol field.
 850      *
 851      * @throws InvalidObjectException if {@code char} and {@code String}
 852      *      representations of either percent, per mille, and/or minus sign disagree.
 853      * @since  1.1.6
 854      */
 855     private void readObject(ObjectInputStream stream)
 856             throws IOException, ClassNotFoundException {
 857         stream.defaultReadObject();
 858         if (serialVersionOnStream < 1) {
 859             // Didn't have monetarySeparator or exponential field;
 860             // use defaults.
 861             monetarySeparator = decimalSeparator;
 862             exponential       = 'E';
 863         }
 864         if (serialVersionOnStream < 2) {
 865             // didn't have locale; use root locale
 866             locale = Locale.ROOT;
 867         }
 868         if (serialVersionOnStream < 3) {
 869             // didn't have exponentialSeparator. Create one using exponential
 870             exponentialSeparator = Character.toString(exponential);
 871         }
 872         if (serialVersionOnStream < 4) {
 873             // didn't have perMillText, percentText, and minusSignText.
 874             // Create one using corresponding char variations.
 875             perMillText = Character.toString(perMill);
 876             percentText = Character.toString(percent);
 877             minusSignText = Character.toString(minusSign);
 878         } else {
 879             // Check whether char and text fields agree
 880             if (findNonFormatChar(perMillText, '\uFFFF') != perMill ||
 881                 findNonFormatChar(percentText, '\uFFFF') != percent ||
 882                 findNonFormatChar(minusSignText, '\uFFFF') != minusSign) {
 883                 throw new InvalidObjectException(
 884                     "'char' and 'String' representations of either percent, " +
 885                     "per mille, and/or minus sign disagree.");
 886             }
 887         }
 888 
 889         serialVersionOnStream = currentSerialVersion;
 890 
 891         if (intlCurrencySymbol != null) {
 892             try {
 893                  currency = Currency.getInstance(intlCurrencySymbol);
 894             } catch (IllegalArgumentException e) {
 895             }
 896             currencyInitialized = true;
 897         }
 898     }
 899 
 900     /**
 901      * Character used for zero.
 902      *
 903      * @serial
 904      * @see #getZeroDigit
 905      */
 906     private  char    zeroDigit;
 907 
 908     /**


 996      */
 997     private  char    monetarySeparator; // Field new in JDK 1.1.6
 998 
 999     /**
1000      * The character used to distinguish the exponent in a number formatted
1001      * in exponential notation, e.g. 'E' for a number such as "1.23E45".
1002      * <p>
1003      * Note that the public API provides no way to set this field,
1004      * even though it is supported by the implementation and the stream format.
1005      * The intent is that this will be added to the API in the future.
1006      *
1007      * @serial
1008      * @since  1.1.6
1009      */
1010     private  char    exponential;       // Field new in JDK 1.1.6
1011 
1012     /**
1013      * The string used to separate the mantissa from the exponent.
1014      * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
1015      * <p>
1016      * If both {@code exponential} and {@code exponentialSeparator}
1017      * exist, this {@code exponentialSeparator} has the precedence.
1018      *
1019      * @serial
1020      * @since 1.6
1021      */
1022     private  String    exponentialSeparator;       // Field new in JDK 1.6
1023 
1024     /**
1025      * The locale of these currency format symbols.
1026      *
1027      * @serial
1028      * @since 1.4
1029      */
1030     private Locale locale;
1031 
1032     /**
1033      * String representation of per mille sign, which may include 
1034      * formatting characters, such as BiDi control characters.
1035      * The first non-format character of this string is the same as
1036      * {@code perMill}.
1037      *
1038      * @serial
1039      * @since 13
1040      */
1041     private  String perMillText;
1042 
1043     /**
1044      * String representation of percent sign, which may include
1045      * formatting characters, such as BiDi control characters.
1046      * The first non-format character of this string is the same as
1047      * {@code percent}.
1048      *
1049      * @serial
1050      * @since 13
1051      */
1052     private  String percentText;
1053 
1054     /**
1055      * String representation of minus sign, which may include
1056      * formatting characters, such as BiDi control characters.
1057      * The first non-format character of this string is the same as
1058      * {@code minusSign}.
1059      *
1060      * @serial
1061      * @since 13
1062      */
1063     private  String minusSignText;
1064 
1065     // currency; only the ISO code is serialized.
1066     private transient Currency currency;
1067     private transient volatile boolean currencyInitialized;
1068 
1069     // Proclaim JDK 1.1 FCS compatibility
1070     static final long serialVersionUID = 5772796243397350300L;
1071 
1072     // The internal serial version which says which version was written
1073     // - 0 (default) for version up to JDK 1.1.5
1074     // - 1 for version from JDK 1.1.6, which includes two new fields:
1075     //     monetarySeparator and exponential.
1076     // - 2 for version from J2SE 1.4, which includes locale field.
1077     // - 3 for version from J2SE 1.6, which includes exponentialSeparator field.
1078     // - 4 for version from Java SE 13, which includes perMillText, percentText,
1079     //      and minusSignText field.
1080     private static final int currentSerialVersion = 4;
1081 
1082     /**
1083      * Describes the version of {@code DecimalFormatSymbols} present on the stream.
1084      * Possible values are:
1085      * <ul>
1086      * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
1087      *
1088      * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include
1089      *      two new fields: {@code monetarySeparator} and {@code exponential}.
1090      * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a
1091      *      new {@code locale} field.
1092      * <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a
1093      *      new {@code exponentialSeparator} field.
1094      * <li><b>4</b>: Versions written by Java SE 13 or later, which include
1095      *      new {@code perMillText}, {@code percentText}, and
1096      *      {@code minusSignText} field.
1097      * </ul>
1098      * When streaming out a {@code DecimalFormatSymbols}, the most recent format
1099      * (corresponding to the highest allowable {@code serialVersionOnStream})
1100      * is always written.
1101      *
1102      * @serial
1103      * @since  1.1.6
1104      */
1105     private int serialVersionOnStream = currentSerialVersion;
1106 }
< prev index next >