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 convertnullto the empty string and vice versa.EmptyNumberFormat(NumberFormat delegate, int emptyValue) Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa.EmptyNumberFormat(NumberFormat delegate, Number emptyValue) Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValueto 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, setRoundingModeMethods 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 convertnullto the empty string and vice versa.- Parameters:
delegate- the format that handles the standard cases- Throws:
NullPointerException- ifdelegateisnull
-
EmptyNumberFormat
Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa.- Parameters:
delegate- the format that handles non-nullvaluesemptyValue- the representation of the empty string- Throws:
NullPointerException- ifdelegateisnull
-
EmptyNumberFormat
Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa.- Parameters:
delegate- the format that handles non-nullvaluesemptyValue- the representation of the empty string- Throws:
NullPointerException- ifdelegateisnull
-
-
Method Details
-
format
If
objis equal to the emptyValue,toAppendTois returned. Otherwise the format is forwarded to the delegate.- Overrides:
formatin classNumberFormat
-
format
- Specified by:
formatin classNumberFormat
-
format
- Specified by:
formatin classNumberFormat
-
parseObject
If
sourceis empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly viaparse(String, ParsePosition).- Overrides:
parseObjectin classFormat- Throws:
ParseException
-
parse
If
sourceis empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly viaparse(String, ParsePosition).- Overrides:
parsein classNumberFormat- Throws:
ParseException
-
parse
- Specified by:
parsein classNumberFormat
-