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
Numbers.
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
ConstructorsConstructorDescriptionNumberValidator(String propertyName, T propertyValue) Constructs a new number validator. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidfailsOnCondition(String condition) Throws an exception indicating the specified condition failed.protected final voidfailsOnCondition(String condition, String thresholdName, T thresholdValue) Throws an exception indicating the specified condition failed along with threshold value that was violated.protected final voidAsserts the value is between the given lower and upper bounds, inclusive.protected final voidAsserts the value equals some other parameter.protected final voidisGreaterThan(String thresholdName, T thresholdValue) Asserts the value is greater than some threshold.protected final voidisGreaterThanOrEqualTo(String thresholdName, T thresholdValue) Asserts the value is greater than or equal to some threshold.protected final voidisLessThan(String thresholdName, T thresholdValue) Asserts the value is less than some threshold.protected final voidisLessThanOrEqualTo(String thresholdName, T thresholdValue) Asserts the value is less than or equal to some threshold.protected final voidisNotEqualTo(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, ornullif not associated with a named parameterthresholdValue- the threshold value
-
isGreaterThan
Asserts the value is greater than some threshold.- Parameters:
thresholdName- the threshold name, ornullif 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, ornullif not associated with a named parameterthresholdValue- the threshold value
-
isLessThan
Asserts the value is less than some threshold.- Parameters:
thresholdName- the threshold name, ornullif 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, ornullif not associated with a named parameterthresholdValue- the threshold value
-
isEqualTo
Asserts the value equals some other parameter.- Parameters:
parameterName- the parameter name, ornullif 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, ornullif 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
-