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.FieldFRACTION_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)
If
obj is equal to the emptyValue,
toAppendTo is returned. |
Number |
parse(String source)
If
source is empty or whitespace, the emptyValue
is returned. |
Number |
parse(String source,
ParsePosition pos) |
Object |
parseObject(String source)
If
source is empty or whitespace, the emptyValue
is returned. |
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, setRoundingModeformat, formatToCharacterIteratorpublic EmptyNumberFormat(NumberFormat delegate)
null to the empty string and vice versa.delegate - the format that handles the standard casesNullPointerException - if delegate is nullpublic 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 nullpublic 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 nullpublic 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 NumberFormatpublic StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
format in class NumberFormatpublic StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
format in class NumberFormatpublic 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 FormatParseExceptionpublic 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 NumberFormatParseExceptionpublic Number parse(String source, ParsePosition pos)
parse in class NumberFormatCopyright © 2009-2014 JGoodies Software GmbH. All Rights Reserved.