📄 decimalformatsymbols.java
字号:
{ return exponential; } /** * Sets the character used to separate the mantissa from the exponent. */ void setExponentialSymbol(char exp) { exponential = exp; } //------------------------------------------------------------ // END Package Private methods ... to be made public later //------------------------------------------------------------ /** * Standard override. */ public Object clone() { try { return (DecimalFormatSymbols)super.clone(); // other fields are bit-copied } catch (CloneNotSupportedException e) { throw new InternalError(); } } /** * Override equals. */ public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; DecimalFormatSymbols other = (DecimalFormatSymbols) obj; return (zeroDigit == other.zeroDigit && groupingSeparator == other.groupingSeparator && decimalSeparator == other.decimalSeparator && percent == other.percent && perMill == other.perMill && digit == other.digit && minusSign == other.minusSign && patternSeparator == other.patternSeparator && infinity.equals(other.infinity) && NaN.equals(other.NaN) && currencySymbol.equals(other.currencySymbol) && intlCurrencySymbol.equals(other.intlCurrencySymbol) && currency == other.currency && monetarySeparator == other.monetarySeparator && locale.equals(other.locale)); } /** * Override hashCode. */ public int hashCode() { int result = zeroDigit; result = result * 37 + groupingSeparator; result = result * 37 + decimalSeparator; return result; } /** * Initializes the symbols from the LocaleElements resource bundle. */ private void initialize( Locale locale ) { this.locale = locale; // get resource bundle data - try the cache first boolean needCacheUpdate = false; Object[] data = (Object[]) cachedLocaleData.get(locale); if (data == null) { /* cache miss */ data = new Object[3]; ResourceBundle rb = LocaleData.getLocaleElements(locale); data[0] = rb.getStringArray("NumberElements"); needCacheUpdate = true; } String[] numberElements = (String[]) data[0];; decimalSeparator = numberElements[0].charAt(0); groupingSeparator = numberElements[1].charAt(0); patternSeparator = numberElements[2].charAt(0); percent = numberElements[3].charAt(0); zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc. digit = numberElements[5].charAt(0); minusSign = numberElements[6].charAt(0); exponential = numberElements[7].charAt(0); perMill = numberElements[8].charAt(0); infinity = numberElements[9]; NaN = numberElements[10]; // Try to obtain the currency used in the locale's country. // Check for empty country string separately because it's a valid // country ID for Locale (and used for the C locale), but not a valid // ISO 3166 country code, and exceptions are expensive. if (!"".equals(locale.getCountry())) { try { currency = Currency.getInstance(locale); } catch (IllegalArgumentException e) { // use default values below for compatibility } } if (currency != null) { intlCurrencySymbol = currency.getCurrencyCode(); if (data[1] != null && data[1] == intlCurrencySymbol) { currencySymbol = (String) data[2]; } else { currencySymbol = currency.getSymbol(locale); data[1] = intlCurrencySymbol; data[2] = currencySymbol; needCacheUpdate = true; } } else { // default values intlCurrencySymbol = "XXX"; try { currency = Currency.getInstance(intlCurrencySymbol); } catch (IllegalArgumentException e) { } currencySymbol = "\u00A4"; } // Currently the monetary decimal separator is the same as the // standard decimal separator for all locales that we support. // If that changes, add a new entry to NumberElements. monetarySeparator = decimalSeparator; if (needCacheUpdate) { cachedLocaleData.put(locale, data); } } /** * Reads the default serializable fields, provides default values for objects * in older serial versions, and initializes non-serializable fields. * If <code>serialVersionOnStream</code> * is less than 1, initializes <code>monetarySeparator</code> to be * the same as <code>decimalSeparator</code> and <code>exponential</code> * to be 'E'. * If <code>serialVersionOnStream</code> is less then 2, * initializes <code>locale</code>to the root locale. * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that * default serialization will work properly if this object is streamed out again. * Initializes the currency from the intlCurrencySymbol field. * * @since JDK 1.1.6 */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); if (serialVersionOnStream < 1) { // Didn't have monetarySeparator or exponential field; // use defaults. monetarySeparator = decimalSeparator; exponential = 'E'; } if (serialVersionOnStream < 2) { // didn't have locale; use root locale locale = new Locale(""); } serialVersionOnStream = currentSerialVersion; if (intlCurrencySymbol != null) { try { currency = Currency.getInstance(intlCurrencySymbol); } catch (IllegalArgumentException e) { } } } /** * Character used for zero. * * @serial * @see #getZeroDigit */ private char zeroDigit; /** * Character used for thousands separator. * * @serial * @see #getGroupingSeparator */ private char groupingSeparator; /** * Character used for decimal sign. * * @serial * @see #getDecimalSeparator */ private char decimalSeparator; /** * Character used for mille percent sign. * * @serial * @see #getPerMill */ private char perMill; /** * Character used for percent sign. * @serial * @see #getPercent */ private char percent; /** * Character used for a digit in a pattern. * * @serial * @see #getDigit */ private char digit; /** * Character used to separate positive and negative subpatterns * in a pattern. * * @serial * @see #getPatternSeparator */ private char patternSeparator; /** * String used to represent infinity. * @serial * @see #getInfinity */ private String infinity; /** * String used to represent "not a number". * @serial * @see #getNaN */ private String NaN; /** * Character used to represent minus sign. * @serial * @see #getMinusSign */ private char minusSign; /** * String denoting the local currency, e.g. "$". * @serial * @see #getCurrencySymbol */ private String currencySymbol; /** * ISO 4217 currency code denoting the local currency, e.g. "USD". * @serial * @see #getInternationalCurrencySymbol */ private String intlCurrencySymbol; /** * The decimal separator used when formatting currency values. * @serial * @since JDK 1.1.6 * @see #getMonetaryDecimalSeparator */ private char monetarySeparator; // Field new in JDK 1.1.6 /** * The character used to distinguish the exponent in a number formatted * in exponential notation, e.g. 'E' for a number such as "1.23E45". * <p> * Note that the public API provides no way to set this field, * even though it is supported by the implementation and the stream format. * The intent is that this will be added to the API in the future. * * @serial * @since JDK 1.1.6 */ private char exponential; // Field new in JDK 1.1.6 /** * The locale of these currency format symbols. * * @serial * @since 1.4 */ private Locale locale; // currency; only the ISO code is serialized. private transient Currency currency; // Proclaim JDK 1.1 FCS compatibility static final long serialVersionUID = 5772796243397350300L; // The internal serial version which says which version was written // - 0 (default) for version up to JDK 1.1.5 // - 1 for version from JDK 1.1.6, which includes two new fields: // monetarySeparator and exponential. // - 2 for version from J2SE 1.4, which includes locale field. private static final int currentSerialVersion = 2; /** * Describes the version of <code>DecimalFormatSymbols</code> present on the stream. * Possible values are: * <ul> * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6. * * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include * two new fields: <code>monetarySeparator</code> and <code>exponential</code>. * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a * new <code>locale</code> field. * </ul> * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format * (corresponding to the highest allowable <code>serialVersionOnStream</code>) * is always written. * * @serial * @since JDK 1.1.6 */ private int serialVersionOnStream = currentSerialVersion; /** * cache to hold the NumberElements and the Currency * of a Locale. */ private static final Hashtable cachedLocaleData = new Hashtable(3);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -