package me.chyxion.tigon.validation.validator;

import javax.validation.ConstraintValidator;
import org.apache.commons.lang3.StringUtils;
import javax.validation.ConstraintValidatorContext;
import me.chyxion.tigon.validation.annotation.NotNullOrBlank;

/**
 * @author Shaun Chyxion <br>
 * chyxion@163.com <br>
 * Feb 22, 2017 15:22:58
 */
public class NotNullOrBlankValidator implements ConstraintValidator<NotNullOrBlank, Object> {

    @Override
    public void initialize(NotNullOrBlank constraintAnnotation) {

    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return (value instanceof String) && StringUtils.isNotBlank((String) value) ||
            (value != null && !(value instanceof String));
    }
}
