com.github.egatlovs.variablemanager.validation.VariableValidator Maven / Gradle / Ivy
package com.github.egatlovs.variablemanager.validation;
import com.github.egatlovs.variablemanager.exceptions.ViolationException;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;
/**
* VariableValidator
*
* This class wraps the BeanValidation Feature in a single Method.
*
* @author egatlovs
*/
public class VariableValidator {
/**
* This method uses BeanValidation on the given Object. If no
* ConstraintViolation is present after validating the object the method just
* finishes. If a ConstraintViolation or more are returned the method throws a
* ViolationException with each validation failure in its message.
*
* @param value - The object to be validated
* @throws ViolationException
*/
public static void validate(Object value) {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set> constraintViolations = validator.validate(value);
if (!constraintViolations.isEmpty()) {
throw new ViolationException(new ConstraintViolationMessage(constraintViolations));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy