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

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

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

import java.util.Arrays;

/**
 * {@code CollectiveValidation} implements PGV validators for the collective {@code in} and {@code notIn} rules.
 */
public final class CollectiveValidation {
    private CollectiveValidation() {
    }

    public static  void in(String field, T value, T[] set) throws ValidationException {
        for (T i : set) {
            if (value.equals(i)) {
                return;
            }
        }

        throw new ValidationException(field, value, "must be in " + Arrays.toString(set));
    }

    public static  void notIn(String field, T value, T[] set) throws ValidationException {
        for (T i : set) {
            if (value.equals(i)) {
                throw new ValidationException(field, value, "must not be in " + Arrays.toString(set));
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy