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

io.envoyproxy.pgv.Validator Maven / Gradle / Ivy

There is a newer version: 0.6.13
Show newest version
package io.envoyproxy.pgv;

/**
 * {@code Validator} asserts the validity of a protobuf object.
 * @param  The type to validate
 */
@FunctionalInterface
public interface Validator {
    /**
     * Asserts validation rules on a protobuf object.
     *
     * @param proto the protobuf object to validate.
     * @throws ValidationException with the first validation error encountered.
     */
    void assertValid(T proto) throws ValidationException;

    /**
     * Checks validation rules on a protobuf object.
     *
     * @param proto the protobuf object to validate.
     * @return {@code true} if all rules are valid, {@code false} if not.
     */
    default boolean isValid(T proto) {
        try {
            assertValid(proto);
            return true;
        } catch (io.envoyproxy.pgv.ValidationException ex) {
            return false;
        }
    }

    Validator ALWAYS_VALID = (proto) -> {
        // Do nothing. Always valid.
    };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy