| java.lang.Object org.apache.commons.validator.routines.AbstractFormatValidator org.apache.commons.validator.routines.AbstractNumberValidator org.apache.commons.validator.routines.BigDecimalValidator org.apache.commons.validator.routines.PercentValidator
PercentValidator | public class PercentValidator extends BigDecimalValidator (Code) | | Percentage Validation and Conversion routines (java.math.BigDecimal ).
This is one implementation of a percent validator that has the following features:
- It is lenient about the the presence of the percent symbol
- It converts the percent to a
java.math.BigDecimal
However any of the number validators can be used for percent validation.
For example, if you wanted a percent validator that converts to a
java.lang.Float then you can simply instantiate an
FloatValidator with the appropriate format type:
... = new FloatValidator(false, FloatValidator.PERCENT_FORMAT);
Pick the appropriate validator, depending on the type (i.e Float, Double or BigDecimal)
you want the percent converted to. Please note, it makes no sense to use
one of the validators that doesn't handle fractions (i.e. byte, short, integer, long
and BigInteger) since percentages are converted to fractions (i.e 50% is
converted to 0.5 ).
version: $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $ since: Validator 1.3.0 |
Constructor Summary | |
public | PercentValidator() Construct a strict instance. | public | PercentValidator(boolean strict) Construct an instance with the specified strict setting. |
Method Summary | |
public static BigDecimalValidator | getInstance() Return a singleton instance of this validator. | protected Object | parse(String value, Format formatter) Parse the value with the specified Format .
This implementation is lenient whether the currency symbol
is present or not. |
PercentValidator | public PercentValidator()(Code) | | Construct a strict instance.
|
PercentValidator | public PercentValidator(boolean strict)(Code) | | Construct an instance with the specified strict setting.
Parameters: strict - true if strict Format parsing should be used. |
getInstance | public static BigDecimalValidator getInstance()(Code) | | Return a singleton instance of this validator.
A singleton instance of the PercentValidator. |
parse | protected Object parse(String value, Format formatter)(Code) | | Parse the value with the specified Format .
This implementation is lenient whether the currency symbol
is present or not. The default NumberFormat
behaviour is for the parsing to "fail" if the currency
symbol is missing. This method re-parses with a format
without the currency symbol if it fails initially.
Parameters: value - The value to be parsed. Parameters: formatter - The Format to parse the value with. The parsed value if valid or null if invalid. |
Fields inherited from org.apache.commons.validator.routines.AbstractNumberValidator | final public static int CURRENCY_FORMAT(Code)(Java Doc) final public static int PERCENT_FORMAT(Code)(Java Doc) final public static int STANDARD_FORMAT(Code)(Java Doc)
|
Methods inherited from org.apache.commons.validator.routines.AbstractNumberValidator | protected int determineScale(NumberFormat format)(Code)(Java Doc) protected Format getFormat(String pattern, Locale locale)(Code)(Java Doc) protected Format getFormat(Locale locale)(Code)(Java Doc) public int getFormatType()(Code)(Java Doc) public boolean isAllowFractions()(Code)(Java Doc) public boolean isInRange(Number value, Number min, Number max)(Code)(Java Doc) public boolean isValid(String value, String pattern, Locale locale)(Code)(Java Doc) public boolean maxValue(Number value, Number max)(Code)(Java Doc) public boolean minValue(Number value, Number min)(Code)(Java Doc) protected Object parse(String value, String pattern, Locale locale)(Code)(Java Doc) abstract protected Object processParsedValue(Object value, Format formatter)(Code)(Java Doc)
|
Methods inherited from org.apache.commons.validator.routines.AbstractFormatValidator | public String format(Object value)(Code)(Java Doc) public String format(Object value, String pattern)(Code)(Java Doc) public String format(Object value, Locale locale)(Code)(Java Doc) public String format(Object value, String pattern, Locale locale)(Code)(Java Doc) protected String format(Object value, Format formatter)(Code)(Java Doc) abstract protected Format getFormat(String pattern, Locale locale)(Code)(Java Doc) public boolean isStrict()(Code)(Java Doc) public boolean isValid(String value)(Code)(Java Doc) public boolean isValid(String value, String pattern)(Code)(Java Doc) public boolean isValid(String value, Locale locale)(Code)(Java Doc) abstract public boolean isValid(String value, String pattern, Locale locale)(Code)(Java Doc) protected Object parse(String value, Format formatter)(Code)(Java Doc) abstract protected Object processParsedValue(Object value, Format formatter)(Code)(Java Doc)
|
|
|