Class ValidationUtils

java.lang.Object
au.csiro.pathling.validation.ValidationUtils

public final class ValidationUtils extends Object
Utility classes to facilitate JRS-380 based validation
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    ensureValid(T bean, String message)
    Ensures that a bean annotated with JSR-380 constraints is valid.
    static void
    failValidation(Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations, String messageTitle)
    Fails with the ConstraintViolationException that includes the violated constraints and the human-readable representation of them.
    static String
    formatViolations(Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations)
    Formats a set of ConstraintViolation to a human-readable string.
    static <T> Set<jakarta.validation.ConstraintViolation<T>>
    validate(T bean)
    Validates a bean annotated with JSR-380 constraints using the default validation factory.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • validate

      @Nonnull public static <T> Set<jakarta.validation.ConstraintViolation<T>> validate(@Nonnull T bean)
      Validates a bean annotated with JSR-380 constraints using the default validation factory.
      Type Parameters:
      T - the type of the bean.
      Parameters:
      bean - the bean to validate
      Returns:
      the set of violated constrains, empty if the bean is valid.
    • ensureValid

      @Nonnull public static <T> T ensureValid(@Nonnull T bean, @Nonnull String message) throws jakarta.validation.ConstraintViolationException
      Ensures that a bean annotated with JSR-380 constraints is valid. If validation with the default validation factory results in any violation throws the ConstraintViolationException.
      Type Parameters:
      T - the type of the bean.
      Parameters:
      bean - the bean to validate
      message - the message to use as the title of the exception message.
      Returns:
      the valid bean.
      Throws:
      jakarta.validation.ConstraintViolationException - if any constraints are violated.
    • failValidation

      public static void failValidation(@Nonnull Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations, @Nullable String messageTitle) throws jakarta.validation.ConstraintViolationException
      Fails with the ConstraintViolationException that includes the violated constraints and the human-readable representation of them.
      Parameters:
      constraintViolations - the violation to include in the exception.
      messageTitle - the title of the error message.
      Throws:
      jakarta.validation.ConstraintViolationException
    • formatViolations

      @Nonnull public static String formatViolations(@Nonnull Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations)
      Formats a set of ConstraintViolation to a human-readable string.
      Parameters:
      constraintViolations - the violations to include
      Returns:
      the human-readable representation of the violations