io.envoyproxy.pgv.ValidatorIndex Maven / Gradle / Ivy
package io.envoyproxy.pgv;
/**
* {@code ValidatorIndex} defines the entry point for finding {@link Validator} instances for a given type.
*/
@FunctionalInterface
public interface ValidatorIndex {
/**
* Retuns the validator for {@code clazz}, or {@code ALWAYS_VALID} if not found.
*/
Validator validatorFor(Class clazz);
/**
* Retuns the validator for {@code }, or {@code ALWAYS_VALID} if not found.
*/
@SuppressWarnings("unchecked")
default Validator validatorFor(Object instance) {
return validatorFor(instance == null ? null : instance.getClass());
}
ValidatorIndex ALWAYS_VALID = new ValidatorIndex() {
@Override
@SuppressWarnings("unchecked")
public Validator validatorFor(Class clazz) {
return Validator.ALWAYS_VALID;
}
};
}