/[classpath]/classpath/java/text/DecimalFormatSymbols.java
ViewVC logotype

Diff of /classpath/java/text/DecimalFormatSymbols.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by mkoch, Fri Oct 22 17:15:57 2004 UTC revision 1.14 by gnu_andrew, Thu Dec 30 12:41:12 2004 UTC
# Line 48  import java.util.ResourceBundle; Line 48  import java.util.ResourceBundle;
48    
49  /**  /**
50   * This class is a container for the symbols used by   * This class is a container for the symbols used by
51   * <code>DecimalFormat</code> to format numbers and currency.  These are   * <code>DecimalFormat</code> to format numbers and currency
52     * for a particular locale.  These are
53   * normally handled automatically, but an application can override   * normally handled automatically, but an application can override
54   * values as desired using this class.   * values as desired using this class.
55   *   *
56   * @author Tom Tromey <tromey@cygnus.com>   * @author Tom Tromey (tromey@cygnus.com)
57   * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
58     * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
59   * @date February 24, 1999   * @date February 24, 1999
60     * @see java.text.DecimalFormat
61   */   */
62  /* Written using "Java Class Libraries", 2nd edition, plus online  /* Written using "Java Class Libraries", 2nd edition, plus online
63   * API docs for JDK 1.2 from http://www.javasoft.com.   * API docs for JDK 1.2 from http://www.javasoft.com.
# Line 83  public final class DecimalFormatSymbols Line 86  public final class DecimalFormatSymbols
86      this (Locale.getDefault());      this (Locale.getDefault());
87    }    }
88    
89      /**
90       * Retrieves a valid string, either using the supplied resource
91       * bundle or the default value.
92       *
93       * @param bundle the resource bundle to use to find the string.
94       * @param name key for the string in the resource bundle.
95       * @param def default value for the string.
96       */
97    private String safeGetString(ResourceBundle bundle,    private String safeGetString(ResourceBundle bundle,
98                                 String name, String def)                                 String name, String def)
99    {    {
# Line 123  public final class DecimalFormatSymbols Line 134  public final class DecimalFormatSymbols
134     * <code>DecimalFormatSymbols</code> for the specified locale.     * <code>DecimalFormatSymbols</code> for the specified locale.
135     *     *
136     * @param locale The local to load symbols for.     * @param locale The local to load symbols for.
137       * @throws NullPointerException if the locale is null.
138     */     */
139    public DecimalFormatSymbols (Locale loc)    public DecimalFormatSymbols (Locale loc)
140    {    {
# Line 136  public final class DecimalFormatSymbols Line 148  public final class DecimalFormatSymbols
148        {        {
149          res = null;          res = null;
150        }        }
151      currencySymbol = safeGetString (res, "currencySymbol", "$");      setCurrency(Currency.getInstance(loc));
152      decimalSeparator = safeGetChar (res, "decimalSeparator", '.');      decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
153      digit = safeGetChar (res, "digit", '#');      digit = safeGetChar (res, "digit", '#');
154      exponential = safeGetChar (res, "exponential", 'E');      exponential = safeGetChar (res, "exponential", 'E');
155      groupingSeparator = safeGetChar (res, "groupingSeparator", ',');      groupingSeparator = safeGetChar (res, "groupingSeparator", ',');
156      infinity = safeGetString (res, "infinity", "\u221e");      infinity = safeGetString (res, "infinity", "\u221e");
     // FIXME: default?  
     intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");  
157      try      try
158        {        {
159          monetarySeparator = safeGetChar (res, "monetarySeparator", '.');          monetarySeparator = safeGetChar (res, "monetarySeparator", '.');
# Line 205  public final class DecimalFormatSymbols Line 215  public final class DecimalFormatSymbols
215     */     */
216    public Currency getCurrency ()    public Currency getCurrency ()
217    {    {
218      return Currency.getInstance (currencySymbol);      return Currency.getInstance(currencySymbol);
219    }    }
220    
221    /**    /**
# Line 368  public final class DecimalFormatSymbols Line 378  public final class DecimalFormatSymbols
378    }    }
379    
380    /**    /**
381     * This method sets the currency to the specified value.     * This method sets the currency symbol and ISO 4217 currency
382       * code to the values obtained from the supplied currency.
383     *     *
384     * @param currency The new currency     * @param currency the currency from which to obtain the values.
385       * @throws NullPointerException if the currency is null.
386     */     */
387    public void setCurrency (Currency currency)    public void setCurrency (Currency currency)
388    {    {
389      setCurrencySymbol (currency.getSymbol());      intlCurrencySymbol = currency.getCurrencyCode();
390        currencySymbol = currency.getSymbol();
391    }    }
392    
393    /**    /**
# Line 435  public final class DecimalFormatSymbols Line 448  public final class DecimalFormatSymbols
448    }    }
449    
450    /**    /**
451     * This method sets the international currency symbols to the     * This method sets the international currency symbol to the
452     * specified value.     * specified value. The currency symbol is also modified if a
453     *     * valid symbol exists for the supplied currency in the locale
454     * @param intlCurrencySymbol The new international currency symbol.     * used by this instance.
455     */     *
456    public void setInternationalCurrencySymbol (String currency)     * @param currencyCode The new international currency symbol.
457    {     */
458      intlCurrencySymbol = currency;    public void setInternationalCurrencySymbol (String currencyCode)
459      {
460        Currency currency;
461    
462        intlCurrencySymbol = currencyCode;
463                    try
464                            {
465                                    currency = Currency.getInstance(currencyCode);
466                            }
467                    catch (IllegalArgumentException exception)
468                            {
469                                    currency = null;
470                            }
471        if (currency != null)
472          {
473            setCurrencySymbol(currency.getSymbol(locale));
474          }
475    }    }
476    
477    /**    /**

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26