Module de.carne

Class 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 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 not null.
        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.
      • 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.
      • get

        public I get()
        Specified by:
        get in interface java.util.function.Supplier<I>