1 // DecimalFormatSymbols.java - Symbols used to format numbers.
3 /* Copyright (C) 1999 Red Hat, Inc.
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 import java.io.Serializable;
14 import java.util.Locale;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
19 * @author Tom Tromey <tromey@cygnus.com>
20 * @date February 24, 1999
22 /* Written using "Java Class Libraries", 2nd edition, plus online
23 * API docs for JDK 1.2 from http://www.javasoft.com.
24 * Status: Believed complete and correct to 1.2, except serialization.
27 public final class DecimalFormatSymbols implements Cloneable, Serializable
29 public Object clone ()
31 return new DecimalFormatSymbols (this);
34 private DecimalFormatSymbols (DecimalFormatSymbols orig)
36 this.currencySymbol = orig.currencySymbol;
37 this.decimalSeparator = orig.decimalSeparator;
38 this.digit = orig.digit;
39 this.exponential = orig.exponential;
40 this.groupingSeparator = orig.groupingSeparator;
41 this.infinity = orig.infinity;
42 this.intlCurrencySymbol = orig.intlCurrencySymbol;
43 this.minusSign = orig.minusSign;
45 this.patternSeparator = orig.patternSeparator;
46 this.percent = orig.percent;
47 this.perMill = orig.perMill;
48 this.zeroDigit = orig.zeroDigit;
51 public DecimalFormatSymbols ()
53 this (Locale.getDefault());
56 private final String safeGetString (ResourceBundle bundle,
57 String name, String def)
63 return bundle.getString(name);
65 catch (MissingResourceException x)
72 public final char safeGetChar (ResourceBundle bundle,
73 String name, char def)
80 r = bundle.getString(name);
82 catch (MissingResourceException x)
86 if (r == null || r.length() < 1)
91 public DecimalFormatSymbols (Locale loc)
96 res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc);
98 catch (MissingResourceException x)
102 currencySymbol = safeGetString (res, "currencySymbol", "$");
103 decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
104 digit = safeGetChar (res, "digit", '#');
105 exponential = safeGetChar (res, "exponential", 'E');
106 groupingSeparator = safeGetChar (res, "groupingSeparator", ',');
107 infinity = safeGetString (res, "infinity", "\u221e");
109 intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");
110 minusSign = safeGetChar (res, "minusSign", '-');
111 NaN = safeGetString (res, "NaN", "\ufffd");
112 patternSeparator = safeGetChar (res, "patternSeparator", ';');
113 percent = safeGetChar (res, "percent", '%');
114 perMill = safeGetChar (res, "perMill", '\u2030');
115 zeroDigit = safeGetChar (res, "zeroDigit", '0');
118 public boolean equals (Object obj)
120 if (! (obj instanceof DecimalFormatSymbols))
122 DecimalFormatSymbols dfs = (DecimalFormatSymbols) obj;
123 return (currencySymbol.equals(dfs.currencySymbol)
124 && decimalSeparator == dfs.decimalSeparator
125 && digit == dfs.digit
126 && exponential == dfs.exponential
127 && groupingSeparator == dfs.groupingSeparator
128 && infinity.equals(dfs.infinity)
129 && intlCurrencySymbol.equals(dfs.intlCurrencySymbol)
130 && minusSign == dfs.minusSign
131 && NaN.equals(dfs.NaN)
132 && patternSeparator == dfs.patternSeparator
133 && percent == dfs.percent
134 && perMill == dfs.perMill
135 && zeroDigit == dfs.zeroDigit);
138 public String getCurrencySymbol ()
140 return currencySymbol;
143 public char getDecimalSeparator ()
145 return decimalSeparator;
148 public char getDigit ()
153 // This is our own extension.
154 char getExponential ()
159 public char getGroupingSeparator ()
161 return groupingSeparator;
164 public String getInfinity ()
169 public String getInternationalCurrencySymbol ()
171 return intlCurrencySymbol;
174 public char getMinusSign ()
179 public String getNaN ()
184 public char getPatternSeparator ()
186 return patternSeparator;
189 public char getPercent ()
194 public char getPerMill ()
199 public char getZeroDigit ()
204 public int hashCode ()
206 // Compute based on zero digit, grouping separator, and decimal
207 // separator -- JCL book. This probably isn't a very good hash
209 return zeroDigit << 16 + groupingSeparator << 8 + decimalSeparator;
212 public void setCurrenySymbol (String currency)
214 currencySymbol = currency;
217 public void setDecimalSeparator (char decimalSep)
219 decimalSeparator = decimalSep;
222 public void setDigit (char digit)
227 // This is our own extension.
228 void setExponential (char exp)
233 public void setGroupingSeparator (char groupSep)
235 groupingSeparator = groupSep;
238 public void setInfinity (String infinity)
240 this.infinity = infinity;
243 public void setInternationalCurrencySymbol (String currency)
245 intlCurrencySymbol = currency;
248 public void setMinusSign (char minusSign)
250 this.minusSign = minusSign;
253 public void setNaN (String nan)
258 public void setPatternSeparator (char patternSep)
260 patternSeparator = patternSep;
263 public void setPercent (char percent)
265 this.percent = percent;
268 public void setPerMill (char perMill)
270 this.perMill = perMill;
273 public void setZeroDigit (char zeroDigit)
275 this.zeroDigit = zeroDigit;
278 // The names of the instance variables are fixed by the
279 // serialization spec.
280 private String currencySymbol;
281 private char decimalSeparator;
283 private char exponential;
284 private char groupingSeparator;
285 private String infinity;
286 private String intlCurrencySymbol;
287 private char minusSign;
289 private char patternSeparator;
290 private char percent;
291 private char perMill;
292 private char zeroDigit;