Class NumberValidator<T extends Number & Comparable<T>>

java.lang.Object
org.moeaframework.util.validate.Validator<T>
org.moeaframework.util.validate.NumberValidator<T>
Type Parameters:
T - the number type
Direct Known Subclasses:
DoubleValidator, IntegerValidator

public abstract class NumberValidator<T extends Number & Comparable<T>> extends Validator<T>
Abstract validator for Numbers.

To simplify the implementation of these validations, we use the fact that most numeric types implement the Comparable interface. Consequently, this class only supports the "boxed" types for numbers, while most parameters we are validating are primitives. Thus, prefer creating subclasses that accept only the primitive type, which then call these generic methods.

  • Constructor Details

    • NumberValidator

      public NumberValidator(String propertyName, T propertyValue)
      Constructs a new number validator.
      Parameters:
      propertyName - the property name
      propertyValue - the property value
  • Method Details

    • failsOnCondition

      protected final void failsOnCondition(String condition)
      Throws an exception indicating the specified condition failed.
      Parameters:
      condition - a description of the condition that failed
    • failsOnCondition

      protected final void failsOnCondition(String condition, String thresholdName, T thresholdValue)
      Throws an exception indicating the specified condition failed along with threshold value that was violated.
      Parameters:
      condition - a description of the condition that failed
      thresholdName - the threshold name, or null if not associated with a named parameter
      thresholdValue - the threshold value
    • isGreaterThan

      protected final void isGreaterThan(String thresholdName, T thresholdValue)
      Asserts the value is greater than some threshold.
      Parameters:
      thresholdName - the threshold name, or null if not associated with a named parameter
      thresholdValue - the threshold value
    • isGreaterThanOrEqualTo

      protected final void isGreaterThanOrEqualTo(String thresholdName, T thresholdValue)
      Asserts the value is greater than or equal to some threshold.
      Parameters:
      thresholdName - the threshold name, or null if not associated with a named parameter
      thresholdValue - the threshold value
    • isLessThan

      protected final void isLessThan(String thresholdName, T thresholdValue)
      Asserts the value is less than some threshold.
      Parameters:
      thresholdName - the threshold name, or null if not associated with a named parameter
      thresholdValue - the threshold value
    • isLessThanOrEqualTo

      protected final void isLessThanOrEqualTo(String thresholdName, T thresholdValue)
      Asserts the value is less than or equal to some threshold.
      Parameters:
      thresholdName - the threshold name, or null if not associated with a named parameter
      thresholdValue - the threshold value
    • isEqualTo

      protected final void isEqualTo(String parameterName, T parameterValue)
      Asserts the value equals some other parameter.
      Parameters:
      parameterName - the parameter name, or null if not associated with a named parameter
      parameterValue - the parameter value
    • isNotEqualTo

      protected final void isNotEqualTo(String parameterName, T parameterValue)
      Asserts the value is not equal to some other parameter.
      Parameters:
      parameterName - the parameter name, or null if not associated with a named parameter
      parameterValue - the parameter value
    • isBetween

      protected final void isBetween(T lower, T upper)
      Asserts the value is between the given lower and upper bounds, inclusive.
      Parameters:
      lower - the lower bound
      upper - the upper bound