Package cdc.validation
Class Validators
- java.lang.Object
-
- cdc.validation.Validators
-
public class Validators extends Object
Registry of validators.- Author:
- Damien Carbonne
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classValidators.Printer
-
Field Summary
Fields Modifier and Type Field Description static cdc.util.debug.PrintablePRINTER
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Set<String>getNames()static Validator<? super String>getStringValidator(String name)static Validator<? super String>getStringValidator(String name, cdc.util.lang.FailureReaction reaction)static <T> Validator<? super T>getValidator(Class<T> valueClass, String name)Returns the validator that has a name and a value type.static <T> Validator<? super T>getValidator(Class<T> valueClass, String name, cdc.util.lang.FailureReaction reaction)Returns the validator that has a name and a value type.static Validator<?>getValidator(String name)Returns the validator that has a name.static Validator<?>getValidator(String name, cdc.util.lang.FailureReaction reaction)Returns the validator that has a name.static booleanhasValidator(String name)Returnstrueif a validator with a name exists.static voidregister(Validator<?> validator, String name)Register a validator with a name.static <T> List<ValidationRecord>validate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName)Validates a value with a validator and returns a list of validation records.static <T> voidvalidate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName, ValidationHandler handler)Validates a value with a validator.static <T> voidvalidate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName, List<ValidationRecord> records)Validates a value with a validator and fills a list of validation records.static voidvalidateRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName, ValidationHandler handler)Validates a raw value with a validator.static voidvalidateRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName, List<ValidationRecord> records)Validates a raw value with a validator and fills a list of validation records.static List<ValidationRecord>validatRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName)Validates a raw value with a validator and returns a list of validation records.
-
-
-
Method Detail
-
register
public static void register(Validator<?> validator, String name)
Register a validator with a name.- Parameters:
validator- The validator.name- The name.- Throws:
IllegalArgumentException- Whenvalidatorornameisnull, or when a validator with thatnameis already registered.
-
hasValidator
public static boolean hasValidator(String name)
Returnstrueif a validator with a name exists.- Parameters:
name- The name.- Returns:
trueif a validator namednameexists.
-
getValidator
public static Validator<?> getValidator(String name, cdc.util.lang.FailureReaction reaction)
Returns the validator that has a name.- Parameters:
name- The name.reaction- The reaction to adopt if no matching validator is found.- Returns:
- The validator named
nameornullor an exception, depending onreaction. - Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.
-
getValidator
public static Validator<?> getValidator(String name)
Returns the validator that has a name.- Parameters:
name- The name.- Returns:
- The validator named
name. - Throws:
cdc.util.lang.NotFoundException- When no validator is found.
-
getValidator
public static <T> Validator<? super T> getValidator(Class<T> valueClass, String name, cdc.util.lang.FailureReaction reaction)
Returns the validator that has a name and a value type.- Type Parameters:
T- The validator value type.- Parameters:
valueClass- The validator value class.name- The name.reaction- The reaction to adopt if no matching validator is found.- Returns:
- the validator named
nameornullor an exception, depending onreaction. - Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
getValidator
public static <T> Validator<? super T> getValidator(Class<T> valueClass, String name)
Returns the validator that has a name and a value type.- Type Parameters:
T- The validator value type.- Parameters:
valueClass- The validator value class.name- The name.- Returns:
- the validator named
nameornullor an exception. - Throws:
cdc.util.lang.NotFoundException- When no validator is found.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
getStringValidator
public static Validator<? super String> getStringValidator(String name, cdc.util.lang.FailureReaction reaction)
-
validate
public static <T> void validate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName, ValidationHandler handler)
Validates a value with a validator.- Type Parameters:
T- The value type.- Parameters:
valueClass- The value class.validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.handler- The validation messages handler.- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
validate
public static <T> void validate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName, List<ValidationRecord> records)
Validates a value with a validator and fills a list of validation records.- Type Parameters:
T- The value type.- Parameters:
valueClass- The value class.validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.records- The list of validation records that must be filled.- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
validate
public static <T> List<ValidationRecord> validate(Class<T> valueClass, String validatorName, cdc.util.lang.FailureReaction reaction, T value, String valueName)
Validates a value with a validator and returns a list of validation records.- Type Parameters:
T- The value type.- Parameters:
valueClass- The value class.validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.- Returns:
- A list of validation records, possibly empty.
- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
validateRaw
public static void validateRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName, ValidationHandler handler)
Validates a raw value with a validator.- Parameters:
validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.handler- The validation messages handler.- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.ClassCastException- Ifvalueis notnulland cannot be assigned to value type of the found validator.
-
validateRaw
public static void validateRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName, List<ValidationRecord> records)
Validates a raw value with a validator and fills a list of validation records.- Parameters:
validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.records- The list of validation records that must be filled.- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.ClassCastException- Ifvalueis notnulland cannot be assigned to value type of the found validator.
-
validatRaw
public static List<ValidationRecord> validatRaw(String validatorName, cdc.util.lang.FailureReaction reaction, Object value, String valueName)
Validates a raw value with a validator and returns a list of validation records.- Parameters:
validatorName- The validator name.reaction- The reaction to adopt if no matching validator is found.value- The value.valueName- The name that must be given tovaluein messages.- Returns:
- A list of validation records, possibly empty.
- Throws:
cdc.util.lang.NotFoundException- When no validator is found andreactionisFailureReaction.FAIL.IllegalArgumentException- When a validator is found but its value type does not matchvalueClass.
-
-