< prev index next >

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

Print this page
rev 47733 : 8176841: Additional Unicode Language-Tag Extensions
8189134: New system properties for the default Locale extensions
Reviewed-by:
   1 /*
   2  * Copyright (c) 1996, 2013, 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


  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.LocaleProviderAdapter;
  48 import sun.util.locale.provider.LocaleServiceProviderPool;
  49 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  50 
  51 /**
  52  * This class represents the set of symbols (such as the decimal separator,
  53  * the grouping separator, and so on) needed by <code>DecimalFormat</code>
  54  * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
  55  * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
  56  * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
  57  * your <code>DecimalFormat</code> and modify it.
  58  *




  59  * @see          java.util.Locale
  60  * @see          DecimalFormat
  61  * @author       Mark Davis
  62  * @author       Alan Liu
  63  * @since 1.1
  64  */
  65 
  66 public class DecimalFormatSymbols implements Cloneable, Serializable {
  67 
  68     /**
  69      * Create a DecimalFormatSymbols object for the default
  70      * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
  71      * This constructor can only construct instances for the locales
  72      * supported by the Java runtime environment, not for those
  73      * supported by installed
  74      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
  75      * implementations. For full locale coverage, use the
  76      * {@link #getInstance(Locale) getInstance} method.
  77      * <p>This is equivalent to calling
  78      * {@link #DecimalFormatSymbols(Locale)


 592         locale.equals(other.locale));
 593     }
 594 
 595     /**
 596      * Override hashCode.
 597      */
 598     @Override
 599     public int hashCode() {
 600             int result = zeroDigit;
 601             result = result * 37 + groupingSeparator;
 602             result = result * 37 + decimalSeparator;
 603             return result;
 604     }
 605 
 606     /**
 607      * Initializes the symbols from the FormatData resource bundle.
 608      */
 609     private void initialize( Locale locale ) {
 610         this.locale = locale;
 611 





 612         // get resource bundle data
 613         LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
 614         // Avoid potential recursions
 615         if (!(adapter instanceof ResourceBundleBasedAdapter)) {
 616             adapter = LocaleProviderAdapter.getResourceBundleBased();
 617         }
 618         Object[] data = adapter.getLocaleResources(locale).getDecimalFormatSymbolsData();
 619         String[] numberElements = (String[]) data[0];
 620 
 621         decimalSeparator = numberElements[0].charAt(0);
 622         groupingSeparator = numberElements[1].charAt(0);
 623         patternSeparator = numberElements[2].charAt(0);
 624         percent = numberElements[3].charAt(0);
 625         zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
 626         digit = numberElements[5].charAt(0);
 627         minusSign = numberElements[6].charAt(0);
 628         exponential = numberElements[7].charAt(0);
 629         exponentialSeparator = numberElements[7]; //string representation new since 1.6
 630         perMill = numberElements[8].charAt(0);
 631         infinity  = numberElements[9];
 632         NaN = numberElements[10];
 633 
 634         // maybe filled with previously cached values, or null.
 635         intlCurrencySymbol = (String) data[1];
 636         currencySymbol = (String) data[2];
 637 
 638         // Currently the monetary decimal separator is the same as the


   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


  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 overriden 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
  79      * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
  80      * implementations. For full locale coverage, use the
  81      * {@link #getInstance(Locale) getInstance} method.
  82      * <p>This is equivalent to calling
  83      * {@link #DecimalFormatSymbols(Locale)


 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;
 609     }
 610 
 611     /**
 612      * Initializes the symbols from the FormatData resource bundle.
 613      */
 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).orElse(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


< prev index next >