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 convertnullto the empty string and vice versa.EmptyFormat(Format delegate, Object emptyValue) Constructs an EmptyFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa. -
Method Summary
Modifier and TypeMethodDescriptionformat(Object obj, StringBuffer toAppendTo, FieldPosition pos) parseObject(String source) final ObjectparseObject(String source, ParsePosition pos)
-
Field Details
-
delegate
Refers to the wrapped Format that is used to forward#formatand#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 convertnullto the empty string and vice versa.- Parameters:
delegate- the format that handles the standard cases- Throws:
NullPointerException- ifdelegateisnull
-
EmptyFormat
Constructs an EmptyFormat 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. -
parseObject
If
sourceis empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate.- Overrides:
parseObjectin classFormat- Throws:
ParseException
-
parseObject
- Specified by:
parseObjectin classFormat
-
formatToCharacterIterator
- Overrides:
formatToCharacterIteratorin classFormat
-