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 delegate)
Constructs an EmptyFormat that wraps the given mandatory format
to convert
null to the empty string and vice versa. |
EmptyFormat(Format delegate,
Object emptyValue)
Constructs an EmptyFormat that wraps the given mandatory 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 delegate)
null
to the empty string and vice versa.delegate
- the format that handles the standard casesNullPointerException
- if delegate
is null
public EmptyFormat(Format delegate, Object emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty stringNullPointerException
- if delegate
is null
public 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 © 2014 JGoodies Software GmbH. All rights reserved.