Package au.csiro.pathling.validation
Class ValidationUtils
java.lang.Object
au.csiro.pathling.validation.ValidationUtils
Utility classes to facilitate JRS-380 based validation
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TensureValid(T bean, String message) Ensures that a bean annotated with JSR-380 constraints is valid.static voidfailValidation(Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations, String messageTitle) Fails with theConstraintViolationExceptionthat includes the violated constraints and the human-readable representation of them.static StringformatViolations(Set<? extends jakarta.validation.ConstraintViolation<?>> constraintViolations) Formats a set ofConstraintViolationto 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.
-
Method Details
-
validate
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 theConstraintViolationException.- Type Parameters:
T- the type of the bean.- Parameters:
bean- the bean to validatemessage- 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 theConstraintViolationExceptionthat 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 ofConstraintViolationto a human-readable string.- Parameters:
constraintViolations- the violations to include- Returns:
- the human-readable representation of the violations
-