OSDN Git Service

* All files: Updated copyright to reflect Cygnus purchase.
[pf3gnuchains/gcc-fork.git] / libjava / java / text / DecimalFormatSymbols.java
1 // DecimalFormatSymbols.java - Symbols used to format numbers.
2
3 /* Copyright (C) 1999  Red Hat, Inc.
4
5    This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10
11 package java.text;
12
13 import java.io.Serializable;
14 import java.util.Locale;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
17
18 /**
19  * @author Tom Tromey <tromey@cygnus.com>
20  * @date February 24, 1999
21  */
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.
25  */
26
27 public final class DecimalFormatSymbols implements Cloneable, Serializable
28 {
29   public Object clone ()
30     {
31       return new DecimalFormatSymbols (this);
32     }
33
34   private DecimalFormatSymbols (DecimalFormatSymbols orig)
35     {
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;
44       this.NaN = orig.NaN;
45       this.patternSeparator = orig.patternSeparator;
46       this.percent = orig.percent;
47       this.perMill = orig.perMill;
48       this.zeroDigit = orig.zeroDigit;
49     }
50
51   public DecimalFormatSymbols ()
52     {
53       this (Locale.getDefault());
54     }
55
56   private final String safeGetString (ResourceBundle bundle,
57                                       String name, String def)
58     {
59       if (bundle != null)
60         {
61           try
62             {
63               return bundle.getString(name);
64             }
65           catch (MissingResourceException x)
66             {
67             }
68         }
69       return def;
70     }
71
72   public final char safeGetChar (ResourceBundle bundle,
73                                  String name, char def)
74     {
75       String r = null;
76       if (bundle != null)
77         {
78           try
79             {
80               r = bundle.getString(name);
81             }
82           catch (MissingResourceException x)
83             {
84             }
85         }
86       if (r == null || r.length() < 1)
87         return def;
88       return r.charAt(0);
89     }
90
91   public DecimalFormatSymbols (Locale loc)
92     {
93       ResourceBundle res;
94       try
95         {
96           res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc);
97         }
98       catch (MissingResourceException x)
99         {
100           res = null;
101         }
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");
108       // FIXME: default?
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');
116     }
117
118   public boolean equals (Object obj)
119     {
120       if (! (obj instanceof DecimalFormatSymbols))
121         return false;
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);
136     }
137
138   public String getCurrencySymbol ()
139     {
140       return currencySymbol;
141     }
142
143   public char getDecimalSeparator ()
144     {
145       return decimalSeparator;
146     }
147
148   public char getDigit ()
149     {
150       return digit;
151     }
152
153   // This is our own extension.
154   char getExponential ()
155     {
156       return exponential;
157     }
158
159   public char getGroupingSeparator ()
160     {
161       return groupingSeparator;
162     }
163
164   public String getInfinity ()
165     {
166       return infinity;
167     }
168
169   public String getInternationalCurrencySymbol ()
170     {
171       return intlCurrencySymbol;
172     }
173
174   public char getMinusSign ()
175     {
176       return minusSign;
177     }
178
179   public String getNaN ()
180     {
181       return NaN;
182     }
183
184   public char getPatternSeparator ()
185     {
186       return patternSeparator;
187     }
188
189   public char getPercent ()
190     {
191       return percent;
192     }
193
194   public char getPerMill ()
195     {
196       return perMill;
197     }
198
199   public char getZeroDigit ()
200     {
201       return zeroDigit;
202     }
203
204   public int hashCode ()
205     {
206       // Compute based on zero digit, grouping separator, and decimal
207       // separator -- JCL book.  This probably isn't a very good hash
208       // code.
209       return zeroDigit << 16 + groupingSeparator << 8 + decimalSeparator;
210     }
211
212   public void setCurrenySymbol (String currency)
213     {
214       currencySymbol = currency;
215     }
216
217   public void setDecimalSeparator (char decimalSep)
218     {
219       decimalSeparator = decimalSep;
220     }
221
222   public void setDigit (char digit)
223     {
224       this.digit = digit;
225     }
226
227   // This is our own extension.
228   void setExponential (char exp)
229     {
230       exponential = exp;
231     }
232
233   public void setGroupingSeparator (char groupSep)
234     {
235       groupingSeparator = groupSep;
236     }
237
238   public void setInfinity (String infinity)
239     {
240       this.infinity = infinity;
241     }
242
243   public void setInternationalCurrencySymbol (String currency)
244     {
245       intlCurrencySymbol = currency;
246     }
247
248   public void setMinusSign (char minusSign)
249     {
250       this.minusSign = minusSign;
251     }
252
253   public void setNaN (String nan)
254     {
255       NaN = nan;
256     }
257
258   public void setPatternSeparator (char patternSep)
259     {
260       patternSeparator = patternSep;
261     }
262
263   public void setPercent (char percent)
264     {
265       this.percent = percent;
266     }
267
268   public void setPerMill (char perMill)
269     {
270       this.perMill = perMill;
271     }
272
273   public void setZeroDigit (char zeroDigit)
274     {
275       this.zeroDigit = zeroDigit;
276     }
277
278   // The names of the instance variables are fixed by the
279   // serialization spec.
280   private String currencySymbol;
281   private char decimalSeparator;
282   private char digit;
283   private char exponential;
284   private char groupingSeparator;
285   private String infinity;
286   private String intlCurrencySymbol;
287   private char minusSign;
288   private String NaN;
289   private char patternSeparator;
290   private char percent;
291   private char perMill;
292   private char zeroDigit;
293 }