Package cdc.validation
Class Validators
java.lang.Object
cdc.validation.Validators
Registry of validators.
- Author:
- Damien Carbonne
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiongetNames()getStringValidator(String name) 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 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.
-
Field Details
-
PRINTER
public static final cdc.util.debug.Printable PRINTER
-
-
Method Details
-
register
Register a validator with a name.- Parameters:
validator- The validator.name- The name.- Throws:
IllegalArgumentException- Whenvalidatorornameisnull, or when a validator with thatnameis already registered.
-
getNames
- Returns:
- A set of registered validators names.
-
hasValidator
Returnstrueif a validator with a name exists.- Parameters:
name- The name.- Returns:
trueif a validator namednameexists.
-
getValidator
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
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
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
-
getStringValidator
-
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.
-