it.cnr.iit.jscontact.tools.dto.utils.ConstraintViolationUtils Maven / Gradle / Ivy
package it.cnr.iit.jscontact.tools.dto.utils;
import javax.validation.ConstraintViolation;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Utility class for handling messages about constraint violations.
*
* @author Mario Loffredo
*/
public class ConstraintViolationUtils {
/**
* Returns a text message including all the constraint violations returned by a validation process and separated by newline.
*
* @param a generic type a constraint is set on
* @param constraintViolations the set of constraint violations
* @return the text message
*/
public static String getMessage(Set> constraintViolations) {
List messages = new ArrayList<>();
for(ConstraintViolation constraintViolation : constraintViolations)
messages.add(constraintViolation.getMessage());
return String.join(DelimiterUtils.NEWLINE_DELIMITER, messages);
}
}