public abstract class BaseValidator
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
BaseValidator.ValidationContext
This class encapsulates the validation context from which a validation check is happening.
|
| Modifier | Constructor and Description |
|---|---|
protected |
BaseValidator() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addSupportedClass(java.lang.Class<?> clazz)
Add a supported class to this
BaseValidator. |
protected static java.util.List<RaveError> |
checkFloatRange(BaseValidator.ValidationContext validationContext,
double value,
double from,
double to)
Check a double value to be in the correct range.
|
protected static java.util.List<RaveError> |
checkIntDef(BaseValidator.ValidationContext validationContext,
int value,
boolean flag,
int... acceptableValues)
Check the value of an input int to see if it matches the acceptable values.
|
protected static java.util.List<RaveError> |
checkIntRange(BaseValidator.ValidationContext validationContext,
long value,
long from,
long to)
Checks the input long value is within the bounds of
from and to inclusive. |
protected static java.util.List<RaveError> |
checkLongDef(BaseValidator.ValidationContext validationContext,
long value,
boolean flag,
long... acceptableValues)
Check the value of an input long to see if it matches the acceptable values.
|
protected static java.util.List<RaveError> |
checkNullable(java.util.Collection<?> collection,
boolean isNullable,
BaseValidator.ValidationContext validationContext)
Checks to see if the object is null.
|
protected static <K,V> java.util.List<RaveError> |
checkNullable(java.util.Map<K,V> map,
boolean isNullable,
BaseValidator.ValidationContext validationContext)
Checks to see if the map is null.
|
protected static java.util.List<RaveError> |
checkNullable(java.lang.Object obj,
boolean isNullable,
BaseValidator.ValidationContext validationContext)
Checks to see if the object is null.
|
protected static <T> java.util.List<RaveError> |
checkNullable(T[] array,
boolean isNullable,
BaseValidator.ValidationContext validationContext)
Checks to see if the object is null.
|
protected static java.util.List<RaveError> |
checkStringDef(boolean isNullable,
BaseValidator.ValidationContext validationContext,
java.util.Collection<java.lang.String> values,
java.lang.String... acceptableValues)
Utility to check if the strings in a
Collection of strings match acceptable values. |
protected static java.util.List<RaveError> |
checkStringDef(boolean isNullable,
BaseValidator.ValidationContext validationContext,
java.lang.String[] values,
java.lang.String... acceptableValues)
Utility to check if the strings in a array of strings match acceptable values.
|
protected static java.util.List<RaveError> |
checkStringDef(boolean isNullable,
BaseValidator.ValidationContext validationContext,
java.lang.String value,
java.lang.String... acceptableValues)
Utility to check if a string is present in a list of strings.
|
protected java.util.Set<java.lang.Class<?>> |
getSupportedClasses() |
protected static BaseValidator.ValidationContext |
getValidationContext(java.lang.Class<?> clazz)
Return an instance of a
BaseValidator.ValidationContext. |
protected static java.util.List<RaveError> |
isSizeOk(java.util.Collection<?> collection,
boolean isNullable,
long min,
long max,
long multiple,
BaseValidator.ValidationContext validationContext)
Validates a collection.
|
protected static <K,V> java.util.List<RaveError> |
isSizeOk(java.util.Map<K,V> map,
boolean isNullable,
long min,
long max,
long multiple,
BaseValidator.ValidationContext validationContext)
Validate the size of an Map.
|
protected static java.util.List<RaveError> |
isSizeOk(java.lang.String string,
boolean isNullable,
long min,
long max,
long multiple,
BaseValidator.ValidationContext validationContext)
Checks to see if the size of the input string is of a size as denoted by
min and max. |
protected static <T> java.util.List<RaveError> |
isSizeOk(T[] array,
boolean isNullable,
long min,
long max,
long multiple,
BaseValidator.ValidationContext validationContext)
Validate the size of an Array.
|
protected static java.util.List<RaveError> |
mergeErrors(java.util.List<RaveError> e1,
java.util.List<RaveError> e2)
Takes two RaveError lists and merges them into one.
|
protected static java.util.List<RaveError> |
mustBeFalse(boolean input,
BaseValidator.ValidationContext validationContext) |
protected static java.util.List<RaveError> |
mustBeTrue(boolean input,
BaseValidator.ValidationContext validationContext)
Verifies the input to be always true.
|
protected java.util.List<RaveError> |
reEvaluateAsSuperType(java.lang.Class<?> clazz,
java.lang.Object obj)
This class kicks the validate call back up through the RAVE api.
|
protected void |
registerSelf()
Register this
BaseValidator with the Rave registry. |
protected abstract void |
validateAs(java.lang.Object obj,
java.lang.Class<?> clazz)
This method targets the inheritance issue for validation.
|
protected final java.util.Set<java.lang.Class<?>> getSupportedClasses()
protected abstract void validateAs(java.lang.Object obj,
java.lang.Class<?> clazz)
throws RaveException
obj - the object to validateclazz - the class to validate it as.RaveException - if validation fails.@Nullable protected final java.util.List<RaveError> reEvaluateAsSuperType(java.lang.Class<?> clazz, java.lang.Object obj)
clazz - the class to validate this object as.obj - the object to validateRaveErrors.protected final void registerSelf()
BaseValidator with the Rave registry.protected final void addSupportedClass(java.lang.Class<?> clazz)
BaseValidator.clazz - the Class to add.protected static BaseValidator.ValidationContext getValidationContext(java.lang.Class<?> clazz)
BaseValidator.ValidationContext.clazz - the Class to tie to the BaseValidator.ValidationContextBaseValidator.ValidationContext@Nullable protected static java.util.List<RaveError> mustBeFalse(boolean input, BaseValidator.ValidationContext validationContext)
protected static java.util.List<RaveError> isSizeOk(@Nullable java.lang.String string, boolean isNullable, long min, long max, long multiple, BaseValidator.ValidationContext validationContext)
min and max. Also check
the multiple constraint of size.string - The string to validate.isNullable - if true than null is a valid value for the input string regardless of min and max.min - The string must be at least this long.max - The string must not exceed this length.multiple - The multiple constraint on the Size. If less than zero it is
ignored.validationContext - The context of the item in the class being validated. This is used in case of an error.List of RaveErrors which list the validation violations. Null otherwise.protected static java.util.List<RaveError> isSizeOk(@Nullable java.util.Collection<?> collection, boolean isNullable, long min, long max, long multiple, BaseValidator.ValidationContext validationContext)
collection - the collection to validate.isNullable - if true than null is a valid value for the input string regardless of min and max.min - The collection must have least this many elements in it.max - The collection can have at most this many elements in it.multiple - The multiple constraint on the Size. If less than zero it is
ignored.validationContext - The context of the item in the class being validated. This is used in case of an error.List of RaveErrors which list the validation violations. Null otherwise.@Nullable protected static <T> java.util.List<RaveError> isSizeOk(@Nullable T[] array, boolean isNullable, long min, long max, long multiple, BaseValidator.ValidationContext validationContext)
T - can be anytype.array - the array to validate.isNullable - if true than null is a valid value for the input string regardless of min and max.min - The Array must have least this many elements in it.max - The Array can have at most this many elements in it.multiple - The multiple constraint on the Size. If less than zero it is
ignored.validationContext - The context of the item in the class being validated. This is used in case of an error.List of RaveErrors which list the validation violations. Null otherwise.@Nullable protected static <K,V> java.util.List<RaveError> isSizeOk(@Nullable java.util.Map<K,V> map, boolean isNullable, long min, long max, long multiple, BaseValidator.ValidationContext validationContext)
K - key type of the map and can be any type.V - value type of the map and can be any type.map - the Map to validate.isNullable - if true than null is a valid value for the input string regardless of min and max.min - the Array must have least this many elements in it.max - the Array can have at most this many elements in it.multiple - the multiple constraint on the Size. If less than zero it is
ignored.validationContext - the context of the item in the class being validated. This is used in case of an error.List of RaveErrors which list the validation violations. Null otherwise.protected static java.util.List<RaveError> checkNullable(@Nullable java.lang.Object obj, boolean isNullable, BaseValidator.ValidationContext validationContext)
obj - the object to validate.isNullable - is the object is allowed to be null.validationContext - The context of the item in the class being validated. This is used in case of an error.RaveErrors if the object is not allowed to be null. Returns null otherwise.protected static java.util.List<RaveError> checkNullable(@Nullable java.util.Collection<?> collection, boolean isNullable, BaseValidator.ValidationContext validationContext)
collection - the collection to validate.isNullable - is the object is allowed to be null.validationContext - the context of the item in the class being validated. This is used in case of an error.RaveErrors if the object is not allowed to be null. Returns null otherwise.protected static <T> java.util.List<RaveError> checkNullable(@Nullable T[] array, boolean isNullable, BaseValidator.ValidationContext validationContext)
array - the array to validate.isNullable - is the object is allowed to be null.validationContext - the context of the item in the class being validated. This is used in case of an error.RaveErrors if the object is not allowed to be null. Returns null otherwise.protected static <K,V> java.util.List<RaveError> checkNullable(@Nullable java.util.Map<K,V> map, boolean isNullable, BaseValidator.ValidationContext validationContext)
map - the map to validate.isNullable - is the object is allowed to be null.validationContext - The context of the item in the class being validated. This is used in case of an error.RaveErrors if the object is not allowed to be null. Returns null otherwise. This
method will also RAVE validate the keys and values of the map if they are RAVE enabled.@Nullable protected static java.util.List<RaveError> mergeErrors(@Nullable java.util.List<RaveError> e1, @Nullable java.util.List<RaveError> e2)
protected static java.util.List<RaveError> mustBeTrue(boolean input, BaseValidator.ValidationContext validationContext)
input - the value to validate.validationContext - The context of the item in the class being validated. This is used in case of an error.List otherwise.protected static java.util.List<RaveError> checkStringDef(boolean isNullable, BaseValidator.ValidationContext validationContext, @Nullable java.lang.String value, java.lang.String... acceptableValues)
isNullable - if the value is allowed to be null or not.validationContext - The context of the item in the class being validated. This is used in case of an error.value - string to look for.acceptableValues - list of strings to look in.protected static java.util.List<RaveError> checkStringDef(boolean isNullable, BaseValidator.ValidationContext validationContext, @Nullable java.util.Collection<java.lang.String> values, java.lang.String... acceptableValues)
Collection of strings match acceptable values. If the input
Collection is null then nothing is done.isNullable - if the value is allowed to be null or not.validationContext - The context of the item in the class being validated. This is used in case of an error.values - a Collection of strings to validate.acceptableValues - list acceptable values for the input list.protected static java.util.List<RaveError> checkStringDef(boolean isNullable, BaseValidator.ValidationContext validationContext, @Nullable java.lang.String[] values, java.lang.String... acceptableValues)
isNullable - if the value is allowed to be null or not.validationContext - The context of the item in the class being validated. This is used in case of an error.values - a array of strings to validate.acceptableValues - list acceptable values for the input array.protected static java.util.List<RaveError> checkFloatRange(BaseValidator.ValidationContext validationContext, double value, double from, double to)
from and to are used as the boundry checks and
are inclusive. Note Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY are supported.
If used any value is always greater than Double.NEGATIVE_INFINITY and always less than
Double.POSITIVE_INFINITY by definition.validationContext - the BaseValidator.ValidationContextvalue - the value to checkfrom - the lower bound of the check (inclusive)to - the upper bound of the check (inclusive)RaveError if the checked value is not within the bounds.protected static java.util.List<RaveError> checkIntRange(BaseValidator.ValidationContext validationContext, long value, long from, long to)
from and to inclusive.validationContext - the BaseValidator.ValidationContextvalue - the value to check.from - the lower bound of the check, inclusive.to - the upper bound of the check, inclusive.RaveError if the checked value is not within the bounds.protected static java.util.List<RaveError> checkIntDef(BaseValidator.ValidationContext validationContext, int value, boolean flag, int... acceptableValues)
validationContext - The context of the item in the class being validated. This is used in case of an error.value - The long value to check.flag - the is the flag value from IntDef it is currently unsupported.acceptableValues - the values that the value parameter can take on.protected static java.util.List<RaveError> checkLongDef(BaseValidator.ValidationContext validationContext, long value, boolean flag, long... acceptableValues)
validationContext - The context of the item in the class being validated. This is used in case of an error.value - The long value to check.flag - the is the flag value from IntDef it is currently unsupported.acceptableValues - the values that the value parameter can take on.