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

org.chobit.commons.validation.StringCollValidator Maven / Gradle / Ivy

There is a newer version: 0.1.3.4
Show newest version
package org.chobit.commons.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.chobit.commons.funcs.Checker;

import java.util.Collection;

/**
 * 字符串集合检查校验
 *
 * @author robin
 */
public class StringCollValidator implements ConstraintValidator> {


    private Checker checker;

    @Override
    public void initialize(StringColl anno) {
        Class> checkerClass = anno.checker();
        try {
            this.checker = checkerClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public boolean isValid(Collection coll, ConstraintValidatorContext context) {
        if (null == coll || coll.isEmpty()) {
            return true;
        }

        for (String s : coll) {
            boolean r = this.checker.check(s);
            if (!r) {
                return false;
            }
        }

        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy