Package org.apache.pivot.wtk.validation
Class DecimalValidator
- java.lang.Object
-
- org.apache.pivot.wtk.validation.FormattedValidator<java.text.NumberFormat>
-
- org.apache.pivot.wtk.validation.DecimalValidator
-
- All Implemented Interfaces:
Validator
- Direct Known Subclasses:
ComparableValidator
,DoubleValidator
,FloatValidator
,IntValidator
public class DecimalValidator extends FormattedValidator<java.text.NumberFormat>
A validator for decimal values.
-
-
Field Summary
-
Fields inherited from class org.apache.pivot.wtk.validation.FormattedValidator
format, locale
-
-
Constructor Summary
Constructors Constructor Description DecimalValidator()
DecimalValidator(java.text.DecimalFormat format)
DecimalValidator(java.text.DecimalFormat format, java.util.Locale locale)
DecimalValidator(java.util.Locale locale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isAutoTrim()
Tell the autoTrim mode.protected java.lang.Number
parseNumber(java.lang.String text)
Helper method that wraps theParseException
in aRuntimeException
.void
setAutoTrim(boolean autoTrim)
Set the autoTrim mode, before parsing the text (default false).protected java.math.BigDecimal
textToBigDecimal(java.lang.String text)
Helper method that returns the widest number real instance, and extract later values depending on the precision needed.-
Methods inherited from class org.apache.pivot.wtk.validation.FormattedValidator
isValid
-
-
-
-
Constructor Detail
-
DecimalValidator
public DecimalValidator(java.text.DecimalFormat format)
-
DecimalValidator
public DecimalValidator(java.text.DecimalFormat format, java.util.Locale locale)
-
DecimalValidator
public DecimalValidator()
-
DecimalValidator
public DecimalValidator(java.util.Locale locale)
-
-
Method Detail
-
parseNumber
protected final java.lang.Number parseNumber(java.lang.String text)
Helper method that wraps theParseException
in aRuntimeException
.- Parameters:
text
- The text to parse.- Returns:
- The number parsed from the text.
- Throws:
java.lang.RuntimeException
- if there was a parsing error.
-
textToBigDecimal
protected final java.math.BigDecimal textToBigDecimal(java.lang.String text)
Helper method that returns the widest number real instance, and extract later values depending on the precision needed.- Parameters:
text
- The text to convert.- Returns:
- The decimal equivalent of the text or
null
if the text cannot be converted.
-
setAutoTrim
public void setAutoTrim(boolean autoTrim)
Set the autoTrim mode, before parsing the text (default false).- Parameters:
autoTrim
- The new auto trim value (true
to trim leading and trailing blanks before parsing text).
-
isAutoTrim
public boolean isAutoTrim()
Tell the autoTrim mode.- Returns:
true
if autoTrim is enabled, otherwisefalse
(default).
-
-