Package com.jgoodies.common.format
Class EmptyNumberFormat
- java.lang.Object
-
- java.text.Format
-
- java.text.NumberFormat
-
- com.jgoodies.common.format.EmptyNumberFormat
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public final class EmptyNumberFormat extends java.text.NumberFormatWraps a givenNumberFormatand adds behavior to convert to/from the empty string. Therefore it holds an empty value 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 NumberFormat.Examples:
new EmptyNumberFormat(NumberFormat().getInstance()); new EmptyNumberFormat(NumberFormat().getIntegerInstance(), -1);
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.NumberFormatdelegateprivate java.lang.NumberemptyValue
-
Constructor Summary
Constructors Constructor Description EmptyNumberFormat(java.text.NumberFormat delegate)Constructs an EmptyNumberFormat that wraps the given mandatory format to convertnullto the empty string and vice versa.EmptyNumberFormat(java.text.NumberFormat delegate, int emptyValue)Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the givenemptyValueto the empty string and vice versa.EmptyNumberFormat(java.text.NumberFormat delegate, java.lang.Number emptyValue)Constructs an EmptyNumberFormat 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(double number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)java.lang.StringBufferformat(long number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)java.lang.StringBufferformat(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)java.lang.Numberparse(java.lang.String source)java.lang.Numberparse(java.lang.String source, java.text.ParsePosition pos)java.lang.ObjectparseObject(java.lang.String source)-
Methods inherited from class java.text.NumberFormat
clone, equals, format, format, getAvailableLocales, getCurrency, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, getRoundingMode, hashCode, isGroupingUsed, isParseIntegerOnly, parseObject, setCurrency, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly, setRoundingMode
-
-
-
-
Constructor Detail
-
EmptyNumberFormat
public EmptyNumberFormat(java.text.NumberFormat delegate)
Constructs an EmptyNumberFormat 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
-
EmptyNumberFormat
public EmptyNumberFormat(java.text.NumberFormat delegate, int emptyValue)Constructs an EmptyNumberFormat 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
-
EmptyNumberFormat
public EmptyNumberFormat(java.text.NumberFormat delegate, java.lang.Number emptyValue)Constructs an EmptyNumberFormat 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.- Overrides:
formatin classjava.text.NumberFormat
-
format
public java.lang.StringBuffer format(double number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)- Specified by:
formatin classjava.text.NumberFormat
-
format
public java.lang.StringBuffer format(long number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)- Specified by:
formatin classjava.text.NumberFormat
-
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 - indirectly viaparse(String, ParsePosition).- Overrides:
parseObjectin classjava.text.Format- Throws:
java.text.ParseException
-
parse
public java.lang.Number parse(java.lang.String source) throws java.text.ParseExceptionIf
sourceis empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly viaparse(String, ParsePosition).- Overrides:
parsein classjava.text.NumberFormat- Throws:
java.text.ParseException
-
parse
public java.lang.Number parse(java.lang.String source, java.text.ParsePosition pos)- Specified by:
parsein classjava.text.NumberFormat
-
-