io.afu.validator.Implement.LimitedOnlyImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of validator Show documentation
Show all versions of validator Show documentation
RffanLAB Validator For Many Way use
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();
}
}