com.jgoodies.common.format
public final class EmptyNumberFormat extends java.text.NumberFormat
NumberFormat
and adds behavior to convert to/from
the empty string. Therefore it holds an empty value 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 NumberFormat.Examples:
new EmptyNumberFormat(NumberFormat().getInstance()); new EmptyNumberFormat(NumberFormat().getIntegerInstance(), -1);
Constructor and Description |
---|
EmptyNumberFormat(java.text.NumberFormat delegate)
Constructs an EmptyNumberFormat that wraps the given format
to convert
null to the empty string and vice versa. |
EmptyNumberFormat(java.text.NumberFormat delegate,
int emptyValue)
Constructs an EmptyNumberFormat that wraps the given format
to convert the given
emptyValue to the empty string
and vice versa. |
EmptyNumberFormat(java.text.NumberFormat delegate,
java.lang.Number emptyValue)
Constructs an EmptyNumberFormat 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(double number,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos) |
java.lang.StringBuffer |
format(long number,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos) |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos) |
java.lang.Number |
parse(java.lang.String source) |
java.lang.Number |
parse(java.lang.String source,
java.text.ParsePosition pos) |
java.lang.Object |
parseObject(java.lang.String source) |
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
public EmptyNumberFormat(java.text.NumberFormat delegate)
null
to the empty string and vice versa.delegate
- the format that handles the standard casespublic EmptyNumberFormat(java.text.NumberFormat delegate, int emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- the format that handles non-null
valuesemptyValue
- the representation of the empty stringpublic EmptyNumberFormat(java.text.NumberFormat delegate, java.lang.Number emptyValue)
emptyValue
to the empty string
and vice versa.delegate
- 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.NumberFormat
public java.lang.StringBuffer format(double number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
format
in class java.text.NumberFormat
public java.lang.StringBuffer format(long number, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
format
in class java.text.NumberFormat
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
- indirectly via parse(String, ParsePosition)
.
parseObject
in class java.text.Format
java.text.ParseException
public java.lang.Number parse(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
- indirectly via parse(String, ParsePosition)
.
parse
in class java.text.NumberFormat
java.text.ParseException
public java.lang.Number parse(java.lang.String source, java.text.ParsePosition pos)
parse
in class java.text.NumberFormat
Copyright © 2009-2011 JGoodies Karsten Lentzsch. All Rights Reserved.