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

io.afu.validator.Implement.LimitedOnlyImpl Maven / Gradle / Ivy

There is a newer version: 2.4-RELEASE
Show newest version
package io.afu.validator.Implement;

import io.afu.validator.Annimation.ChineseWord;
import io.afu.validator.Annimation.LimitedOnly;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class LimitedOnlyImpl implements ConstraintValidator {

    private String[] strs;

    private Boolean allowEmpty;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (null == s || s.equals("")){
            return this.allowEmpty;
        }else {
            for (String str:this.strs){
                if (s.equals(str)){
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public void initialize(LimitedOnly constraintAnnotation) {
        this.strs = constraintAnnotation.limit();
        this.allowEmpty = constraintAnnotation.allowEmpty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy