All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.groupbyinc.common.util.ValidatorUtil Maven / Gradle / Ivy

There is a newer version: 198
Show newest version
package com.groupbyinc.common.util;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.List;
import java.util.Set;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;

/**
 * ValidatorUtil
 *
 * @author Amir Behnam
 */
public class ValidatorUtil {

  public static  List validate(Validator validator, T object) {
    if (object != null) {
      Set> errors = validator.validate(object);
      if (errors != null) {
        return errors.stream().map(ConstraintViolation::getMessage).collect(toList());
      } else {
        return emptyList();
      }
    } else {
      return emptyList();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy