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.FormatWraps a givenFormatand 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#formatresult of the empty value is the empty string, and the#parseresult 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
EmptyDateFormatorEmptyNumberFormatresp. Examples:new EmptyFormat(new WeightFormat());
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.FormatdelegateRefers to the wrapped Format that is used to forward#formatand#parseObject.private java.lang.ObjectemptyValueHolds 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 convertnullto 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 givenemptyValueto the empty string and vice versa.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringBufferformat(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)java.text.AttributedCharacterIteratorformatToCharacterIterator(java.lang.Object obj)java.lang.ObjectparseObject(java.lang.String source)java.lang.ObjectparseObject(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#formatand#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 convertnullto the empty string and vice versa.- Parameters:
delegate- the format that handles the standard cases- Throws:
java.lang.NullPointerException- ifdelegateisnull
-
EmptyFormat
public EmptyFormat(java.text.Format delegate, java.lang.Object emptyValue)Constructs an EmptyFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa.- Parameters:
delegate- the format that handles non-nullvaluesemptyValue- the representation of the empty string- Throws:
java.lang.NullPointerException- ifdelegateisnull
-
-
Method Detail
-
format
public java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)If
objis equal to the emptyValue,toAppendTois returned. Otherwise the format is forwarded to the delegate.- Specified by:
formatin classjava.text.Format
-
parseObject
public java.lang.Object parseObject(java.lang.String source) throws java.text.ParseExceptionIf
sourceis empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate.- Overrides:
parseObjectin classjava.text.Format- Throws:
java.text.ParseException
-
parseObject
public final java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)- Specified by:
parseObjectin classjava.text.Format
-
formatToCharacterIterator
public final java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
- Overrides:
formatToCharacterIteratorin classjava.text.Format
-
-