Class Validate

java.lang.Object
org.moeaframework.util.validate.Validate

public final class Validate extends Object
Static methods for creating validators of parameters, arguments, or inputs. Each method produces a validator for a specific type. Additionally, when creating the validator, the name of the parameter, argument, or input is given along with the value, which is used to format the error message.

All validators throw IllegalArgumentExceptions if the conditions fail, though they may also throw NullPointerException for unexpected null values.

  • Method Details

    • that

      public static final DoubleValidator that(String name, double value)
      Constructs a validator for a double value.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the validator
    • that

      public static final IntegerValidator that(String name, int value)
      Constructs a validator for an integer value.
      Parameters:
      name - the parameter name
      value - the parameter value
      Returns:
      the validator
    • that

      public static final ProblemValidator that(String name, Problem problem)
      Constructs a validator for a Problem.
      Parameters:
      name - the parameter name
      problem - the problem
      Returns:
      the validator
    • that

      public static final <T> ObjectValidator<T> that(String name, T value)
      Constructs a validator for any generic object.
      Type Parameters:
      T - the type of the object
      Parameters:
      name - the parameter name
      value - the object
      Returns:
      the validator
    • fail

      public static final <R> R fail(String message)
      Always fails with the given message.
      Type Parameters:
      R - the return type
      Parameters:
      message - the reason for the failure
      Returns:
      this method never returns