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 delegate)
Constructs an EmptyFormat that wraps the given mandatory format
to convert
null to the empty string and vice versa. |
EmptyFormat(java.text.Format delegate,
java.lang.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 |
---|---|
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 delegate)
null
to the empty string and vice versa.delegate
- the format that handles the standard casesjava.lang.NullPointerException
- if delegate
is null
public EmptyFormat(java.text.Format delegate, java.lang.Object emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty stringjava.lang.NullPointerException
- if delegate
is null
public 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-2012 JGoodies Karsten Lentzsch. All Rights Reserved.