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