Package org.conical.common.bbl.util
Class DataValidator
java.lang.Object
org.conical.common.bbl.util.DataValidator
Abstract class which can serve as a parent to any classes that need to
validate input data. (e.g. when processing form input). Typically a child
class will want to call the validator methods using a
label
with the first letter capitalized, since the validation messages generally
start with the label.- Author:
- rdoherty
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addValidationError
(String errorStr) Adds a validation error or warning to the message listReturns a list of validation errors/warnings encountered while validatingstatic boolean
isFieldEmpty
(Object value) Returns whether the field is empty, regardless of type.protected boolean
isFloatAsRequired
(String label, String value) Returns true if the passed value can be evaluated to be a number, or is null or empty.protected boolean
isIntegerAsRequired
(String label, String value) Returns true if the passed value is plain integer (only made up of digits), or is null or empty.protected boolean
isRequiredFieldEmpty
(String label, Object value) Returns true if the passed value is null or empty.protected boolean
isRequiredSize
(String label, String value, int maxLength) Returns true if the passed value is <= maxLength, or if value is null or empty.protected boolean
isRequiredSize
(String label, String value, int minLength, int maxLength) Returns true if the passed value is <= maxLength and >= minLength, or if value is null or empty.
-
Constructor Details
-
DataValidator
public DataValidator()
-
-
Method Details
-
isFieldEmpty
Returns whether the field is empty, regardless of type.- Parameters:
value
- value to be evaluated- Returns:
- true if value is null, or if, after conversion to a String, value contains no characters
-
addValidationError
Adds a validation error or warning to the message list- Parameters:
errorStr
- error/warning text
-
getErrors
Returns a list of validation errors/warnings encountered while validating- Returns:
- list of validation errors/warnings
-
isRequiredSize
Returns true if the passed value is <= maxLength, or if value is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.- Parameters:
label
- name of the value passedvalue
- value to be validatedmaxLength
- maximum valid length of the value- Returns:
- true if value is blank or valid, else false
-
isRequiredSize
Returns true if the passed value is <= maxLength and >= minLength, or if value is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.- Parameters:
label
- name of the value passedvalue
- value to be validatedminLength
- minimum valid length of the valuemaxLength
- maximum valid length of the value- Returns:
- true if value is blank or valid, else false
-
isIntegerAsRequired
Returns true if the passed value is plain integer (only made up of digits), or is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.- Parameters:
label
- name of the value passedvalue
- value to be validated- Returns:
- true if value is blank or valid, else false
-
isFloatAsRequired
Returns true if the passed value can be evaluated to be a number, or is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.- Parameters:
label
- name of the value passedvalue
- value to be validated- Returns:
- true if value is blank or valid, else false
-
isRequiredFieldEmpty
Returns true if the passed value is null or empty. Otherwise returns false. If true is returned, an error message is added detailing the validation failure.- Parameters:
label
- name of the value passedvalue
- value to be validated- Returns:
- true if value is null or blank, else false
-