Class Validators

java.lang.Object
io.helidon.validation.Validators

public class Validators extends Object
Programmatic API to validate values and types. There are always two methods for validation - one starting with validate and one starting with check. The validate method will return a ValidationResponse, while the check method will throw an ValidationException if the validation fails.
  • Method Details

    • validateNotNull

      public static ValidationResponse validateNotNull(Object value)
      Check that the value is not null.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNotNull

      public static void checkNotNull(Object value)
      Check that the value is not null.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateNull

      public static ValidationResponse validateNull(Object value)
      Check that the value is null.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNull

      public static void checkNull(Object value)
      Check that the value is null.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateEmail

      public static ValidationResponse validateEmail(CharSequence value)
      Check that the string value is a valid email address.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkEmail

      public static void checkEmail(CharSequence value)
      Check that the string value is a valid email address.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateNotBlank

      public static ValidationResponse validateNotBlank(CharSequence value)
      Check that the string value is not blank.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNotBlank

      public static void checkNotBlank(CharSequence value)
      Check that the string value is not blank.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateNotEmpty

      public static ValidationResponse validateNotEmpty(CharSequence value)
      Check that the string value is not empty.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNotEmpty

      public static void checkNotEmpty(CharSequence value)
      Check that the string value is not empty.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateLength

      public static ValidationResponse validateLength(CharSequence value, int minLength, int maxLength)
      Check that the string value has the specified length.
      Parameters:
      value - value to check
      minLength - minimum length (inclusive)
      maxLength - maximum length (inclusive)
      Returns:
      validation response
    • checkLength

      public static void checkLength(CharSequence value, int minLength, int maxLength)
      Check that the string value has the specified length.
      Parameters:
      value - value to check
      minLength - minimum length (inclusive)
      maxLength - maximum length (inclusive)
      Throws:
      ValidationException - if the validation fails
    • validatePattern

      public static ValidationResponse validatePattern(CharSequence value, String pattern)
      Check that the string value matches the specified pattern.
      Parameters:
      value - value to check
      pattern - regular expression pattern
      Returns:
      validation response
    • checkPattern

      public static void checkPattern(CharSequence value, String pattern)
      Check that the string value matches the specified pattern.
      Parameters:
      value - value to check
      pattern - regular expression pattern
      Throws:
      ValidationException - if the validation fails
    • validateNegative

      public static ValidationResponse validateNegative(Number value)
      Check that the number value is negative.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNegative

      public static void checkNegative(Number value)
      Check that the number value is negative.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateNegativeOrZero

      public static ValidationResponse validateNegativeOrZero(Number value)
      Check that the number value is negative or zero.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkNegativeOrZero

      public static void checkNegativeOrZero(Number value)
      Check that the number value is negative or zero.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validatePositive

      public static ValidationResponse validatePositive(Number value)
      Check that the number value is positive.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkPositive

      public static void checkPositive(Number value)
      Check that the number value is positive.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validatePositiveOrZero

      public static ValidationResponse validatePositiveOrZero(Number value)
      Check that the number value is positive or zero.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkPositiveOrZero

      public static void checkPositiveOrZero(Number value)
      Check that the number value is positive or zero.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateMin

      public static ValidationResponse validateMin(Number value, String minValue)
      Check that the number value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Returns:
      validation response
    • checkMin

      public static void checkMin(Number value, String minValue)
      Check that the number value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Throws:
      ValidationException - if the validation fails
    • validateMax

      public static ValidationResponse validateMax(Number value, String maxValue)
      Check that the number value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Returns:
      validation response
    • checkMax

      public static void checkMax(Number value, String maxValue)
      Check that the number value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Throws:
      ValidationException - if the validation fails
    • validateDigits

      public static ValidationResponse validateDigits(Number value, int integerDigits, int fractionDigits)
      Check that the number value has the specified number of digits.
      Parameters:
      value - value to check
      integerDigits - maximum number of integer digits
      fractionDigits - maximum number of fraction digits
      Returns:
      validation response
    • checkDigits

      public static void checkDigits(Number value, int integerDigits, int fractionDigits)
      Check that the number value has the specified number of digits.
      Parameters:
      value - value to check
      integerDigits - maximum number of integer digits
      fractionDigits - maximum number of fraction digits
      Throws:
      ValidationException - if the validation fails
    • validateMin

      public static ValidationResponse validateMin(Integer value, int minValue)
      Check that the integer value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Returns:
      validation response
    • checkMin

      public static void checkMin(Integer value, int minValue)
      Check that the integer value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Throws:
      ValidationException - if the validation fails
    • validateMax

      public static ValidationResponse validateMax(Integer value, int maxValue)
      Check that the integer value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Returns:
      validation response
    • checkMax

      public static void checkMax(Integer value, int maxValue)
      Check that the integer value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Throws:
      ValidationException - if the validation fails
    • validateMin

      public static ValidationResponse validateMin(Long value, long minValue)
      Check that the long value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Returns:
      validation response
    • checkMin

      public static void checkMin(Long value, long minValue)
      Check that the long value is greater than or equal to the minimum value.
      Parameters:
      value - value to check
      minValue - minimum value
      Throws:
      ValidationException - if the validation fails
    • validateMax

      public static ValidationResponse validateMax(Long value, long maxValue)
      Check that the long value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Returns:
      validation response
    • checkMax

      public static void checkMax(Long value, long maxValue)
      Check that the long value is less than or equal to the maximum value.
      Parameters:
      value - value to check
      maxValue - maximum value
      Throws:
      ValidationException - if the validation fails
    • validateTrue

      public static ValidationResponse validateTrue(Boolean value)
      Check that the boolean value is true.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkTrue

      public static void checkTrue(Boolean value)
      Check that the boolean value is true.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateFalse

      public static ValidationResponse validateFalse(Boolean value)
      Check that the boolean value is false.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkFalse

      public static void checkFalse(Boolean value)
      Check that the boolean value is false.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateCalendarFuture

      public static ValidationResponse validateCalendarFuture(Object value)
      Check that the calendar value is in the future.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkCalendarFuture

      public static void checkCalendarFuture(Object value)
      Check that the calendar value is in the future.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateCalendarFutureOrPresent

      public static ValidationResponse validateCalendarFutureOrPresent(Object value)
      Check that the calendar value is in the future or present.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkCalendarFutureOrPresent

      public static void checkCalendarFutureOrPresent(Object value)
      Check that the calendar value is in the future or present.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateCalendarPast

      public static ValidationResponse validateCalendarPast(Object value)
      Check that the calendar value is in the past.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkCalendarPast

      public static void checkCalendarPast(Object value)
      Check that the calendar value is in the past.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateCalendarPastOrPresent

      public static ValidationResponse validateCalendarPastOrPresent(Object value)
      Check that the calendar value is in the past or present.
      Parameters:
      value - value to check
      Returns:
      validation response
    • checkCalendarPastOrPresent

      public static void checkCalendarPastOrPresent(Object value)
      Check that the calendar value is in the past or present.
      Parameters:
      value - value to check
      Throws:
      ValidationException - if the validation fails
    • validateCollectionSize

      public static ValidationResponse validateCollectionSize(Object value, int minSize, int maxSize)
      Check that the collection value has the specified size.
      Parameters:
      value - value to check
      minSize - minimum size (inclusive)
      maxSize - maximum size (inclusive)
      Returns:
      validation response
    • checkCollectionSize

      public static void checkCollectionSize(Object value, int minSize, int maxSize)
      Check that the collection value has the specified size.
      Parameters:
      value - value to check
      minSize - minimum size (inclusive)
      maxSize - maximum size (inclusive)
      Throws:
      ValidationException - if the validation fails