Package org.moeaframework.util.validate
Class Validator<T>
java.lang.Object
org.moeaframework.util.validate.Validator<T>
- Type Parameters:
T
- the value type
- Direct Known Subclasses:
NumberValidator
,ObjectValidator
Abstract class for validators. This class captures the name of the property, argument, or input along with its
value. Subclasses are expected to define specific methods for validating the value based on its type.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<R> R
Throws anIllegalArgumentException
with the given message.final <R> R
failUnsupportedOption
(Class<? extends Enum<?>> enumType) Always fails to indicate a user-provided value does not match the supported list of enum constants.final <S,
R> R failUnsupportedOption
(S... supportedValues) Always fails to indicate a user-provided value does not match the supported list of options.protected String
Returns the property name.protected T
Returns the property value.
-
Constructor Details
-
Validator
Constructs a new validator.- Parameters:
propertyName
- the property namepropertyValue
- the property value
-
-
Method Details
-
getPropertyName
Returns the property name. This method is protected to simplify the API.- Returns:
- the property name
-
getPropertyValue
Returns the property value. This method is protected to simplify the API.- Returns:
- the property value
-
fails
Throws anIllegalArgumentException
with the given message. This method does define a return type so callers canreturn
the result to avoid "not all code paths return a value" compilation errors. However, this method always throws and never returns.- Type Parameters:
R
- the return type, typically determined automatically by the type system- Parameters:
message
- the message describing the validation failure- Returns:
- this method will never return
- Throws:
IllegalArgumentException
- with the given message
-
failUnsupportedOption
Always fails to indicate a user-provided value does not match the supported list of options. The argument is a list of supported values that are displayed in the error message. If none are provided, will attempt to determine the valid values from the type.- Type Parameters:
S
- the type of supported values, which might differ from the property value if conversion is requiredR
- the return type- Parameters:
supportedValues
- a list of supported values- Returns:
- this method never returns
-
failUnsupportedOption
Always fails to indicate a user-provided value does not match the supported list of enum constants. The property value does not necessarily need to be the enum type, as we often convert from strings.- Type Parameters:
R
- the return type- Parameters:
enumType
- the enum type- Returns:
- this method never returns
-