public final class EmptyNumberFormat extends NumberFormat
NumberFormat
and adds behavior to convert to/from
the empty string. Therefore it holds an empty value that is
mapped to/from the empty string. The #format
result
of the empty value is the empty string, and the #parse
result of the empty string is the empty value. In all other cases
the formatting and parsing is forwarded to the wrapped NumberFormat.Examples:
new EmptyNumberFormat(NumberFormat().getInstance()); new EmptyNumberFormat(NumberFormat().getIntegerInstance(), -1);
NumberFormat.Field
FRACTION_FIELD, INTEGER_FIELD
Constructor and Description |
---|
EmptyNumberFormat(NumberFormat delegate)
Constructs an EmptyNumberFormat that wraps the given mandatory format
to convert
null to the empty string and vice versa. |
EmptyNumberFormat(NumberFormat delegate,
int emptyValue)
Constructs an EmptyNumberFormat that wraps the given mandatory format
to convert the given
emptyValue to the empty string
and vice versa. |
EmptyNumberFormat(NumberFormat delegate,
Number emptyValue)
Constructs an EmptyNumberFormat that wraps the given mandatory format
to convert the given
emptyValue to the empty string
and vice versa. |
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(double number,
StringBuffer toAppendTo,
FieldPosition pos) |
StringBuffer |
format(long number,
StringBuffer toAppendTo,
FieldPosition pos) |
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
Number |
parse(String source) |
Number |
parse(String source,
ParsePosition pos) |
Object |
parseObject(String source) |
clone, equals, format, format, getAvailableLocales, getCurrency, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, getRoundingMode, hashCode, isGroupingUsed, isParseIntegerOnly, parseObject, setCurrency, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly, setRoundingMode
format, formatToCharacterIterator
public EmptyNumberFormat(NumberFormat delegate)
null
to the empty string and vice versa.delegate
- the format that handles the standard casesNullPointerException
- if delegate
is null
public EmptyNumberFormat(NumberFormat delegate, int emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty stringNullPointerException
- if delegate
is null
public EmptyNumberFormat(NumberFormat delegate, Number emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty stringNullPointerException
- if delegate
is null
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
If obj
is equal to the emptyValue,
toAppendTo
is returned. Otherwise the format
is forwarded to the delegate.
format
in class NumberFormat
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
format
in class NumberFormat
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
format
in class NumberFormat
public Object parseObject(String source) throws ParseException
If source
is empty or whitespace, the emptyValue
is returned. Otherwise parsing is forwarded to the delegate
- indirectly via parse(String, ParsePosition)
.
parseObject
in class Format
ParseException
public Number parse(String source) throws ParseException
If source
is empty or whitespace, the emptyValue
is returned. Otherwise parsing is forwarded to the delegate
- indirectly via parse(String, ParsePosition)
.
parse
in class NumberFormat
ParseException
public Number parse(String source, ParsePosition pos)
parse
in class NumberFormat
Copyright © 2014 JGoodies Software GmbH. All rights reserved.