/** * Returns a copy of the decimal format symbols used by this format. * * @return desired DecimalFormatSymbols * @see DecimalFormatSymbols * @stable ICU 2.0 */ public DecimalFormatSymbols getDecimalFormatSymbols() { try { // don't allow multiple references return (DecimalFormatSymbols) symbols.clone(); } catch (Exception foo) { return null; // should never happen } }
@Override public Object clone() { DecimalFormatSymbolsICU other = (DecimalFormatSymbolsICU)super.clone(); other.fIcuDecfs = (DecimalFormatSymbols)fIcuDecfs.clone(); return other; }
/** * Sets the decimal format symbols used by this format. The format uses a copy of the * provided symbols. * * @param newSymbols desired DecimalFormatSymbols * @see DecimalFormatSymbols * @stable ICU 2.0 */ public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { symbols = (DecimalFormatSymbols) newSymbols.clone(); setCurrencyForSymbols(); expandAffixes(null); }
/** * Overrides clone. * @stable ICU 2.0 */ @Override public Object clone() { try { DecimalFormat other = (DecimalFormat) super.clone(); other.symbols = (DecimalFormatSymbols) symbols.clone(); other.digitList = new DigitList(); // fix for JB#5358 if (currencyPluralInfo != null) { other.currencyPluralInfo = (CurrencyPluralInfo) currencyPluralInfo.clone(); } other.attributes = new ArrayList<FieldPosition>(); // #9240 other.currencyUsage = currencyUsage; // TODO: We need to figure out whether we share a single copy of DigitList by // multiple cloned copies. format/subformat are designed to use a single // instance, but parse/subparse implementation is not. return other; } catch (Exception e) { throw new IllegalStateException(); } }
private void createFromPatternAndSymbols(String pattern, DecimalFormatSymbols inputSymbols) { // Always applyPattern after the symbols are set symbols = (DecimalFormatSymbols) inputSymbols.clone(); if (pattern.indexOf(CURRENCY_SIGN) >= 0) { // Only spend time with currency symbols when we're going to display it. // Also set some defaults before the apply pattern. setCurrencyForSymbols(); } applyPatternWithoutExpandAffix(pattern, false); if (currencySignCount == CURRENCY_SIGN_COUNT_IN_PLURAL_FORMAT) { currencyPluralInfo = new CurrencyPluralInfo(symbols.getULocale()); } else { expandAffixAdjustWidth(null); } }
private void create(String pattern, DecimalFormatSymbols inputSymbols, CurrencyPluralInfo info, int inputStyle) { if (inputStyle != NumberFormat.PLURALCURRENCYSTYLE) { createFromPatternAndSymbols(pattern, inputSymbols); } else { // Always applyPattern after the symbols are set symbols = (DecimalFormatSymbols) inputSymbols.clone(); currencyPluralInfo = info; // the pattern used in format is not fixed until formatting, in which, the // number is known and will be used to pick the right pattern based on plural // count. Here, set the pattern as the pattern of plural count == "other". // For most locale, the patterns are probably the same for all plural // count. If not, the right pattern need to be re-applied during format. String currencyPluralPatternForOther = currencyPluralInfo.getCurrencyPluralPattern("other"); applyPatternWithoutExpandAffix(currencyPluralPatternForOther, false); setCurrencyForSymbols(); } style = inputStyle; }
/** * Sets the decimal format symbols used by this formatter. The formatter uses a copy of the * provided symbols. * * @param newSymbols desired DecimalFormatSymbols * @see DecimalFormatSymbols * @stable ICU 49 */ public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { if (newSymbols != null) { decimalFormatSymbols = (DecimalFormatSymbols) newSymbols.clone(); if (decimalFormat != null) { decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols); } if (defaultInfinityRule != null) { defaultInfinityRule = null; getDefaultInfinityRule(); // Reset with the new DecimalFormatSymbols } if (defaultNaNRule != null) { defaultNaNRule = null; getDefaultNaNRule(); // Reset with the new DecimalFormatSymbols } // Apply the new decimalFormatSymbols by reparsing the rulesets for (NFRuleSet ruleSet : ruleSets) { ruleSet.setDecimalFormatSymbols(decimalFormatSymbols); } } }