Class ParamChecks

java.lang.Object
opennlp.tools.util.ParamChecks

@Internal public final class ParamChecks extends Object
Argument checks that report an invalid parameter with an IllegalArgumentException naming that parameter.

Note: Do not use this class, internal use only!

Since:
3.0.0
  • Method Details

    • requireNonNullArg

      public static <T> T requireNonNullArg(T value, String name)
      Returns value if it is not null.

      The message of a thrown exception is "<name> must not be null".

      Type Parameters:
      T - The argument type.
      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never null.
      Throws:
      IllegalArgumentException - Thrown if value is null.
    • requireNonEmpty

      public static <T extends CharSequence> T requireNonEmpty(T value, String name)
      Returns value if it is neither null nor empty.

      The message of a thrown exception is "<name> must not be null or empty".

      Type Parameters:
      T - The argument type.
      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never null or empty.
      Throws:
      IllegalArgumentException - Thrown if value is null or has a length of zero.
    • requireNonEmpty

      public static <T extends Collection<?>> T requireNonEmpty(T value, String name)
      Returns value if it is neither null nor empty.

      The message of a thrown exception is "<name> must not be null or empty".

      Type Parameters:
      T - The argument type.
      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never null or empty.
      Throws:
      IllegalArgumentException - Thrown if value is null or contains no elements.
    • requireNonBlank

      public static String requireNonBlank(String value, String name)
      Returns value if it is neither null nor blank.

      A string is blank if it is empty or contains only Unicode White_Space code points, as defined by StringUtil.isUnicodeBlank(CharSequence). The message of a thrown exception is "<name> must not be null or blank".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never null or blank.
      Throws:
      IllegalArgumentException - Thrown if value is null or blank.
    • requireNonNegative

      public static int requireNonNegative(int value, String name)
      Returns value if it is not negative.

      The message of a thrown exception is "<name> must not be negative".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never negative.
      Throws:
      IllegalArgumentException - Thrown if value is less than zero.
    • requireNonNegative

      public static long requireNonNegative(long value, String name)
      Returns value if it is not negative.

      The message of a thrown exception is "<name> must not be negative".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never negative.
      Throws:
      IllegalArgumentException - Thrown if value is less than zero.
    • requireNonNegative

      public static double requireNonNegative(double value, String name)
      Returns value if it is not negative.

      NaN is not less than zero and is returned unchanged, so check it with requireFinite(double, String) first where it is not allowed. The message of a thrown exception is "<name> must not be negative".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never negative.
      Throws:
      IllegalArgumentException - Thrown if value is less than zero.
    • requirePositive

      public static int requirePositive(int value, String name)
      Returns value if it is greater than zero.

      The message of a thrown exception is "<name> must be positive".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, always greater than zero.
      Throws:
      IllegalArgumentException - Thrown if value is zero or negative.
    • requirePositive

      public static double requirePositive(double value, String name)
      Returns value if it is greater than zero. Positive infinity passes; call requireFinite(double, String) first where it is not allowed. The message of a thrown exception is "<name> must be positive".
      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, always greater than zero.
      Throws:
      IllegalArgumentException - Thrown if value is zero, negative, or NaN.
    • requireFinite

      public static double requireFinite(double value, String name)
      Returns value if it is finite.

      The message of a thrown exception is "<name> must be finite".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, never NaN or infinite.
      Throws:
      IllegalArgumentException - Thrown if value is NaN or infinite.
    • requirePositiveFraction

      public static double requirePositiveFraction(double value, String name)
      Returns value if it is in (0, 1].

      The message of a thrown exception is "<name> must be in (0, 1]".

      Parameters:
      value - The argument to check.
      name - The parameter name used in the exception message.
      Returns:
      value, always in (0, 1].
      Throws:
      IllegalArgumentException - Thrown if value is not in (0, 1], including NaN.
    • requireNonEmptyParallelArrays

      public static void requireNonEmptyParallelArrays(Object[] first, String firstName, Object[] second, String secondName)
      Checks two arrays that hold corresponding values. Both arrays must be non-empty, have the same length, and contain no null entries.
      Parameters:
      first - The first array to check.
      firstName - The first parameter name used in exception messages.
      second - The second array to check.
      secondName - The second parameter name used in exception messages.
      Throws:
      IllegalArgumentException - Thrown if either array is null or empty, their lengths differ, or an entry is null.