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, requiredMessageFields 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 TypeMethodDescriptionvoidassertValidity(String testValue, Locale locale) Determine whether a testValue meets the criteria specified in the constraints defined for this validatorvoidassertValidity(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.voidinit(Map<String, ? extends Constraint> paramMap) Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.protected NumberparseIntoNumber(String stringValue, Locale locale) Helper method to parse a number object out of a stringprotected abstract TparseNumber(String stringValue, Locale locale) Parse the actual value out of a stringvoidsetInvalidNumberMessage(String invalidNumberMessage) Set the value of invalidNumberMessage.voidsetMaxValue(T maxValue) Set the value of maxValue.voidsetMaxValueMessage(String maxValueMessage) Set the value of maxValueMessage.voidsetMinValue(T minValue) Set the value of minValue.voidsetMinValueMessage(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:
initin interfaceInitableByConstraintMap- Overrides:
initin classDefaultValidator<T extends Number>- Parameters:
paramMap- aMapofrule'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:
assertValidityin interfaceValidator<T extends Number>- Overrides:
assertValidityin classDefaultValidator<T extends Number>- Parameters:
field- aFieldto 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- aStringto 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.
-