Class NumberValidator<T extends Number>
java.lang.Object
org.apache.fulcrum.intake.validator.DefaultValidator<T>
org.apache.fulcrum.intake.validator.NumberValidator<T>
- All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled
,InitableByConstraintMap
,Validator<T>
- Direct Known Subclasses:
BigDecimalValidator
,DoubleValidator
,FloatValidator
,IntegerValidator
,LongValidator
,ShortValidator
Validates numbers with the following constraints in addition to those
listed in DefaultValidator.
Name | Valid Values | Default Value |
---|---|---|
minValue | greater than BigDecimal.MIN_VALUE | |
maxValue | less than BigDecimal.MAX_VALUE | |
notANumberMessage | Some text | Entry was not a valid number |
- Version:
- $Id$
- Author:
- John McNally, Quinton McCombs, Colin Chalmers
-
Field Summary
Fields inherited from class org.apache.fulcrum.intake.validator.DefaultValidator
errorMessage, log, maxLength, maxLengthMessage, minLength, minLengthMessage, required, requiredMessage
Fields inherited from interface org.apache.fulcrum.intake.validator.Validator
FLEXIBLE_RULE_NAME, FORMAT_RULE_NAME, INVALID_NUMBER_RULE_NAME, MASK_RULE_NAME, MAX_LENGTH_RULE_NAME, MAX_VALUE_RULE_NAME, MIN_LENGTH_RULE_NAME, MIN_VALUE_RULE_NAME, REQUIRED_RULE_NAME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertValidity
(String testValue, Locale locale) Determine whether a testValue meets the criteria specified in the constraints defined for this validatorvoid
assertValidity
(Field<T> field) Determine whether a field meets the criteria specified in the constraints defined for this validatorGet the value of invalidNumberMessage.Get the value of maxValue.Get the value of maxValueMessage.Get the value of minValue.Get the value of minValueMessage.void
init
(Map<String, ? extends Constraint> paramMap) Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.protected Number
parseIntoNumber
(String stringValue, Locale locale) Helper method to parse a number object out of a stringprotected abstract T
parseNumber
(String stringValue, Locale locale) Parse the actual value out of a stringvoid
setInvalidNumberMessage
(String invalidNumberMessage) Set the value of invalidNumberMessage.void
setMaxValue
(T maxValue) Set the value of maxValue.void
setMaxValueMessage
(String maxValueMessage) Set the value of maxValueMessage.void
setMinValue
(T minValue) Set the value of minValue.void
setMinValueMessage
(String minValueMessage) Set the value of minValueMessage.Methods inherited from class org.apache.fulcrum.intake.validator.DefaultValidator
assertValidity, enableLogging, getMaxLength, getMaxLengthMessage, getMessage, getMinLength, getMinLengthMessage, getRequiredMessage, isRequired, isValid, isValid, setMaxLength, setMaxLengthMessage, setMinLength, setMinLengthMessage, setRequired, setRequiredMessage
-
Constructor Details
-
NumberValidator
public NumberValidator()Default Constructor
-
-
Method Details
-
init
Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.- Specified by:
init
in interfaceInitableByConstraintMap
- Overrides:
init
in classDefaultValidator<T extends Number>
- Parameters:
paramMap
- aMap
ofrule
's containing constraints on the input.- Throws:
InvalidMaskException
- an invalid mask was specified
-
parseNumber
Parse the actual value out of a string- Parameters:
stringValue
- the string valuelocale
- the locale to use while parsing- Returns:
- the value
- Throws:
NumberFormatException
- if the value could not be parsed
-
parseIntoNumber
Helper method to parse a number object out of a string- Parameters:
stringValue
- the string valuelocale
- the locale to use while parsing- Returns:
- the Number
- Throws:
NumberFormatException
- if the value could not be parsed
-
assertValidity
Determine whether a field meets the criteria specified in the constraints defined for this validator- Specified by:
assertValidity
in interfaceValidator<T extends Number>
- Overrides:
assertValidity
in classDefaultValidator<T extends Number>
- Parameters:
field
- aField
to be tested- Throws:
ValidationException
- containing an error message if the testValue did not pass the validation tests.
-
assertValidity
Determine whether a testValue meets the criteria specified in the constraints defined for this validator- Parameters:
testValue
- aString
to be testedlocale
- the Locale of the associated field- Throws:
ValidationException
- containing an error message if the testValue did not pass the validation tests.
-
getMinValueMessage
Get the value of minValueMessage.- Returns:
- value of minValueMessage.
-
setMinValueMessage
Set the value of minValueMessage.- Parameters:
minValueMessage
- Value to assign to minValueMessage.
-
getMaxValueMessage
Get the value of maxValueMessage.- Returns:
- value of maxValueMessage.
-
setMaxValueMessage
Set the value of maxValueMessage.- Parameters:
maxValueMessage
- Value to assign to maxValueMessage.
-
getInvalidNumberMessage
Get the value of invalidNumberMessage.- Returns:
- value of invalidNumberMessage.
-
setInvalidNumberMessage
Set the value of invalidNumberMessage.- Parameters:
invalidNumberMessage
- Value to assign to invalidNumberMessage.
-
getMinValue
Get the value of minValue.- Returns:
- value of minValue.
-
setMinValue
Set the value of minValue.- Parameters:
minValue
- Value to assign to minValue.
-
getMaxValue
Get the value of maxValue.- Returns:
- value of maxValue.
-
setMaxValue
Set the value of maxValue.- Parameters:
maxValue
- Value to assign to maxValue.
-