Reset version to prerelease
[official-gcc.git] / libjava / java / text / DecimalFormatSymbols.java
blob0f404a57235dd7e23a4b561ea6d44cbf6cbf89d5
1 // DecimalFormatSymbols.java - Symbols used to format numbers.
3 /* Copyright (C) 1999, 2000 Free Software Foundation
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
9 details. */
11 package java.text;
13 import java.io.Serializable;
14 import java.util.Locale;
15 import java.util.MissingResourceException;
16 import java.util.ResourceBundle;
17 import java.io.ObjectInputStream;
18 import java.io.IOException;
20 /**
21 * @author Tom Tromey <tromey@cygnus.com>
22 * @date February 24, 1999
24 /* Written using "Java Class Libraries", 2nd edition, plus online
25 * API docs for JDK 1.2 from http://www.javasoft.com.
26 * Status: Believed complete and correct to 1.2.
29 public final class DecimalFormatSymbols implements Cloneable, Serializable
31 public Object clone ()
33 return new DecimalFormatSymbols (this);
36 private DecimalFormatSymbols (DecimalFormatSymbols orig)
38 this.currencySymbol = orig.currencySymbol;
39 this.decimalSeparator = orig.decimalSeparator;
40 this.digit = orig.digit;
41 this.exponential = orig.exponential;
42 this.groupingSeparator = orig.groupingSeparator;
43 this.infinity = orig.infinity;
44 this.intlCurrencySymbol = orig.intlCurrencySymbol;
45 this.monetarySeparator = orig.monetarySeparator;
46 this.minusSign = orig.minusSign;
47 this.NaN = orig.NaN;
48 this.patternSeparator = orig.patternSeparator;
49 this.percent = orig.percent;
50 this.perMill = orig.perMill;
51 this.zeroDigit = orig.zeroDigit;
54 public DecimalFormatSymbols ()
56 this (Locale.getDefault());
59 private final String safeGetString (ResourceBundle bundle,
60 String name, String def)
62 if (bundle != null)
64 try
66 return bundle.getString(name);
68 catch (MissingResourceException x)
72 return def;
75 private final char safeGetChar (ResourceBundle bundle,
76 String name, char def)
78 String r = null;
79 if (bundle != null)
81 try
83 r = bundle.getString(name);
85 catch (MissingResourceException x)
89 if (r == null || r.length() < 1)
90 return def;
91 return r.charAt(0);
94 public DecimalFormatSymbols (Locale loc)
96 ResourceBundle res;
97 try
99 res = ResourceBundle.getBundle("gnu.gcj.text.LocaleData", loc);
101 catch (MissingResourceException x)
103 res = null;
105 currencySymbol = safeGetString (res, "currencySymbol", "$");
106 decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
107 digit = safeGetChar (res, "digit", '#');
108 exponential = safeGetChar (res, "exponential", 'E');
109 groupingSeparator = safeGetChar (res, "groupingSeparator", ',');
110 infinity = safeGetString (res, "infinity", "\u221e");
111 // FIXME: default?
112 intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");
115 monetarySeparator = safeGetChar (res, "monetarySeparator", '.');
117 catch (MissingResourceException x)
119 monetarySeparator = decimalSeparator;
121 minusSign = safeGetChar (res, "minusSign", '-');
122 NaN = safeGetString (res, "NaN", "\ufffd");
123 patternSeparator = safeGetChar (res, "patternSeparator", ';');
124 percent = safeGetChar (res, "percent", '%');
125 perMill = safeGetChar (res, "perMill", '\u2030');
126 zeroDigit = safeGetChar (res, "zeroDigit", '0');
129 public boolean equals (Object obj)
131 if (! (obj instanceof DecimalFormatSymbols))
132 return false;
133 DecimalFormatSymbols dfs = (DecimalFormatSymbols) obj;
134 return (currencySymbol.equals(dfs.currencySymbol)
135 && decimalSeparator == dfs.decimalSeparator
136 && digit == dfs.digit
137 && exponential == dfs.exponential
138 && groupingSeparator == dfs.groupingSeparator
139 && infinity.equals(dfs.infinity)
140 && intlCurrencySymbol.equals(dfs.intlCurrencySymbol)
141 && minusSign == dfs.minusSign
142 && monetarySeparator == dfs.monetarySeparator
143 && NaN.equals(dfs.NaN)
144 && patternSeparator == dfs.patternSeparator
145 && percent == dfs.percent
146 && perMill == dfs.perMill
147 && zeroDigit == dfs.zeroDigit);
150 public String getCurrencySymbol ()
152 return currencySymbol;
155 public char getDecimalSeparator ()
157 return decimalSeparator;
160 public char getDigit ()
162 return digit;
165 // This is our own extension.
166 char getExponential ()
168 return exponential;
171 public char getGroupingSeparator ()
173 return groupingSeparator;
176 public String getInfinity ()
178 return infinity;
181 public String getInternationalCurrencySymbol ()
183 return intlCurrencySymbol;
186 public char getMinusSign ()
188 return minusSign;
191 public char getMonetaryDecimalSeparator ()
193 return monetarySeparator;
196 public String getNaN ()
198 return NaN;
201 public char getPatternSeparator ()
203 return patternSeparator;
206 public char getPercent ()
208 return percent;
211 public char getPerMill ()
213 return perMill;
216 public char getZeroDigit ()
218 return zeroDigit;
221 public int hashCode ()
223 // Compute based on zero digit, grouping separator, and decimal
224 // separator -- JCL book. This probably isn't a very good hash
225 // code.
226 return zeroDigit << 16 + groupingSeparator << 8 + decimalSeparator;
229 public void setCurrencySymbol (String currency)
231 currencySymbol = currency;
234 public void setDecimalSeparator (char decimalSep)
236 decimalSeparator = decimalSep;
239 public void setDigit (char digit)
241 this.digit = digit;
244 // This is our own extension.
245 void setExponential (char exp)
247 exponential = exp;
250 public void setGroupingSeparator (char groupSep)
252 groupingSeparator = groupSep;
255 public void setInfinity (String infinity)
257 this.infinity = infinity;
260 public void setInternationalCurrencySymbol (String currency)
262 intlCurrencySymbol = currency;
265 public void setMinusSign (char minusSign)
267 this.minusSign = minusSign;
270 public void setMonetaryDecimalSeparator (char decimalSep)
272 monetarySeparator = decimalSep;
275 public void setNaN (String nan)
277 NaN = nan;
280 public void setPatternSeparator (char patternSep)
282 patternSeparator = patternSep;
285 public void setPercent (char percent)
287 this.percent = percent;
290 public void setPerMill (char perMill)
292 this.perMill = perMill;
295 public void setZeroDigit (char zeroDigit)
297 this.zeroDigit = zeroDigit;
300 // The names of the instance variables are fixed by the
301 // serialization spec.
302 private String currencySymbol;
303 private char decimalSeparator;
304 private char digit;
305 private char exponential;
306 private char groupingSeparator;
307 private String infinity;
308 private String intlCurrencySymbol;
309 private char minusSign;
310 private char monetarySeparator;
311 private String NaN;
312 private char patternSeparator;
313 private char percent;
314 private char perMill;
315 private int serialVersionOnStream = 1;
316 private char zeroDigit;
317 private static final long serialVersionUID = 5772796243397350300L;
319 private void readObject(ObjectInputStream stream)
320 throws IOException, ClassNotFoundException
322 stream.defaultReadObject();
323 if (serialVersionOnStream < 1)
325 monetarySeparator = decimalSeparator;
326 exponential = 'E';
327 serialVersionOnStream = 1;