Package org.moeaframework.util.validate
Class NumberValidator<T extends Number & Comparable<T>>
java.lang.Object
org.moeaframework.util.validate.Validator<T>
org.moeaframework.util.validate.NumberValidator<T>
- Type Parameters:
T
- the number type
- Direct Known Subclasses:
DoubleValidator
,IntegerValidator
Abstract validator for
Number
s.
To simplify the implementation of these validations, we use the fact that most numeric types implement the
Comparable
interface. Consequently, this class only supports the "boxed" types for numbers, while most
parameters we are validating are primitives. Thus, prefer creating subclasses that accept only the primitive type,
which then call these generic methods.
-
Constructor Summary
ConstructorDescriptionNumberValidator
(String propertyName, T propertyValue) Constructs a new number validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
failsOnCondition
(String condition) Throws an exception indicating the specified condition failed.protected final void
failsOnCondition
(String condition, String thresholdName, T thresholdValue) Throws an exception indicating the specified condition failed along with threshold value that was violated.protected final void
Asserts the value is between the given lower and upper bounds, inclusive.protected final void
Asserts the value equals some other parameter.protected final void
isGreaterThan
(String thresholdName, T thresholdValue) Asserts the value is greater than some threshold.protected final void
isGreaterThanOrEqualTo
(String thresholdName, T thresholdValue) Asserts the value is greater than or equal to some threshold.protected final void
isLessThan
(String thresholdName, T thresholdValue) Asserts the value is less than some threshold.protected final void
isLessThanOrEqualTo
(String thresholdName, T thresholdValue) Asserts the value is less than or equal to some threshold.protected final void
isNotEqualTo
(String parameterName, T parameterValue) Asserts the value is not equal to some other parameter.Methods inherited from class org.moeaframework.util.validate.Validator
fails, failUnsupportedOption, failUnsupportedOption, getPropertyName, getPropertyValue
-
Constructor Details
-
NumberValidator
Constructs a new number validator.- Parameters:
propertyName
- the property namepropertyValue
- the property value
-
-
Method Details
-
failsOnCondition
Throws an exception indicating the specified condition failed.- Parameters:
condition
- a description of the condition that failed
-
failsOnCondition
Throws an exception indicating the specified condition failed along with threshold value that was violated.- Parameters:
condition
- a description of the condition that failedthresholdName
- the threshold name, ornull
if not associated with a named parameterthresholdValue
- the threshold value
-
isGreaterThan
Asserts the value is greater than some threshold.- Parameters:
thresholdName
- the threshold name, ornull
if not associated with a named parameterthresholdValue
- the threshold value
-
isGreaterThanOrEqualTo
Asserts the value is greater than or equal to some threshold.- Parameters:
thresholdName
- the threshold name, ornull
if not associated with a named parameterthresholdValue
- the threshold value
-
isLessThan
Asserts the value is less than some threshold.- Parameters:
thresholdName
- the threshold name, ornull
if not associated with a named parameterthresholdValue
- the threshold value
-
isLessThanOrEqualTo
Asserts the value is less than or equal to some threshold.- Parameters:
thresholdName
- the threshold name, ornull
if not associated with a named parameterthresholdValue
- the threshold value
-
isEqualTo
Asserts the value equals some other parameter.- Parameters:
parameterName
- the parameter name, ornull
if not associated with a named parameterparameterValue
- the parameter value
-
isNotEqualTo
Asserts the value is not equal to some other parameter.- Parameters:
parameterName
- the parameter name, ornull
if not associated with a named parameterparameterValue
- the parameter value
-
isBetween
Asserts the value is between the given lower and upper bounds, inclusive.- Parameters:
lower
- the lower boundupper
- the upper bound
-