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
Modifier and TypeFieldDescriptionstatic final int
CurrencyNumberFormat
typestatic final int
PercentNumberFormat
typestatic final int
StandardNumberFormat
type -
Constructor Summary
ConstructorDescriptionAbstractNumberValidator
(boolean strict, int formatType, boolean allowFractions) Constructs an instance with specified strict and decimal parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
determineScale
(NumberFormat format) Returns the multiplier of theNumberFormat
.protected Format
Returns aNumberFormat
for the specified pattern and/orLocale
.protected Format
Returns aNumberFormat
for the specified Locale.int
Indicates the type ofNumberFormat
created by this validator instance.boolean
Indicates whether the number being validated is a decimal or integer.boolean
Check if the value is within a specified range.boolean
Validate using the specifiedLocale
.boolean
Check if the value is less than or equal to a maximum.boolean
Check if the value is greater than or equal to a minimum.protected Object
Parse the value using the specified pattern.protected abstract Object
processParsedValue
(Object value, Format formatter) Process the parsed value, performing any further validation and type conversion required.
-
Field Details
-
STANDARD_FORMAT
StandardNumberFormat
type- See Also:
-
CURRENCY_FORMAT
CurrencyNumberFormat
type- See Also:
-
PERCENT_FORMAT
PercentNumberFormat
type- See Also:
-
-
Constructor Details
-
AbstractNumberValidator
Constructs an instance with specified strict and decimal parameters.- Parameters:
strict
-true
if strictFormat
parsing should be used.formatType
- TheNumberFormat
type to create for validation, default is STANDARD_FORMAT.allowFractions
-true
if fractions are allowed orfalse
if integers only.
-
-
Method Details
-
determineScale
Returns the multiplier of the
NumberFormat
.- Parameters:
format
- TheNumberFormat
to determine the multiplier of.- Returns:
- The multiplying factor for the format..
-
getFormat
Returns a
NumberFormat
for the specified Locale.- Parameters:
locale
- The locale aNumberFormat
is required for, system default if null.- Returns:
- The
NumberFormat
to created.
-
getFormat
Returns a
NumberFormat
for the specified pattern and/orLocale
.- Specified by:
getFormat
in classAbstractFormatValidator
- Parameters:
pattern
- The pattern used to validate the value against ornull
to use the default for theLocale
.locale
- The locale to use for the currency format, system default if null.- Returns:
- The
NumberFormat
to created.
-
getFormatType
Indicates the type of
NumberFormat
created by this validator instance.- Returns:
- the format type created.
-
isAllowFractions
Indicates whether the number being validated is a decimal or integer.
- Returns:
true
if decimals are allowed orfalse
if 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:
true
if the value is within the specified range.
-
isValid
Validate using the specified
Locale
.- Specified by:
isValid
in classAbstractFormatValidator
- Parameters:
value
- The value validation is being performed on.pattern
- The pattern used to validate the value against, or the default for theLocale
ifnull
.locale
- The locale to use for the date format, system default if null.- Returns:
true
if 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:
true
if 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:
true
if 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 theLocale
ifnull
.locale
- The locale to use for the date format, system default if null.- Returns:
- The parsed value if valid or
null
if invalid.
-
processParsedValue
Process the parsed value, performing any further validation and type conversion required.
- Specified by:
processParsedValue
in 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
null
if invalid.
-