Path: blob/master/src/java.base/share/classes/java/text/DecimalFormatSymbols.java
41152 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved27* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved28*29* The original version of this source code and documentation is copyrighted30* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These31* materials are provided under terms of a License Agreement between Taligent32* and Sun. This technology is protected by multiple US and International33* patents. This notice and attribution to Taligent may not be removed.34* Taligent is a registered trademark of Taligent, Inc.35*36*/3738package java.text;3940import java.io.InvalidObjectException;41import java.io.IOException;42import java.io.ObjectInputStream;43import java.io.Serializable;44import java.text.spi.DecimalFormatSymbolsProvider;45import java.util.Currency;46import java.util.Locale;47import java.util.Objects;48import sun.util.locale.provider.CalendarDataUtility;49import sun.util.locale.provider.LocaleProviderAdapter;50import sun.util.locale.provider.LocaleServiceProviderPool;51import sun.util.locale.provider.ResourceBundleBasedAdapter;5253/**54* This class represents the set of symbols (such as the decimal separator,55* the grouping separator, and so on) needed by {@code DecimalFormat}56* to format numbers. {@code DecimalFormat} creates for itself an instance of57* {@code DecimalFormatSymbols} from its locale data. If you need to change any58* of these symbols, you can get the {@code DecimalFormatSymbols} object from59* your {@code DecimalFormat} and modify it.60*61* <p>If the locale contains "rg" (region override)62* <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,63* the symbols are overridden for the designated region.64*65* @see java.util.Locale66* @see DecimalFormat67* @author Mark Davis68* @author Alan Liu69* @since 1.170*/7172public class DecimalFormatSymbols implements Cloneable, Serializable {7374/**75* Create a DecimalFormatSymbols object for the default76* {@link java.util.Locale.Category#FORMAT FORMAT} locale.77* This constructor can only construct instances for the locales78* supported by the Java runtime environment, not for those79* supported by installed80* {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}81* implementations. For full locale coverage, use the82* {@link #getInstance(Locale) getInstance} method.83* <p>This is equivalent to calling84* {@link #DecimalFormatSymbols(Locale)85* DecimalFormatSymbols(Locale.getDefault(Locale.Category.FORMAT))}.86* @see java.util.Locale#getDefault(java.util.Locale.Category)87* @see java.util.Locale.Category#FORMAT88*/89public DecimalFormatSymbols() {90initialize( Locale.getDefault(Locale.Category.FORMAT) );91}9293/**94* Create a DecimalFormatSymbols object for the given locale.95* This constructor can only construct instances for the locales96* supported by the Java runtime environment, not for those97* supported by installed98* {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}99* implementations. For full locale coverage, use the100* {@link #getInstance(Locale) getInstance} method.101* If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}102* for the numbering system, the instance is initialized with the specified numbering103* system if the JRE implementation supports it. For example,104* <pre>105* NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))106* </pre>107* This may return a {@code NumberFormat} instance with the Thai numbering system,108* instead of the Latin numbering system.109*110* @param locale the desired locale111* @throws NullPointerException if {@code locale} is null112*/113public DecimalFormatSymbols( Locale locale ) {114initialize( locale );115}116117/**118* Returns an array of all locales for which the119* {@code getInstance} methods of this class can return120* localized instances.121* The returned array represents the union of locales supported by the Java122* runtime and by installed123* {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}124* implementations. It must contain at least a {@code Locale}125* instance equal to {@link java.util.Locale#US Locale.US}.126*127* @return an array of locales for which localized128* {@code DecimalFormatSymbols} instances are available.129* @since 1.6130*/131public static Locale[] getAvailableLocales() {132LocaleServiceProviderPool pool =133LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);134return pool.getAvailableLocales();135}136137/**138* Gets the {@code DecimalFormatSymbols} instance for the default139* locale. This method provides access to {@code DecimalFormatSymbols}140* instances for locales supported by the Java runtime itself as well141* as for those supported by installed142* {@link java.text.spi.DecimalFormatSymbolsProvider143* DecimalFormatSymbolsProvider} implementations.144* <p>This is equivalent to calling145* {@link #getInstance(Locale)146* getInstance(Locale.getDefault(Locale.Category.FORMAT))}.147* @see java.util.Locale#getDefault(java.util.Locale.Category)148* @see java.util.Locale.Category#FORMAT149* @return a {@code DecimalFormatSymbols} instance.150* @since 1.6151*/152public static final DecimalFormatSymbols getInstance() {153return getInstance(Locale.getDefault(Locale.Category.FORMAT));154}155156/**157* Gets the {@code DecimalFormatSymbols} instance for the specified158* locale. This method provides access to {@code DecimalFormatSymbols}159* instances for locales supported by the Java runtime itself as well160* as for those supported by installed161* {@link java.text.spi.DecimalFormatSymbolsProvider162* DecimalFormatSymbolsProvider} implementations.163* If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}164* for the numbering system, the instance is initialized with the specified numbering165* system if the JRE implementation supports it. For example,166* <pre>167* NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))168* </pre>169* This may return a {@code NumberFormat} instance with the Thai numbering system,170* instead of the Latin numbering system.171*172* @param locale the desired locale.173* @return a {@code DecimalFormatSymbols} instance.174* @throws NullPointerException if {@code locale} is null175* @since 1.6176*/177public static final DecimalFormatSymbols getInstance(Locale locale) {178LocaleProviderAdapter adapter;179adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);180DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();181DecimalFormatSymbols dfsyms = provider.getInstance(locale);182if (dfsyms == null) {183provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();184dfsyms = provider.getInstance(locale);185}186return dfsyms;187}188189/**190* Gets the character used for zero. Different for Arabic, etc.191*192* @return the character used for zero193*/194public char getZeroDigit() {195return zeroDigit;196}197198/**199* Sets the character used for zero. Different for Arabic, etc.200*201* @param zeroDigit the character used for zero202*/203public void setZeroDigit(char zeroDigit) {204hashCode = 0;205this.zeroDigit = zeroDigit;206}207208/**209* Gets the character used for grouping separator. Different for French, etc.210*211* @return the grouping separator212*/213public char getGroupingSeparator() {214return groupingSeparator;215}216217/**218* Sets the character used for grouping separator. Different for French, etc.219*220* @param groupingSeparator the grouping separator221*/222public void setGroupingSeparator(char groupingSeparator) {223hashCode = 0;224this.groupingSeparator = groupingSeparator;225}226227/**228* Gets the character used for decimal sign. Different for French, etc.229*230* @return the character used for decimal sign231*/232public char getDecimalSeparator() {233return decimalSeparator;234}235236/**237* Sets the character used for decimal sign. Different for French, etc.238*239* @param decimalSeparator the character used for decimal sign240*/241public void setDecimalSeparator(char decimalSeparator) {242hashCode = 0;243this.decimalSeparator = decimalSeparator;244}245246/**247* Gets the character used for per mille sign. Different for Arabic, etc.248*249* @return the character used for per mille sign250*/251public char getPerMill() {252return perMill;253}254255/**256* Sets the character used for per mille sign. Different for Arabic, etc.257*258* @param perMill the character used for per mille sign259*/260public void setPerMill(char perMill) {261hashCode = 0;262this.perMill = perMill;263this.perMillText = Character.toString(perMill);264}265266/**267* Gets the character used for percent sign. Different for Arabic, etc.268*269* @return the character used for percent sign270*/271public char getPercent() {272return percent;273}274275/**276* Sets the character used for percent sign. Different for Arabic, etc.277*278* @param percent the character used for percent sign279*/280public void setPercent(char percent) {281hashCode = 0;282this.percent = percent;283this.percentText = Character.toString(percent);284}285286/**287* Gets the character used for a digit in a pattern.288*289* @return the character used for a digit in a pattern290*/291public char getDigit() {292return digit;293}294295/**296* Sets the character used for a digit in a pattern.297*298* @param digit the character used for a digit in a pattern299*/300public void setDigit(char digit) {301hashCode = 0;302this.digit = digit;303}304305/**306* Gets the character used to separate positive and negative subpatterns307* in a pattern.308*309* @return the pattern separator310*/311public char getPatternSeparator() {312return patternSeparator;313}314315/**316* Sets the character used to separate positive and negative subpatterns317* in a pattern.318*319* @param patternSeparator the pattern separator320*/321public void setPatternSeparator(char patternSeparator) {322hashCode = 0;323this.patternSeparator = patternSeparator;324}325326/**327* Gets the string used to represent infinity. Almost always left328* unchanged.329*330* @return the string representing infinity331*/332public String getInfinity() {333return infinity;334}335336/**337* Sets the string used to represent infinity. Almost always left338* unchanged.339*340* @param infinity the string representing infinity341*/342public void setInfinity(String infinity) {343hashCode = 0;344this.infinity = infinity;345}346347/**348* Gets the string used to represent "not a number". Almost always left349* unchanged.350*351* @return the string representing "not a number"352*/353public String getNaN() {354return NaN;355}356357/**358* Sets the string used to represent "not a number". Almost always left359* unchanged.360*361* @param NaN the string representing "not a number"362*/363public void setNaN(String NaN) {364hashCode = 0;365this.NaN = NaN;366}367368/**369* Gets the character used to represent minus sign. If no explicit370* negative format is specified, one is formed by prefixing371* minusSign to the positive format.372*373* @return the character representing minus sign374*/375public char getMinusSign() {376return minusSign;377}378379/**380* Sets the character used to represent minus sign. If no explicit381* negative format is specified, one is formed by prefixing382* minusSign to the positive format.383*384* @param minusSign the character representing minus sign385*/386public void setMinusSign(char minusSign) {387hashCode = 0;388this.minusSign = minusSign;389this.minusSignText = Character.toString(minusSign);390}391392/**393* Returns the currency symbol for the currency of these394* DecimalFormatSymbols in their locale.395*396* @return the currency symbol397* @since 1.2398*/399public String getCurrencySymbol()400{401initializeCurrency(locale);402return currencySymbol;403}404405/**406* Sets the currency symbol for the currency of these407* DecimalFormatSymbols in their locale.408*409* @param currency the currency symbol410* @since 1.2411*/412public void setCurrencySymbol(String currency)413{414initializeCurrency(locale);415hashCode = 0;416currencySymbol = currency;417}418419/**420* Returns the ISO 4217 currency code of the currency of these421* DecimalFormatSymbols.422*423* @return the currency code424* @since 1.2425*/426public String getInternationalCurrencySymbol()427{428initializeCurrency(locale);429return intlCurrencySymbol;430}431432/**433* Sets the ISO 4217 currency code of the currency of these434* DecimalFormatSymbols.435* If the currency code is valid (as defined by436* {@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),437* this also sets the currency attribute to the corresponding Currency438* instance and the currency symbol attribute to the currency's symbol439* in the DecimalFormatSymbols' locale. If the currency code is not valid,440* then the currency attribute is set to null and the currency symbol441* attribute is not modified.442*443* @param currencyCode the currency code444* @see #setCurrency445* @see #setCurrencySymbol446* @since 1.2447*/448public void setInternationalCurrencySymbol(String currencyCode)449{450initializeCurrency(locale);451hashCode = 0;452intlCurrencySymbol = currencyCode;453currency = null;454if (currencyCode != null) {455try {456currency = Currency.getInstance(currencyCode);457currencySymbol = currency.getSymbol();458} catch (IllegalArgumentException e) {459}460}461}462463/**464* Gets the currency of these DecimalFormatSymbols. May be null if the465* currency symbol attribute was previously set to a value that's not466* a valid ISO 4217 currency code.467*468* @return the currency used, or null469* @since 1.4470*/471public Currency getCurrency() {472initializeCurrency(locale);473return currency;474}475476/**477* Sets the currency of these DecimalFormatSymbols.478* This also sets the currency symbol attribute to the currency's symbol479* in the DecimalFormatSymbols' locale, and the international currency480* symbol attribute to the currency's ISO 4217 currency code.481*482* @param currency the new currency to be used483* @throws NullPointerException if {@code currency} is null484* @since 1.4485* @see #setCurrencySymbol486* @see #setInternationalCurrencySymbol487*/488public void setCurrency(Currency currency) {489if (currency == null) {490throw new NullPointerException();491}492initializeCurrency(locale);493hashCode = 0;494this.currency = currency;495intlCurrencySymbol = currency.getCurrencyCode();496currencySymbol = currency.getSymbol(locale);497}498499500/**501* Returns the monetary decimal separator.502*503* @return the monetary decimal separator504* @since 1.2505*/506public char getMonetaryDecimalSeparator()507{508return monetarySeparator;509}510511/**512* Sets the monetary decimal separator.513*514* @param sep the monetary decimal separator515* @since 1.2516*/517public void setMonetaryDecimalSeparator(char sep)518{519hashCode = 0;520monetarySeparator = sep;521}522523/**524* Returns the string used to separate the mantissa from the exponent.525* Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.526*527* @return the exponent separator string528* @see #setExponentSeparator(java.lang.String)529* @since 1.6530*/531public String getExponentSeparator()532{533return exponentialSeparator;534}535536/**537* Sets the string used to separate the mantissa from the exponent.538* Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.539*540* @param exp the exponent separator string541* @throws NullPointerException if {@code exp} is null542* @see #getExponentSeparator()543* @since 1.6544*/545public void setExponentSeparator(String exp)546{547if (exp == null) {548throw new NullPointerException();549}550hashCode = 0;551exponentialSeparator = exp;552}553554/**555* Gets the character used for grouping separator for currencies.556* May be different from {@code grouping separator} in some locales,557* e.g, German in Austria.558*559* @return the monetary grouping separator560* @since 15561*/562public char getMonetaryGroupingSeparator() {563return monetaryGroupingSeparator;564}565566/**567* Sets the character used for grouping separator for currencies.568* Invocation of this method will not affect the normal569* {@code grouping separator}.570*571* @param monetaryGroupingSeparator the monetary grouping separator572* @see #setGroupingSeparator(char)573* @since 15574*/575public void setMonetaryGroupingSeparator(char monetaryGroupingSeparator)576{577hashCode = 0;578this.monetaryGroupingSeparator = monetaryGroupingSeparator;579}580581//------------------------------------------------------------582// BEGIN Package Private methods ... to be made public later583//------------------------------------------------------------584585/**586* Returns the character used to separate the mantissa from the exponent.587*/588char getExponentialSymbol()589{590return exponential;591}592593/**594* Sets the character used to separate the mantissa from the exponent.595*/596void setExponentialSymbol(char exp)597{598exponential = exp;599}600601/**602* Gets the string used for per mille sign. Different for Arabic, etc.603*604* @return the string used for per mille sign605* @since 13606*/607String getPerMillText() {608return perMillText;609}610611/**612* Sets the string used for per mille sign. Different for Arabic, etc.613*614* Setting the {@code perMillText} affects the return value of615* {@link #getPerMill()}, in which the first non-format character of616* {@code perMillText} is returned.617*618* @param perMillText the string used for per mille sign619* @throws NullPointerException if {@code perMillText} is null620* @throws IllegalArgumentException if {@code perMillText} is an empty string621* @see #getPerMill()622* @see #getPerMillText()623* @since 13624*/625void setPerMillText(String perMillText) {626Objects.requireNonNull(perMillText);627if (perMillText.isEmpty()) {628throw new IllegalArgumentException("Empty argument string");629}630631hashCode = 0;632this.perMillText = perMillText;633this.perMill = findNonFormatChar(perMillText, '\u2030');634}635636/**637* Gets the string used for percent sign. Different for Arabic, etc.638*639* @return the string used for percent sign640* @since 13641*/642String getPercentText() {643return percentText;644}645646/**647* Sets the string used for percent sign. Different for Arabic, etc.648*649* Setting the {@code percentText} affects the return value of650* {@link #getPercent()}, in which the first non-format character of651* {@code percentText} is returned.652*653* @param percentText the string used for percent sign654* @throws NullPointerException if {@code percentText} is null655* @throws IllegalArgumentException if {@code percentText} is an empty string656* @see #getPercent()657* @see #getPercentText()658* @since 13659*/660void setPercentText(String percentText) {661Objects.requireNonNull(percentText);662if (percentText.isEmpty()) {663throw new IllegalArgumentException("Empty argument string");664}665666hashCode = 0;667this.percentText = percentText;668this.percent = findNonFormatChar(percentText, '%');669}670671/**672* Gets the string used to represent minus sign. If no explicit673* negative format is specified, one is formed by prefixing674* minusSignText to the positive format.675*676* @return the string representing minus sign677* @since 13678*/679String getMinusSignText() {680return minusSignText;681}682683/**684* Sets the string used to represent minus sign. If no explicit685* negative format is specified, one is formed by prefixing686* minusSignText to the positive format.687*688* Setting the {@code minusSignText} affects the return value of689* {@link #getMinusSign()}, in which the first non-format character of690* {@code minusSignText} is returned.691*692* @param minusSignText the character representing minus sign693* @throws NullPointerException if {@code minusSignText} is null694* @throws IllegalArgumentException if {@code minusSignText} is an695* empty string696* @see #getMinusSign()697* @see #getMinusSignText()698* @since 13699*/700void setMinusSignText(String minusSignText) {701Objects.requireNonNull(minusSignText);702if (minusSignText.isEmpty()) {703throw new IllegalArgumentException("Empty argument string");704}705706hashCode = 0;707this.minusSignText = minusSignText;708this.minusSign = findNonFormatChar(minusSignText, '-');709}710711//------------------------------------------------------------712// END Package Private methods ... to be made public later713//------------------------------------------------------------714715/**716* Standard override.717*/718@Override719public Object clone() {720try {721return (DecimalFormatSymbols)super.clone();722// other fields are bit-copied723} catch (CloneNotSupportedException e) {724throw new InternalError(e);725}726}727728/**729* Override equals.730*/731@Override732public boolean equals(Object obj) {733if (obj == null) return false;734if (this == obj) return true;735if (getClass() != obj.getClass()) return false;736DecimalFormatSymbols other = (DecimalFormatSymbols) obj;737return (zeroDigit == other.zeroDigit &&738groupingSeparator == other.groupingSeparator &&739decimalSeparator == other.decimalSeparator &&740percent == other.percent &&741percentText.equals(other.percentText) &&742perMill == other.perMill &&743perMillText.equals(other.perMillText) &&744digit == other.digit &&745minusSign == other.minusSign &&746minusSignText.equals(other.minusSignText) &&747patternSeparator == other.patternSeparator &&748infinity.equals(other.infinity) &&749NaN.equals(other.NaN) &&750getCurrencySymbol().equals(other.getCurrencySymbol()) && // possible currency init occurs here751intlCurrencySymbol.equals(other.intlCurrencySymbol) &&752currency == other.currency &&753monetarySeparator == other.monetarySeparator &&754monetaryGroupingSeparator == other.monetaryGroupingSeparator &&755exponentialSeparator.equals(other.exponentialSeparator) &&756locale.equals(other.locale));757}758759/**760* Override hashCode.761*/762@Override763public int hashCode() {764if (hashCode == 0) {765hashCode = Objects.hash(766zeroDigit,767groupingSeparator,768decimalSeparator,769percent,770percentText,771perMill,772perMillText,773digit,774minusSign,775minusSignText,776patternSeparator,777infinity,778NaN,779getCurrencySymbol(), // possible currency init occurs here780intlCurrencySymbol,781currency,782monetarySeparator,783monetaryGroupingSeparator,784exponentialSeparator,785locale);786}787return hashCode;788}789790/**791* Initializes the symbols from the FormatData resource bundle.792*/793private void initialize( Locale locale ) {794this.locale = locale;795796// check for region override797Locale override = locale.getUnicodeLocaleType("nu") == null ?798CalendarDataUtility.findRegionOverride(locale) :799locale;800801// get resource bundle data802LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, override);803// Avoid potential recursions804if (!(adapter instanceof ResourceBundleBasedAdapter)) {805adapter = LocaleProviderAdapter.getResourceBundleBased();806}807Object[] data = adapter.getLocaleResources(override).getDecimalFormatSymbolsData();808String[] numberElements = (String[]) data[0];809810decimalSeparator = numberElements[0].charAt(0);811groupingSeparator = numberElements[1].charAt(0);812patternSeparator = numberElements[2].charAt(0);813percentText = numberElements[3];814percent = findNonFormatChar(percentText, '%');815zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.816digit = numberElements[5].charAt(0);817minusSignText = numberElements[6];818minusSign = findNonFormatChar(minusSignText, '-');819exponential = numberElements[7].charAt(0);820exponentialSeparator = numberElements[7]; //string representation new since 1.6821perMillText = numberElements[8];822perMill = findNonFormatChar(perMillText, '\u2030');823infinity = numberElements[9];824NaN = numberElements[10];825826// monetary decimal/grouping separators may be missing in resource bundles827monetarySeparator = numberElements.length < 12 || numberElements[11].isEmpty() ?828decimalSeparator : numberElements[11].charAt(0);829monetaryGroupingSeparator = numberElements.length < 13 || numberElements[12].isEmpty() ?830groupingSeparator : numberElements[12].charAt(0);831832// maybe filled with previously cached values, or null.833intlCurrencySymbol = (String) data[1];834currencySymbol = (String) data[2];835}836837/**838* Obtains non-format single character from String839*/840private char findNonFormatChar(String src, char defChar) {841return (char)src.chars()842.filter(c -> Character.getType(c) != Character.FORMAT)843.findFirst()844.orElse(defChar);845}846847/**848* Lazy initialization for currency related fields849*/850private void initializeCurrency(Locale locale) {851if (currencyInitialized) {852return;853}854855// Try to obtain the currency used in the locale's country.856// Check for empty country string separately because it's a valid857// country ID for Locale (and used for the C locale), but not a valid858// ISO 3166 country code, and exceptions are expensive.859if (!locale.getCountry().isEmpty()) {860try {861currency = Currency.getInstance(locale);862} catch (IllegalArgumentException e) {863// use default values below for compatibility864}865}866867if (currency != null) {868// get resource bundle data869LocaleProviderAdapter adapter =870LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);871// Avoid potential recursions872if (!(adapter instanceof ResourceBundleBasedAdapter)) {873adapter = LocaleProviderAdapter.getResourceBundleBased();874}875Object[] data = adapter.getLocaleResources(locale).getDecimalFormatSymbolsData();876intlCurrencySymbol = currency.getCurrencyCode();877if (data[1] != null && data[1] == intlCurrencySymbol) {878currencySymbol = (String) data[2];879} else {880currencySymbol = currency.getSymbol(locale);881data[1] = intlCurrencySymbol;882data[2] = currencySymbol;883}884} else {885// default values886intlCurrencySymbol = "XXX";887try {888currency = Currency.getInstance(intlCurrencySymbol);889} catch (IllegalArgumentException e) {890}891currencySymbol = "\u00A4";892}893894currencyInitialized = true;895}896897/**898* Reads the default serializable fields, provides default values for objects899* in older serial versions, and initializes non-serializable fields.900* If {@code serialVersionOnStream}901* is less than 1, initializes {@code monetarySeparator} to be902* the same as {@code decimalSeparator} and {@code exponential}903* to be 'E'.904* If {@code serialVersionOnStream} is less than 2,905* initializes {@code locale} to the root locale, and initializes906* If {@code serialVersionOnStream} is less than 3, it initializes907* {@code exponentialSeparator} using {@code exponential}.908* If {@code serialVersionOnStream} is less than 4, it initializes909* {@code perMillText}, {@code percentText}, and910* {@code minusSignText} using {@code perMill}, {@code percent}, and911* {@code minusSign} respectively.912* If {@code serialVersionOnStream} is less than 5, it initializes913* {@code monetaryGroupingSeparator} using {@code groupingSeparator}.914* Sets {@code serialVersionOnStream} back to the maximum allowed value so that915* default serialization will work properly if this object is streamed out again.916* Initializes the currency from the intlCurrencySymbol field.917*918* @throws InvalidObjectException if {@code char} and {@code String}919* representations of either percent, per mille, and/or minus sign disagree.920* @since 1.1.6921*/922@java.io.Serial923private void readObject(ObjectInputStream stream)924throws IOException, ClassNotFoundException {925stream.defaultReadObject();926if (serialVersionOnStream < 1) {927// Didn't have monetarySeparator or exponential field;928// use defaults.929monetarySeparator = decimalSeparator;930exponential = 'E';931}932if (serialVersionOnStream < 2) {933// didn't have locale; use root locale934locale = Locale.ROOT;935}936if (serialVersionOnStream < 3) {937// didn't have exponentialSeparator. Create one using exponential938exponentialSeparator = Character.toString(exponential);939}940if (serialVersionOnStream < 4) {941// didn't have perMillText, percentText, and minusSignText.942// Create one using corresponding char variations.943perMillText = Character.toString(perMill);944percentText = Character.toString(percent);945minusSignText = Character.toString(minusSign);946} else {947// Check whether char and text fields agree948if (findNonFormatChar(perMillText, '\uFFFF') != perMill ||949findNonFormatChar(percentText, '\uFFFF') != percent ||950findNonFormatChar(minusSignText, '\uFFFF') != minusSign) {951throw new InvalidObjectException(952"'char' and 'String' representations of either percent, " +953"per mille, and/or minus sign disagree.");954}955}956if (serialVersionOnStream < 5) {957// didn't have monetaryGroupingSeparator. Create one using groupingSeparator958monetaryGroupingSeparator = groupingSeparator;959}960961serialVersionOnStream = currentSerialVersion;962963if (intlCurrencySymbol != null) {964try {965currency = Currency.getInstance(intlCurrencySymbol);966} catch (IllegalArgumentException e) {967}968currencyInitialized = true;969}970}971972/**973* Character used for zero.974*975* @serial976* @see #getZeroDigit977*/978private char zeroDigit;979980/**981* Character used for grouping separator.982*983* @serial984* @see #getGroupingSeparator985*/986private char groupingSeparator;987988/**989* Character used for decimal sign.990*991* @serial992* @see #getDecimalSeparator993*/994private char decimalSeparator;995996/**997* Character used for per mille sign.998*999* @serial1000* @see #getPerMill1001*/1002private char perMill;10031004/**1005* Character used for percent sign.1006* @serial1007* @see #getPercent1008*/1009private char percent;10101011/**1012* Character used for a digit in a pattern.1013*1014* @serial1015* @see #getDigit1016*/1017private char digit;10181019/**1020* Character used to separate positive and negative subpatterns1021* in a pattern.1022*1023* @serial1024* @see #getPatternSeparator1025*/1026private char patternSeparator;10271028/**1029* String used to represent infinity.1030* @serial1031* @see #getInfinity1032*/1033private String infinity;10341035/**1036* String used to represent "not a number".1037* @serial1038* @see #getNaN1039*/1040private String NaN;10411042/**1043* Character used to represent minus sign.1044* @serial1045* @see #getMinusSign1046*/1047private char minusSign;10481049/**1050* String denoting the local currency, e.g. "$".1051* @serial1052* @see #getCurrencySymbol1053*/1054private String currencySymbol;10551056/**1057* ISO 4217 currency code denoting the local currency, e.g. "USD".1058* @serial1059* @see #getInternationalCurrencySymbol1060*/1061private String intlCurrencySymbol;10621063/**1064* The decimal separator used when formatting currency values.1065* @serial1066* @since 1.1.61067* @see #getMonetaryDecimalSeparator1068*/1069private char monetarySeparator; // Field new in JDK 1.1.610701071/**1072* The character used to distinguish the exponent in a number formatted1073* in exponential notation, e.g. 'E' for a number such as "1.23E45".1074* <p>1075* Note that the public API provides no way to set this field,1076* even though it is supported by the implementation and the stream format.1077* The intent is that this will be added to the API in the future.1078*1079* @serial1080* @since 1.1.61081*/1082private char exponential; // Field new in JDK 1.1.610831084/**1085* The string used to separate the mantissa from the exponent.1086* Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.1087* <p>1088* If both {@code exponential} and {@code exponentialSeparator}1089* exist, this {@code exponentialSeparator} has the precedence.1090*1091* @serial1092* @since 1.61093*/1094private String exponentialSeparator; // Field new in JDK 1.610951096/**1097* The locale of these currency format symbols.1098*1099* @serial1100* @since 1.41101*/1102private Locale locale;11031104/**1105* String representation of per mille sign, which may include1106* formatting characters, such as BiDi control characters.1107* The first non-format character of this string is the same as1108* {@code perMill}.1109*1110* @serial1111* @since 131112*/1113private String perMillText;11141115/**1116* String representation of percent sign, which may include1117* formatting characters, such as BiDi control characters.1118* The first non-format character of this string is the same as1119* {@code percent}.1120*1121* @serial1122* @since 131123*/1124private String percentText;11251126/**1127* String representation of minus sign, which may include1128* formatting characters, such as BiDi control characters.1129* The first non-format character of this string is the same as1130* {@code minusSign}.1131*1132* @serial1133* @since 131134*/1135private String minusSignText;11361137/**1138* The grouping separator used when formatting currency values.1139*1140* @serial1141* @since 151142*/1143private char monetaryGroupingSeparator;11441145// currency; only the ISO code is serialized.1146private transient Currency currency;1147private transient volatile boolean currencyInitialized;11481149/**1150* Cached hash code.1151*/1152private transient volatile int hashCode;11531154// Proclaim JDK 1.1 FCS compatibility1155@java.io.Serial1156static final long serialVersionUID = 5772796243397350300L;11571158// The internal serial version which says which version was written1159// - 0 (default) for version up to JDK 1.1.51160// - 1 for version from JDK 1.1.6, which includes two new fields:1161// monetarySeparator and exponential.1162// - 2 for version from J2SE 1.4, which includes locale field.1163// - 3 for version from J2SE 1.6, which includes exponentialSeparator field.1164// - 4 for version from Java SE 13, which includes perMillText, percentText,1165// and minusSignText field.1166// - 5 for version from Java SE 15, which includes monetaryGroupingSeparator.1167private static final int currentSerialVersion = 5;11681169/**1170* Describes the version of {@code DecimalFormatSymbols} present on the stream.1171* Possible values are:1172* <ul>1173* <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.1174*1175* <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include1176* two new fields: {@code monetarySeparator} and {@code exponential}.1177* <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a1178* new {@code locale} field.1179* <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a1180* new {@code exponentialSeparator} field.1181* <li><b>4</b>: Versions written by Java SE 13 or later, which include1182* new {@code perMillText}, {@code percentText}, and1183* {@code minusSignText} field.1184* <li><b>5</b>: Versions written by Java SE 15 or later, which include1185* new {@code monetaryGroupingSeparator} field.1186* * </ul>1187* When streaming out a {@code DecimalFormatSymbols}, the most recent format1188* (corresponding to the highest allowable {@code serialVersionOnStream})1189* is always written.1190*1191* @serial1192* @since 1.1.61193*/1194private int serialVersionOnStream = currentSerialVersion;1195}119611971198