Class AbstractNumberValidator
java.lang.Object
org.apache.commons.validator.routines.AbstractFormatValidator
org.apache.commons.validator.routines.AbstractNumberValidator
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BigDecimalValidator,BigIntegerValidator,ByteValidator,DoubleValidator,FloatValidator,IntegerValidator,LongValidator,ShortValidator
Abstract class for Number Validation.
This is a base class for building Number Validators using format parsing.
- Since:
- 1.3.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCurrencyNumberFormattypestatic final intPercentNumberFormattypestatic final intStandardNumberFormattype -
Constructor Summary
ConstructorsConstructorDescriptionAbstractNumberValidator(boolean strict, int formatType, boolean allowFractions) Constructs an instance with specified strict and decimal parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected intdetermineScale(NumberFormat format) Returns the multiplier of theNumberFormat.protected FormatReturns aNumberFormatfor the specified pattern and/orLocale.protected FormatReturns aNumberFormatfor the specified Locale.intIndicates the type ofNumberFormatcreated by this validator instance.booleanIndicates whether the number being validated is a decimal or integer.booleanCheck if the value is within a specified range.booleanValidate using the specifiedLocale.booleanCheck if the value is less than or equal to a maximum.booleanCheck if the value is greater than or equal to a minimum.protected ObjectParse the value using the specified pattern.protected abstract ObjectprocessParsedValue(Object value, Format formatter) Process the parsed value, performing any further validation and type conversion required.
-
Field Details
-
STANDARD_FORMAT
StandardNumberFormattype- See Also:
-
CURRENCY_FORMAT
CurrencyNumberFormattype- See Also:
-
PERCENT_FORMAT
PercentNumberFormattype- See Also:
-
-
Constructor Details
-
AbstractNumberValidator
Constructs an instance with specified strict and decimal parameters.- Parameters:
strict-trueif strictFormatparsing should be used.formatType- TheNumberFormattype to create for validation, default is STANDARD_FORMAT.allowFractions-trueif fractions are allowed orfalseif integers only.
-
-
Method Details
-
determineScale
Returns the multiplier of the
NumberFormat.- Parameters:
format- TheNumberFormatto determine the multiplier of.- Returns:
- The multiplying factor for the format..
-
getFormat
Returns a
NumberFormatfor the specified Locale.- Parameters:
locale- The locale aNumberFormatis required for, system default if null.- Returns:
- The
NumberFormatto created.
-
getFormat
Returns a
NumberFormatfor the specified pattern and/orLocale.- Specified by:
getFormatin classAbstractFormatValidator- Parameters:
pattern- The pattern used to validate the value against ornullto use the default for theLocale.locale- The locale to use for the currency format, system default if null.- Returns:
- The
NumberFormatto created.
-
getFormatType
Indicates the type of
NumberFormatcreated by this validator instance.- Returns:
- the format type created.
-
isAllowFractions
Indicates whether the number being validated is a decimal or integer.
- Returns:
trueif decimals are allowed orfalseif the number is an integer.
-
isInRange
Check if the value is within a specified range.- Parameters:
value- The value validation is being performed on.min- The minimum value of the range.max- The maximum value of the range.- Returns:
trueif the value is within the specified range.
-
isValid
Validate using the specified
Locale.- Specified by:
isValidin classAbstractFormatValidator- Parameters:
value- The value validation is being performed on.pattern- The pattern used to validate the value against, or the default for theLocaleifnull.locale- The locale to use for the date format, system default if null.- Returns:
trueif the value is valid.
-
maxValue
Check if the value is less than or equal to a maximum.- Parameters:
value- The value validation is being performed on.max- The maximum value.- Returns:
trueif the value is less than or equal to the maximum.
-
minValue
Check if the value is greater than or equal to a minimum.- Parameters:
value- The value validation is being performed on.min- The minimum value.- Returns:
trueif the value is greater than or equal to the minimum.
-
parse
Parse the value using the specified pattern.
- Parameters:
value- The value validation is being performed on.pattern- The pattern used to validate the value against, or the default for theLocaleifnull.locale- The locale to use for the date format, system default if null.- Returns:
- The parsed value if valid or
nullif invalid.
-
processParsedValue
Process the parsed value, performing any further validation and type conversion required.
- Specified by:
processParsedValuein classAbstractFormatValidator- Parameters:
value- The parsed object created.formatter- The Format used to parse the value with.- Returns:
- The parsed value converted to the appropriate type
if valid or
nullif invalid.
-