Package com.jgoodies.common.format
Class EmptyFormat
- java.lang.Object
-
- java.text.Format
-
- com.jgoodies.common.format.EmptyFormat
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class EmptyFormat extends java.text.Format
Wraps a givenFormat
and adds behavior to convert to/from the empty string. Therefore it holds an empty value (oftennull
) 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
orEmptyNumberFormat
resp. Examples:new EmptyFormat(new WeightFormat());
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.Format
delegate
Refers to the wrapped Format that is used to forward#format
and#parseObject
.private java.lang.Object
emptyValue
Holds the object that represents the empty value.
-
Constructor Summary
Constructors Constructor Description EmptyFormat(java.text.Format delegate)
Constructs an EmptyFormat that wraps the given mandatory format to convertnull
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 givenemptyValue
to the empty string and vice versa.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Field Detail
-
delegate
private final java.text.Format delegate
Refers to the wrapped Format that is used to forward#format
and#parseObject
.
-
emptyValue
private final java.lang.Object 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 Detail
-
EmptyFormat
public EmptyFormat(java.text.Format delegate)
Constructs an EmptyFormat that wraps the given mandatory format to convertnull
to the empty string and vice versa.- Parameters:
delegate
- the format that handles the standard cases- Throws:
java.lang.NullPointerException
- ifdelegate
isnull
-
EmptyFormat
public EmptyFormat(java.text.Format delegate, java.lang.Object emptyValue)
Constructs an EmptyFormat that wraps the given mandatory format to convert the givenemptyValue
to the empty string and vice versa.- Parameters:
delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty string- Throws:
java.lang.NullPointerException
- ifdelegate
isnull
-
-
Method Detail
-
format
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.- Specified by:
format
in classjava.text.Format
-
parseObject
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.- Overrides:
parseObject
in classjava.text.Format
- Throws:
java.text.ParseException
-
parseObject
public final java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
- Specified by:
parseObject
in classjava.text.Format
-
formatToCharacterIterator
public final java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
- Overrides:
formatToCharacterIterator
in classjava.text.Format
-
-