Methods Summary |
---|
public java.lang.Object | clone()Returns a new {@code NumberFormat} with the same properties as this
{@code NumberFormat}.
return super.clone();
|
public boolean | equals(java.lang.Object object)Compares the specified object to this number format and indicates if
they are equal. In order to be equal, {@code object} must be an instance
of {@code NumberFormat} with the same pattern and properties.
if (object == this) {
return true;
}
if (!(object instanceof NumberFormat)) {
return false;
}
NumberFormat obj = (NumberFormat) object;
return groupingUsed == obj.groupingUsed
&& parseIntegerOnly == obj.parseIntegerOnly
&& maximumFractionDigits == obj.maximumFractionDigits
&& maximumIntegerDigits == obj.maximumIntegerDigits
&& minimumFractionDigits == obj.minimumFractionDigits
&& minimumIntegerDigits == obj.minimumIntegerDigits;
|
public final java.lang.String | format(double value)Formats the specified double using the rules of this number format.
return format(value, new StringBuffer(), new FieldPosition(0))
.toString();
|
public abstract java.lang.StringBuffer | format(double value, java.lang.StringBuffer buffer, java.text.FieldPosition field)Formats the specified double value as a string using the pattern of this
number format and appends the string to the specified string buffer.
If the {@code field} member of {@code position} contains a value
specifying a format field, then its {@code beginIndex} and
{@code endIndex} members will be updated with the position of the first
occurrence of this field in the formatted text.
|
public final java.lang.String | format(long value)Formats the specified long using the rules of this number format.
return format(value, new StringBuffer(), new FieldPosition(0))
.toString();
|
public abstract java.lang.StringBuffer | format(long value, java.lang.StringBuffer buffer, java.text.FieldPosition field)Formats the specified long value as a string using the pattern of this
number format and appends the string to the specified string buffer.
If the {@code field} member of {@code position} contains a value
specifying a format field, then its {@code beginIndex} and
{@code endIndex} members will be updated with the position of the first
occurrence of this field in the formatted text.
|
public java.lang.StringBuffer | format(java.lang.Object object, java.lang.StringBuffer buffer, java.text.FieldPosition field)Formats the specified object as a string using the pattern of this number
format and appends the string to the specified string buffer.
If the {@code field} member of {@code field} contains a value specifying
a format field, then its {@code beginIndex} and {@code endIndex} members
will be updated with the position of the first occurrence of this field
in the formatted text.
if (object instanceof Number) {
double dv = ((Number) object).doubleValue();
long lv = ((Number) object).longValue();
if (dv == lv) {
return format(lv, buffer, field);
}
return format(dv, buffer, field);
}
throw new IllegalArgumentException();
|
public static java.util.Locale[] | getAvailableLocales()Gets the list of installed locales which support {@code NumberFormat}.
return Locale.getAvailableLocales();
|
public java.util.Currency | getCurrency()Returns the currency used by this number format.
This implementation throws {@code UnsupportedOperationException},
concrete subclasses should override this method if they support currency
formatting.
throw new UnsupportedOperationException();
|
public static final java.text.NumberFormat | getCurrencyInstance()Returns a {@code NumberFormat} for formatting and parsing currency values
for the default locale.
return getCurrencyInstance(Locale.getDefault());
|
public static java.text.NumberFormat | getCurrencyInstance(java.util.Locale locale)Returns a {@code NumberFormat} for formatting and parsing currency values
for the specified locale.
return getInstance(locale, "Currency"); //$NON-NLS-1$
|
public static final java.text.NumberFormat | getInstance()Returns a {@code NumberFormat} for formatting and parsing numbers for the
default locale.
return getNumberInstance();
|
public static java.text.NumberFormat | getInstance(java.util.Locale locale)Returns a {@code NumberFormat} for formatting and parsing numbers for the
specified locale.
return getNumberInstance(locale);
|
static java.text.NumberFormat | getInstance(java.util.Locale locale, java.lang.String type)
return new DecimalFormat(getPattern(locale, type),
new DecimalFormatSymbols(locale));
|
public static final java.text.NumberFormat | getIntegerInstance()Returns a {@code NumberFormat} for formatting and parsing integers for the
default locale.
return getIntegerInstance(Locale.getDefault());
|
public static java.text.NumberFormat | getIntegerInstance(java.util.Locale locale)Returns a {@code NumberFormat} for formatting and parsing integers for
the specified locale.
NumberFormat format = getInstance(locale, "Integer"); //$NON-NLS-1$
format.setParseIntegerOnly(true);
return format;
|
public int | getMaximumFractionDigits()Returns the maximum number of fraction digits that are printed when
formatting. If the maximum is less than the number of fraction digits,
the least significant digits are truncated.
return maximumFractionDigits;
|
public int | getMaximumIntegerDigits()Returns the maximum number of integer digits that are printed when
formatting. If the maximum is less than the number of integer digits, the
most significant digits are truncated.
return maximumIntegerDigits;
|
public int | getMinimumFractionDigits()Returns the minimum number of fraction digits that are printed when
formatting.
return minimumFractionDigits;
|
public int | getMinimumIntegerDigits()Returns the minimum number of integer digits that are printed when
formatting.
return minimumIntegerDigits;
|
public static final java.text.NumberFormat | getNumberInstance()Returns a {@code NumberFormat} for formatting and parsing numbers for the
default locale.
return getNumberInstance(Locale.getDefault());
|
public static java.text.NumberFormat | getNumberInstance(java.util.Locale locale)Returns a {@code NumberFormat} for formatting and parsing numbers for the
specified locale.
return getInstance(locale, "Number"); //$NON-NLS-1$
|
static java.lang.String | getPattern(java.util.Locale locale, java.lang.String type)
ResourceBundle bundle = getBundle(locale);
return bundle.getString(type);
|
public static final java.text.NumberFormat | getPercentInstance()Returns a {@code NumberFormat} for formatting and parsing percentage
values for the default locale.
return getPercentInstance(Locale.getDefault());
|
public static java.text.NumberFormat | getPercentInstance(java.util.Locale locale)Returns a {@code NumberFormat} for formatting and parsing percentage
values for the specified locale.
return getInstance(locale, "Percent"); //$NON-NLS-1$
|
public int | hashCode()
return (groupingUsed ? 1231 : 1237) + (parseIntegerOnly ? 1231 : 1237)
+ maximumFractionDigits + maximumIntegerDigits
+ minimumFractionDigits + minimumIntegerDigits;
|
public boolean | isGroupingUsed()Indicates whether this number format formats and parses numbers using a
grouping separator.
return groupingUsed;
|
public boolean | isParseIntegerOnly()Indicates whether this number format only parses integer numbers. Parsing
stops if a decimal separator is encountered.
return parseIntegerOnly;
|
public java.lang.Number | parse(java.lang.String string)Parses a {@code Number} from the specified string using the rules of this
number format.
ParsePosition pos = new ParsePosition(0);
Number number = parse(string, pos);
if (pos.getErrorIndex() != -1 || pos.getIndex() == 0) {
throw new ParseException(null, pos.getErrorIndex());
}
return number;
|
public abstract java.lang.Number | parse(java.lang.String string, java.text.ParsePosition position)Parses a {@code Number} from the specified string starting at the index
specified by {@code position}. If the string is successfully parsed then
the index of the {@code ParsePosition} is updated to the index following
the parsed text. On error, the index is unchanged and the error index of
{@code ParsePosition} is set to the index where the error occurred.
|
public final java.lang.Object | parseObject(java.lang.String string, java.text.ParsePosition position)
if (position == null) {
// text.1A=position is null
throw new NullPointerException(Messages.getString("text.1A")); //$NON-NLS-1$
}
try {
return parse(string, position);
} catch (Exception e) {
return null;
}
|
private void | readObject(java.io.ObjectInputStream stream)
ObjectInputStream.GetField fields = stream.readFields();
groupingUsed = fields.get("groupingUsed", true); //$NON-NLS-1$
parseIntegerOnly = fields.get("parseIntegerOnly", false); //$NON-NLS-1$
if (fields.get("serialVersionOnStream", 0) == 0) { //$NON-NLS-1$
maximumFractionDigits = fields.get("maxFractionDigits", (byte) 3); //$NON-NLS-1$
maximumIntegerDigits = fields.get("maxIntegerDigits", (byte) 40); //$NON-NLS-1$
minimumFractionDigits = fields.get("minFractionDigits", (byte) 0); //$NON-NLS-1$
minimumIntegerDigits = fields.get("minIntegerDigits", (byte) 1); //$NON-NLS-1$
} else {
maximumFractionDigits = fields.get("maximumFractionDigits", 3); //$NON-NLS-1$
maximumIntegerDigits = fields.get("maximumIntegerDigits", 40); //$NON-NLS-1$
minimumFractionDigits = fields.get("minimumFractionDigits", 0); //$NON-NLS-1$
minimumIntegerDigits = fields.get("minimumIntegerDigits", 1); //$NON-NLS-1$
}
if (minimumIntegerDigits > maximumIntegerDigits
|| minimumFractionDigits > maximumFractionDigits) {
// text.00=min digits greater than max digits
throw new InvalidObjectException(Messages.getString("text.00")); //$NON-NLS-1$
}
if (minimumIntegerDigits < 0 || maximumIntegerDigits < 0
|| minimumFractionDigits < 0 || maximumFractionDigits < 0) {
// text.01=min or max digits negative
throw new InvalidObjectException(Messages.getString("text.01")); //$NON-NLS-1$
}
|
public void | setCurrency(java.util.Currency currency)Sets the currency used by this number format when formatting currency
values. The min and max fraction digits remain the same.
This implementation throws {@code UnsupportedOperationException},
concrete subclasses should override this method if they support currency
formatting.
throw new UnsupportedOperationException();
|
public void | setGroupingUsed(boolean value)Sets whether this number format formats and parses numbers using a
grouping separator.
groupingUsed = value;
|
public void | setMaximumFractionDigits(int value)Sets the maximum number of fraction digits that are printed when
formatting. If the maximum is less than the number of fraction digits,
the least significant digits are truncated.
maximumFractionDigits = value < 0 ? 0 : value;
if (maximumFractionDigits < minimumFractionDigits) {
minimumFractionDigits = maximumFractionDigits;
}
|
public void | setMaximumIntegerDigits(int value)Sets the new maximum count of integer digits that are printed when
formatting. If the maximum is less than the number of integer digits, the
most significant digits are truncated.
maximumIntegerDigits = value < 0 ? 0 : value;
if (maximumIntegerDigits < minimumIntegerDigits) {
minimumIntegerDigits = maximumIntegerDigits;
}
|
public void | setMinimumFractionDigits(int value)Sets the minimum number of fraction digits that are printed when
formatting.
minimumFractionDigits = value < 0 ? 0 : value;
if (maximumFractionDigits < minimumFractionDigits) {
maximumFractionDigits = minimumFractionDigits;
}
|
public void | setMinimumIntegerDigits(int value)Sets the minimum number of integer digits that are printed when
formatting.
minimumIntegerDigits = value < 0 ? 0 : value;
if (maximumIntegerDigits < minimumIntegerDigits) {
maximumIntegerDigits = minimumIntegerDigits;
}
|
public void | setParseIntegerOnly(boolean value)Specifies if this number format should parse numbers only as integers or
else as any kind of number. If this method is called with a {@code true}
value then subsequent parsing attempts will stop if a decimal separator
is encountered.
parseIntegerOnly = value;
|
private void | writeObject(java.io.ObjectOutputStream stream) //$NON-NLS-1$
ObjectOutputStream.PutField fields = stream.putFields();
fields.put("groupingUsed", groupingUsed); //$NON-NLS-1$
fields
.put(
"maxFractionDigits", //$NON-NLS-1$
maximumFractionDigits < Byte.MAX_VALUE ? (byte) maximumFractionDigits
: Byte.MAX_VALUE);
fields.put("maximumFractionDigits", maximumFractionDigits); //$NON-NLS-1$
fields.put("maximumIntegerDigits", maximumIntegerDigits); //$NON-NLS-1$
fields
.put(
"maxIntegerDigits", //$NON-NLS-1$
maximumIntegerDigits < Byte.MAX_VALUE ? (byte) maximumIntegerDigits
: Byte.MAX_VALUE);
fields
.put(
"minFractionDigits", //$NON-NLS-1$
minimumFractionDigits < Byte.MAX_VALUE ? (byte) minimumFractionDigits
: Byte.MAX_VALUE);
fields.put("minimumFractionDigits", minimumFractionDigits); //$NON-NLS-1$
fields.put("minimumIntegerDigits", minimumIntegerDigits); //$NON-NLS-1$
fields
.put(
"minIntegerDigits", //$NON-NLS-1$
minimumIntegerDigits < Byte.MAX_VALUE ? (byte) minimumIntegerDigits
: Byte.MAX_VALUE);
fields.put("parseIntegerOnly", parseIntegerOnly); //$NON-NLS-1$
fields.put("serialVersionOnStream", 1); //$NON-NLS-1$
stream.writeFields();
|