Package com.jgoodies.common.format
Class EmptyFormat
java.lang.Object
java.text.Format
com.jgoodies.common.format.EmptyFormat
- All Implemented Interfaces:
Serializable
,Cloneable
Wraps a given
Format
and adds behavior to convert to/from
the empty string. Therefore it holds an empty value
(often null
) 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 Format.
If you want to wrap a DateFormat or NumberFormat, you may use
EmptyDateFormat
or EmptyNumberFormat
resp.
Examples:
new EmptyFormat(new WeightFormat());
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEmptyFormat
(Format delegate) Constructs an EmptyFormat that wraps the given mandatory format to convertnull
to the empty string and vice versa.EmptyFormat
(Format delegate, Object emptyValue) Constructs an EmptyFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa. -
Method Summary
Modifier and TypeMethodDescriptionformat
(Object obj, StringBuffer toAppendTo, FieldPosition pos) parseObject
(String source) final Object
parseObject
(String source, ParsePosition pos)
-
Field Details
-
delegate
Refers to the wrapped Format that is used to forward#format
and#parseObject
. -
emptyValue
Holds the object that represents the empty value. The result of formatting this value is the empty string; the result of parsing an empty string is this object.
-
-
Constructor Details
-
EmptyFormat
Constructs an EmptyFormat 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
-
EmptyFormat
Constructs an EmptyFormat 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. -
parseObject
If
source
is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate.- Overrides:
parseObject
in classFormat
- Throws:
ParseException
-
parseObject
- Specified by:
parseObject
in classFormat
-
formatToCharacterIterator
- Overrides:
formatToCharacterIterator
in classFormat
-