Package au.csiro.pathling.validation
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TensureValid(T bean, String message)Ensures that a bean annotated with JSR-380 constraints is valid.static voidfailValidation(Set<? extends javax.validation.ConstraintViolation<?>> constraintViolations, String messageTitle)Fails with theConstraintViolationExceptionthat includes the violated constraints and the human-readable representation of them.static StringformatViolations(Set<? extends javax.validation.ConstraintViolation<?>> constraintViolations)Formats a set ofConstraintViolationto a human-readable string.static <T> Set<javax.validation.ConstraintViolation<T>>validate(T bean)Validates a bean annotated with JSR-380 constraints using the default validation factory.
-
-
-
Method Detail
-
validate
@Nonnull public static <T> Set<javax.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 javax.validation.ConstraintViolationExceptionEnsures 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:
javax.validation.ConstraintViolationException- if any constraints are violated.
-
failValidation
public static void failValidation(@Nonnull Set<? extends javax.validation.ConstraintViolation<?>> constraintViolations, @Nullable String messageTitle) throws javax.validation.ConstraintViolationExceptionFails 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:
javax.validation.ConstraintViolationException
-
formatViolations
@Nonnull public static String formatViolations(@Nonnull Set<? extends javax.validation.ConstraintViolation<?>> constraintViolations)
Formats a set ofConstraintViolationto a human-readable string.- Parameters:
constraintViolations- the violations to include.- Returns:
- the human-readable representaion of the violations.
-
-