ValidationUtils
This utility class provides methods for validating various data types, primarily double and generic objects, to ensure they meet certain criteria (e.g., not NaN, not infinite, not null). It throws ValidationExceptions when validation fails, providing informative error messages.
Fields
NO_NAME
A static String constant used as a default parameter name when one is not specified.
NO_MORE_INFO
A static String constant used as a default custom message when more information is not specified.
Methods
validateNotNaN(double value, String parameterName, String customMessage)
Validates that a double value is not NaN (Not a Number). If it is, a ValidationException is thrown with a detailed error message including the parameterName and customMessage.
validateNotNaN(double value, String parameterName)
Overloaded method. Validates that a double value is not NaN, using a default custom message.
validateNotInfinite(double value, String parameterName, String customMessage)
Validates that a double value is not positive or negative infinity. If it is, a ValidationException is thrown with a detailed error message.
validateNotInfinite(double value, String parameterName)
Overloaded method. Validates that a double value is not infinite, using a default custom message.
validate(double value, String parameterName, boolean canBeNaN, boolean canBeInfinite, String customMessage)
Comprehensive validation for a double value. It allows specifying whether the value can be NaN or infinite. If validation fails, a ValidationException is thrown.
validate(double value, String parameterName, DoubleValidationMode mode, String customMessage)
Validates a double value based on a DoubleValidationMode enum, which encapsulates canBeNaN and canBeInfinite flags.
validate(double value, String parameterName, String customMessage)
Overloaded method. Validates a double value using DoubleValidationMode.NOT_NAN_OR_INFINITE and a custom message.
validate(double value, String parameterName)
Overloaded method. Validates a double value using DoubleValidationMode.NOT_NAN_OR_INFINITE and a default custom message.
validate(double value)
Overloaded method. Validates a double value using DoubleValidationMode.NOT_NAN_OR_INFINITE and default parameter name and custom message.
validate(float value, String parameterName)
Validates a float value by casting it to a double and using the validate(double, String) method.
validate(float value)
Overloaded method. Validates a float value using default parameter name.
validateNotNull(T t, String parameterName, String customMessage)
Validates that a generic object t is not null. If it is, a ValidationException is thrown.
validateNotNull(T t, String parameterName)
Overloaded method. Validates that a generic object t is not null, using a default custom message.
validate(T t, String parameterName, String customMessageFormat, Object[] formatSources)
Validates a generic object t for nullity, allowing for a formatted custom message.
validateAndFormat(T t, String parameterName, String customMessage, Object... formatSources)
Overloaded method. Validates a generic object t for nullity, allowing for a formatted custom message (varargs version).
validate(T t, String parameterName, String customMessage)
Overloaded method. Validates a generic object t for nullity with a custom message.
validate(T t, String parameterName)
Overloaded method. Validates a generic object t for nullity with a default custom message.
validate(T t)
Overloaded method. Validates a generic object t for nullity with default parameter name and custom message.
Enum: DoubleValidationMode
An enum defining different modes for double validation, specifying whether NaN or infinite values are allowed.
DO_NOT_VALIDATE
Allows NaN and infinite values.
NOT_NAN
Does not allow NaN values, but allows infinite values.
NOT_INFINITE
Allows NaN values, but does not allow infinite values.
NOT_NAN_OR_INFINITE
Does not allow NaN or infinite values.