jdk/src/share/classes/java/text/DecimalFormat.java
changeset 7003 7d8d9506b4ee
parent 6489 9e7015635425
child 10419 12c063b39232
equal deleted inserted replaced
6843:6ab7e78c51eb 7003:7d8d9506b4ee
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    44 import java.math.BigDecimal;
    44 import java.math.BigDecimal;
    45 import java.math.BigInteger;
    45 import java.math.BigInteger;
    46 import java.math.RoundingMode;
    46 import java.math.RoundingMode;
    47 import java.util.ArrayList;
    47 import java.util.ArrayList;
    48 import java.util.Currency;
    48 import java.util.Currency;
    49 import java.util.Hashtable;
       
    50 import java.util.Locale;
    49 import java.util.Locale;
    51 import java.util.ResourceBundle;
    50 import java.util.ResourceBundle;
       
    51 import java.util.concurrent.ConcurrentHashMap;
       
    52 import java.util.concurrent.ConcurrentMap;
    52 import java.util.concurrent.atomic.AtomicInteger;
    53 import java.util.concurrent.atomic.AtomicInteger;
    53 import java.util.concurrent.atomic.AtomicLong;
    54 import java.util.concurrent.atomic.AtomicLong;
    54 import sun.util.resources.LocaleData;
    55 import sun.util.resources.LocaleData;
    55 
    56 
    56 /**
    57 /**
   392      * @see java.text.NumberFormat#getPercentInstance
   393      * @see java.text.NumberFormat#getPercentInstance
   393      */
   394      */
   394     public DecimalFormat() {
   395     public DecimalFormat() {
   395         Locale def = Locale.getDefault(Locale.Category.FORMAT);
   396         Locale def = Locale.getDefault(Locale.Category.FORMAT);
   396         // try to get the pattern from the cache
   397         // try to get the pattern from the cache
   397         String pattern = (String) cachedLocaleData.get(def);
   398         String pattern = cachedLocaleData.get(def);
   398         if (pattern == null) {  /* cache miss */
   399         if (pattern == null) {  /* cache miss */
   399             // Get the pattern for the default locale.
   400             // Get the pattern for the default locale.
   400             ResourceBundle rb = LocaleData.getNumberFormatData(def);
   401             ResourceBundle rb = LocaleData.getNumberFormatData(def);
   401             String[] all = rb.getStringArray("NumberPatterns");
   402             String[] all = rb.getStringArray("NumberPatterns");
   402             pattern = all[0];
   403             pattern = all[0];
   403             /* update cache */
   404             /* update cache */
   404             cachedLocaleData.put(def, pattern);
   405             cachedLocaleData.putIfAbsent(def, pattern);
   405         }
   406         }
   406 
   407 
   407         // Always applyPattern after the symbols are set
   408         // Always applyPattern after the symbols are set
   408         this.symbols = new DecimalFormatSymbols(def);
   409         this.symbols = new DecimalFormatSymbols(def);
   409         applyPattern(pattern, false);
   410         applyPattern(pattern, false);
  3270     static final long serialVersionUID = 864413376551465018L;
  3271     static final long serialVersionUID = 864413376551465018L;
  3271 
  3272 
  3272     /**
  3273     /**
  3273      * Cache to hold the NumberPattern of a Locale.
  3274      * Cache to hold the NumberPattern of a Locale.
  3274      */
  3275      */
  3275     private static Hashtable cachedLocaleData = new Hashtable(3);
  3276     private static final ConcurrentMap<Locale, String> cachedLocaleData
       
  3277         = new ConcurrentHashMap<Locale, String>(3);
  3276 }
  3278 }