com.jgoodies.common.format
public class EmptyFormat extends Format
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());
Format.Field
Constructor and Description |
---|
EmptyFormat(Format format)
Constructs an EmptyFormat that wraps the given format
to convert
null to the empty string and vice versa. |
EmptyFormat(Format format,
Object emptyValue)
Constructs an EmptyFormat that wraps the given format
to convert the given
emptyValue to the empty string
and vice versa. |
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos) |
AttributedCharacterIterator |
formatToCharacterIterator(Object obj) |
Object |
parseObject(String source) |
Object |
parseObject(String source,
ParsePosition pos) |
public EmptyFormat(Format format)
null
to the empty string and vice versa.format
- the format that handles the standard casespublic 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.
public Object parseObject(String source) throws ParseException
If source
is empty or whitespace, the emptyValue
is returned. Otherwise parsing is forwarded to the delegate.
parseObject
in class Format
ParseException
public final Object parseObject(String source, ParsePosition pos)
parseObject
in class Format
public final AttributedCharacterIterator formatToCharacterIterator(Object obj)
formatToCharacterIterator
in class Format
Copyright © 2009-2011 JGoodies Karsten Lentzsch. All Rights Reserved.