Package com.jgoodies.common.format
Class EmptyNumberFormat
java.lang.Object
java.text.Format
java.text.NumberFormat
com.jgoodies.common.format.EmptyNumberFormat
- All Implemented Interfaces:
Serializable
,Cloneable
Wraps a given
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);
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.NumberFormat
NumberFormat.Field, NumberFormat.Style
-
Field Summary
FieldsFields inherited from class java.text.NumberFormat
FRACTION_FIELD, INTEGER_FIELD
-
Constructor Summary
ConstructorsConstructorDescriptionEmptyNumberFormat
(NumberFormat delegate) Constructs an EmptyNumberFormat that wraps the given mandatory format to convertnull
to the empty string and vice versa.EmptyNumberFormat
(NumberFormat delegate, int emptyValue) Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa.EmptyNumberFormat
(NumberFormat delegate, Number emptyValue) Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa. -
Method Summary
Modifier and TypeMethodDescriptionformat
(double number, StringBuffer toAppendTo, FieldPosition pos) format
(long number, StringBuffer toAppendTo, FieldPosition pos) format
(Object obj, StringBuffer toAppendTo, FieldPosition pos) parse
(String source, ParsePosition pos) parseObject
(String source) Methods inherited from class java.text.NumberFormat
clone, equals, format, format, getAvailableLocales, getCompactNumberInstance, getCompactNumberInstance, 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
Methods inherited from class java.text.Format
format, formatToCharacterIterator
-
Field Details
-
delegate
-
emptyValue
-
-
Constructor Details
-
EmptyNumberFormat
Constructs an EmptyNumberFormat that wraps the given mandatory format to convertnull
to the empty string and vice versa.- Parameters:
delegate
- the format that handles the standard cases- Throws:
NullPointerException
- ifdelegate
isnull
-
EmptyNumberFormat
Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa.- Parameters:
delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty string- Throws:
NullPointerException
- ifdelegate
isnull
-
EmptyNumberFormat
Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa.- Parameters:
delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty string- Throws:
NullPointerException
- ifdelegate
isnull
-
-
Method Details
-
format
If
obj
is equal to the emptyValue,toAppendTo
is returned. Otherwise the format is forwarded to the delegate.- Overrides:
format
in classNumberFormat
-
format
- Specified by:
format
in classNumberFormat
-
format
- Specified by:
format
in classNumberFormat
-
parseObject
If
source
is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly viaparse(String, ParsePosition)
.- Overrides:
parseObject
in classFormat
- Throws:
ParseException
-
parse
If
source
is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly viaparse(String, ParsePosition)
.- Overrides:
parse
in classNumberFormat
- Throws:
ParseException
-
parse
- Specified by:
parse
in classNumberFormat
-