Description
These are suggestions for new methods for the Validate class.
Floating point values
notNaN(value)
Throws an exception if value != value .
double value; value = Double.NaN; Validate.notNaN(value); // Throws exception value = 1.0; Validate.notNaN(value); // Validates value = Double.POSITIVE_INFINITY; Validate.notNaN(value); // Validates
finite(value)
Validates that the argument contains a numeric value (not NaN or infinite).
double value; value = Double.NaN; Validate.finite(value); // Throws exception value = Double.POSITIVE_INFINITY; Validate.finite(value); // Throws exception value = 1.0; Validate.finite(value); // Validates
Integers and floats
The following methods are overloaded to accept both integers and floating point values.
greater(reference, value), greaterOrEqual(reference, value)
Ensures the argument is greater than (or equal to) a given value.
double value; value = 0.0; Validate.greater(0.0, value); // Throws exception Validate.greaterOrEqual(0.0, value); // Validates value = Double.POSITIVE_INFINITY; Validate.greater(0.0, value); // Validates value = Double.NaN; Validate.greater(0.0, value); // Throws exception
smaller(reference, value), smallerOrEqual(reference, value)
Ensures the argument is smaller than (or equal to) a given value. Does the opposite of greater(), see example above.
different(reference, value)
Ensures the argument is not equal to a given value. A typical use case would be to accept only non-zero values.
double value; value = 0.0; Validate.different(0.0, value); // Throws exception Validate.different(1.0, value); // Validates value = Double.NaN; Validate.different(0.0, value); // Validates
Attachments
Issue Links
- is superceded by
-
LANG-1268 Add methods for comparing numbers/compareables against each others to Validate
- Open