private void initNative(String pattern) { try { this.ndf = new NativeDecimalFormat(pattern, symbols); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException(pattern); } super.setMaximumFractionDigits(ndf.getMaximumFractionDigits()); super.setMaximumIntegerDigits(ndf.getMaximumIntegerDigits()); super.setMinimumFractionDigits(ndf.getMinimumFractionDigits()); super.setMinimumIntegerDigits(ndf.getMinimumIntegerDigits()); }
/** * Changes the pattern of this decimal format to the specified pattern which * uses localized pattern characters. * * @param pattern * the localized pattern. * @throws IllegalArgumentException * if the pattern cannot be parsed. */ public void applyLocalizedPattern(String pattern) { ndf.applyLocalizedPattern(pattern); }
public NativeDecimalFormat update(LocaleData localeData, String pattern) { if (decimalFormat == null) { currentPattern = pattern; currentLocaleData = localeData; decimalFormat = new NativeDecimalFormat(currentPattern, currentLocaleData); } if (!pattern.equals(currentPattern)) { decimalFormat.applyPattern(pattern); currentPattern = pattern; } if (localeData != currentLocaleData) { decimalFormat.setDecimalFormatSymbols(localeData); currentLocaleData = localeData; } return decimalFormat; } }
@Override public final StringBuffer format(Object number, StringBuffer buffer, FieldPosition position) { checkBufferAndFieldPosition(buffer, position); if (number instanceof BigInteger) { BigInteger bigInteger = (BigInteger) number; char[] chars = (bigInteger.bitLength() < 64) ? ndf.formatLong(bigInteger.longValue(), position) : ndf.formatBigInteger(bigInteger, position); buffer.append(chars); return buffer; } else if (number instanceof BigDecimal) { buffer.append(ndf.formatBigDecimal((BigDecimal) number, position)); return buffer; } return super.format(number, buffer, position); }
char[] chars; if (arg instanceof BigDecimal) { chars = nf.formatBigDecimal((BigDecimal) arg, null); } else { chars = nf.formatDouble(((Number) arg).doubleValue(), null);
/** * Changes the pattern of this decimal format to the specified pattern which * uses non-localized pattern characters. * * @param pattern * the non-localized pattern. * @throws IllegalArgumentException * if the pattern cannot be parsed. */ public void applyPattern(String pattern) { ndf.applyPattern(pattern); }
public synchronized void close() { if (address != 0) { close(address); address = 0; } }
private static void applyPattern(long addr, boolean localized, String pattern) { try { applyPatternImpl(addr, localized, pattern); } catch (NullPointerException npe) { throw npe; } catch (RuntimeException re) { throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern); } }
/** * Returns a new instance of {@code DecimalFormat} with the same pattern and * properties. */ @Override public Object clone() { DecimalFormat clone = (DecimalFormat) super.clone(); clone.ndf = (NativeDecimalFormat) ndf.clone(); clone.symbols = (DecimalFormatSymbols) symbols.clone(); return clone; }
@Override public Object clone() { try { NativeDecimalFormat clone = (NativeDecimalFormat) super.clone(); clone.address = cloneImpl(address); clone.lastPattern = lastPattern; clone.negPrefNull = negPrefNull; clone.negSuffNull = negSuffNull; clone.posPrefNull = posPrefNull; clone.posSuffNull = posSuffNull; return clone; } catch (CloneNotSupportedException unexpected) { throw new AssertionError(unexpected); } }
/** * Compares the specified object to this decimal format and indicates if * they are equal. In order to be equal, {@code object} must be an instance * of {@code DecimalFormat} with the same pattern and properties. * * @param object * the object to compare with this object. * @return {@code true} if the specified object is equal to this decimal * format; {@code false} otherwise. * @see #hashCode */ @Override public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof DecimalFormat)) { return false; } DecimalFormat other = (DecimalFormat) object; return (this.ndf == null ? other.ndf == null : this.ndf.equals(other.ndf)) && getDecimalFormatSymbols().equals(other.getDecimalFormatSymbols()); }
@Override public final StringBuffer format(Object number, StringBuffer buffer, FieldPosition position) { checkBufferAndFieldPosition(buffer, position); if (number instanceof BigInteger) { BigInteger bigInteger = (BigInteger) number; char[] chars = (bigInteger.bitLength() < 64) ? ndf.formatLong(bigInteger.longValue(), position) : ndf.formatBigInteger(bigInteger, position); buffer.append(chars); return buffer; } else if (number instanceof BigDecimal) { buffer.append(ndf.formatBigDecimal((BigDecimal) number, position)); return buffer; } return super.format(number, buffer, position); }
result.append(nf.formatBigDecimal((BigDecimal) arg, null)); } else { result.append(nf.formatDouble(((Number) arg).doubleValue(), null));
public void applyLocalizedPattern(String pattern) { applyPattern(this.address, true, pattern); lastPattern = null; }
@Override protected void finalize() throws Throwable { try { close(); } finally { super.finalize(); } }
private static void applyPattern(long addr, boolean localized, String pattern) { try { applyPatternImpl(addr, localized, pattern); } catch (NullPointerException npe) { throw npe; } catch (RuntimeException re) { throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern); } }
/** * Returns a new instance of {@code DecimalFormat} with the same pattern and * properties. */ @Override public Object clone() { DecimalFormat clone = (DecimalFormat) super.clone(); clone.ndf = (NativeDecimalFormat) ndf.clone(); clone.symbols = (DecimalFormatSymbols) symbols.clone(); return clone; }
@Override public Object clone() { try { NativeDecimalFormat clone = (NativeDecimalFormat) super.clone(); clone.address = cloneImpl(address); clone.lastPattern = lastPattern; clone.negPrefNull = negPrefNull; clone.negSuffNull = negSuffNull; clone.posPrefNull = posPrefNull; clone.posSuffNull = posSuffNull; return clone; } catch (CloneNotSupportedException unexpected) { throw new AssertionError(unexpected); } }
/** * Compares the specified object to this decimal format and indicates if * they are equal. In order to be equal, {@code object} must be an instance * of {@code DecimalFormat} with the same pattern and properties. * * @param object * the object to compare with this object. * @return {@code true} if the specified object is equal to this decimal * format; {@code false} otherwise. * @see #hashCode */ @Override public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof DecimalFormat)) { return false; } DecimalFormat other = (DecimalFormat) object; return (this.ndf == null ? other.ndf == null : this.ndf.equals(other.ndf)) && getDecimalFormatSymbols().equals(other.getDecimalFormatSymbols()); }
private void initNative(String pattern) { try { this.ndf = new NativeDecimalFormat(pattern, symbols); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException(pattern); } super.setMaximumFractionDigits(ndf.getMaximumFractionDigits()); super.setMaximumIntegerDigits(ndf.getMaximumIntegerDigits()); super.setMinimumFractionDigits(ndf.getMinimumFractionDigits()); super.setMinimumIntegerDigits(ndf.getMinimumIntegerDigits()); }