Package cdc.util.validation
Interface Validator<T>
-
- Type Parameters:
T- Value type.
- All Known Implementing Classes:
ValidatorImpl
public interface Validator<T>Validator of values.- Author:
- Damien Carbonne
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <S> Validator<S>after(Converter<S,? extends T> converter)Creates a validator composed of this one applied after a converter.default <S> Validator<S>after(Function<S,? extends T> function, Class<S> sourceClass)Creates a validator composed of this one applied after a conversion function.default Validator<?>afterRaw(Converter<?,?> converter)default ValiditygetValidity(T value)Returns the validity of a value.default ValiditygetValidityRaw(Object value)Returns the validity of a raw value.Class<T>getValueClass()default List<ValidationRecord>validate(T value, String name)Validates a value and returns a list of validation records.voidvalidate(T value, String name, ValidationHandler handler)Validates a value.default voidvalidate(T value, String name, List<ValidationRecord> records)Validates a value and adds validation records to a list.default List<ValidationRecord>validateRaw(Object value, String name)Validates a raw value and returns a list of validation records.default voidvalidateRaw(Object value, String name, ValidationHandler handler)Validates a raw value.default voidvalidateRaw(Object value, String name, List<ValidationRecord> records)Validates a raw value and adds validation records to a list.
-
-
-
Method Detail
-
validate
void validate(T value, String name, ValidationHandler handler)
Validates a value.- Parameters:
value- The value.name- The name that must be given tovaluein messages.handler- The validation messages handler.
-
validate
default void validate(T value, String name, List<ValidationRecord> records)
Validates a value and adds validation records to a list.- Parameters:
value- The value.name- The name that must be given tovaluein messages.records- The list of validation records that must be filled.- Throws:
IllegalArgumentException- Whenrecordsisnull.
-
validate
default List<ValidationRecord> validate(T value, String name)
Validates a value and returns a list of validation records.- Parameters:
value- The value.name- The name that must be given tovaluein messages.- Returns:
- A list of validation records, possibly empty.
-
validateRaw
default void validateRaw(Object value, String name, ValidationHandler handler)
Validates a raw value.- Parameters:
value- The value.name- The name that must be given tovaluein messages.handler- The validation messages handler.- Throws:
ClassCastException- Ifvalueis notnulland cannot be assigned to value typeT.
-
validateRaw
default void validateRaw(Object value, String name, List<ValidationRecord> records)
Validates a raw value and adds validation records to a list.- Parameters:
value- The value.name- The name that must be given tovaluein messages.records- The list of validation records that must be filled.- Throws:
IllegalArgumentException- Whenrecordsisnull.ClassCastException- Ifvalueis notnulland cannot be assigned to value typeT.
-
validateRaw
default List<ValidationRecord> validateRaw(Object value, String name)
Validates a raw value and returns a list of validation records.- Parameters:
value- The value.name- The name that must be given tovaluein messages.- Returns:
- A list of validation records, possibly empty.
- Throws:
ClassCastException- Ifvalueis notnulland cannot be assigned to value typeT.
-
getValidity
default Validity getValidity(T value)
Returns the validity of a value.- Parameters:
value- The value.- Returns:
- The validity of
value.
-
getValidityRaw
default Validity getValidityRaw(Object value)
Returns the validity of a raw value.- Parameters:
value- The value.- Returns:
- The validity of
value. - Throws:
ClassCastException- Ifvalueis notnulland cannot be assigned to value typeT.
-
after
default <S> Validator<S> after(Converter<S,? extends T> converter)
Creates a validator composed of this one applied after a converter.- Type Parameters:
S- The source type.- Parameters:
converter- The converter from source typeStoT.- Returns:
- A new validator composed of this one applied after
converter. - Throws:
IllegalArgumentException- Whenconverterisnull.
-
afterRaw
default Validator<?> afterRaw(Converter<?,?> converter)
- Parameters:
converter- The converter.- Returns:
- A new validator composed of this one applied after
converter. - Throws:
IllegalArgumentException- Whenconverterisnull.
-
after
default <S> Validator<S> after(Function<S,? extends T> function, Class<S> sourceClass)
Creates a validator composed of this one applied after a conversion function.- Type Parameters:
S- The source type.- Parameters:
function- The function that converts values from source typeStoT.sourceClass- The source class.- Returns:
- A new validator composed of this one applied conversion
function. - Throws:
IllegalArgumentException- WhenfunctionorsourceClassisnull.
-
-