package com.shkj.wms.validator;

import com.shkj.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * 注解校验实现类
 *
 * @Author lch
 */
public class InArrValidator implements ConstraintValidator<InArrNoCheckBlank, String> {

    private String[] arr;

    @Override
    public void initialize(InArrNoCheckBlank constraintAnnotation) {
        arr = constraintAnnotation.arr();
    }


    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        //不校验为空的情况
        if (StringUtils.isBlank(value)) {
            return true;
        }
        return Arrays.asList(arr).contains(value);
    }

}
