// Path: cango-common/src/main/java/com/bella/cango/exception/CangoException.java
// public class CangoException extends RuntimeException {
//     public CangoException() {
//         super();
//     }
// 
//     public CangoException(String message) {
//         super(message);
//     }
// 
//     public CangoException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public CangoException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected CangoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


import com.bella.cango.exception.CangoException;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;
package com.bella.cango.utils;



/**
 * TODO
 *
 * @author kevin
 * @date 2016/9/24
 */
public class ValidateUtil {
    private static Validator validator;
    static {
        final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        validator = validatorFactory.getValidator();
    }
    public static <T> void validate(T t) {
        final Set<ConstraintViolation<T>> constraintViolations = validator.validate(t);
        if (constraintViolations != null && constraintViolations.size() > 0) {
            StringBuilder stringBuilder = new StringBuilder();
            for (ConstraintViolation<T> constraintViolation : constraintViolations) {
                stringBuilder.append(constraintViolation.getPropertyPath())
                        .append(" : ")
                        .append(constraintViolation.getMessage())
                        .append(", ");
            }
            String constraintMessage = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
// Path: cango-common/src/main/java/com/bella/cango/exception/CangoException.java
// public class CangoException extends RuntimeException {
//     public CangoException() {
//         super();
//     }
// 
//     public CangoException(String message) {
//         super(message);
//     }
// 
//     public CangoException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public CangoException(Throwable cause) {
//         super(cause);
//     }
// 
//     protected CangoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }


// Path: cango-common/src/main/java/com/bella/cango/utils/ValidateUtil.java
import com.bella.cango.exception.CangoException;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

package com.bella.cango.utils;



/**
 * TODO
 *
 * @author kevin
 * @date 2016/9/24
 */
public class ValidateUtil {
    private static Validator validator;
    static {
        final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
        validator = validatorFactory.getValidator();
    }
    public static <T> void validate(T t) {
        final Set<ConstraintViolation<T>> constraintViolations = validator.validate(t);
        if (constraintViolations != null && constraintViolations.size() > 0) {
            StringBuilder stringBuilder = new StringBuilder();
            for (ConstraintViolation<T> constraintViolation : constraintViolations) {
                stringBuilder.append(constraintViolation.getPropertyPath())
                        .append(" : ")
                        .append(constraintViolation.getMessage())
                        .append(", ");
            }
            String constraintMessage = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
            throw new CangoException(constraintMessage);