- java.lang.Object
-
- de.carne.util.validation.InputValidator<I>
-
- Type Parameters:
I- the actual input type.
- All Implemented Interfaces:
java.util.function.Supplier<I>
- Direct Known Subclasses:
PathValidator,StringValidator
public class InputValidator<I> extends java.lang.Object implements java.util.function.Supplier<I>Base class for all kinds of input validation classes.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedInputValidator(I input)Constructs a new InputValidator instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description InputValidator<I>check(Validation<I> validation, ValidationMessage message)Checks the given validation.static <I> InputValidator<I>checkNotNull(@Nullable I input, ValidationMessage message)Checks that an input value is notnull.<O> Oconvert(Conversion<I,O> conversion, ValidationMessage message)Checks and converts the input value against the given conversion.Iget()static <I> InputValidator<I>input(I input)Constructs a new InputValidator instance for input validation.
-
-
-
Constructor Detail
-
InputValidator
protected InputValidator(I input)
Constructs a new InputValidator instance.- Parameters:
input- the input value to validate.
-
-
Method Detail
-
input
public static <I> InputValidator<I> input(I input)
Constructs a new InputValidator instance for input validation.- Type Parameters:
I- the actual input type.- Parameters:
input- the input value to check.- Returns:
- the new InputValidator instance for further validation steps.
-
checkNotNull
public static <I> InputValidator<I> checkNotNull(@Nullable I input, ValidationMessage message) throws ValidationException
Checks that an input value is notnull.- Type Parameters:
I- the actual input type.- Parameters:
input- the input value to check.message- the validation message to create in case the validation fails.- Returns:
- a new InputValidator instance for further validation steps.
- Throws:
ValidationException- if the validation fails.
-
check
public InputValidator<I> check(Validation<I> validation, ValidationMessage message) throws ValidationException
Checks the given validation.- Parameters:
validation- the Validation to perform.message- the validation message to create in case the validation fails.- Returns:
- the validated InputValidator instance for further validation steps.
- Throws:
ValidationException- if the validation fails.
-
convert
public <O> O convert(Conversion<I,O> conversion, ValidationMessage message) throws ValidationException
Checks and converts the input value against the given conversion.- Type Parameters:
O- the actual output type.- Parameters:
conversion- the Conversion to apply.message- the validation message to create in case the conversion fails.- Returns:
- the converted InputValidator instance for further validation steps.
- Throws:
ValidationException- if the conversion fails.
-
-