Class Check

java.lang.Object
org.apache.hadoop.lib.util.Check

@Private public class Check extends Object
Utility methods to check preconditions.

Commonly used for method arguments preconditions.

  • Constructor Details

    • Check

      public Check()
  • Method Details

    • notNull

      public static <T> T notNull(T obj, String name)
      Verifies a variable is not NULL.
      Parameters:
      obj - the variable to check.
      name - the name to use in the exception message.
      Returns:
      the variable.
      Throws:
      IllegalArgumentException - if the variable is NULL.
    • notNullElements

      public static <T> List<T> notNullElements(List<T> list, String name)
      Verifies a list does not have any NULL elements.
      Parameters:
      list - the list to check.
      name - the name to use in the exception message.
      Returns:
      the list.
      Throws:
      IllegalArgumentException - if the list has NULL elements.
    • notEmpty

      public static String notEmpty(String str, String name)
      Verifies a string is not NULL and not emtpy
      Parameters:
      str - the variable to check.
      name - the name to use in the exception message.
      Returns:
      the variable.
      Throws:
      IllegalArgumentException - if the variable is NULL or empty.
    • notEmptyElements

      public static List<String> notEmptyElements(List<String> list, String name)
      Verifies a string list is not NULL and not emtpy
      Parameters:
      list - the list to check.
      name - the name to use in the exception message.
      Returns:
      the variable.
      Throws:
      IllegalArgumentException - if the string list has NULL or empty elements.
    • validIdentifier

      public static String validIdentifier(String value, int maxLen, String name)
      Verifies a value is a valid identifier, [a-zA-Z_][a-zA-Z0-9_\-]*, up to a maximum length.
      Parameters:
      value - string to check if it is a valid identifier.
      maxLen - maximun length.
      name - the name to use in the exception message.
      Returns:
      the value.
      Throws:
      IllegalArgumentException - if the string is not a valid identifier.
    • gt0

      public static int gt0(int value, String name)
      Verifies an integer is greater than zero.
      Parameters:
      value - integer value.
      name - the name to use in the exception message.
      Returns:
      the value.
      Throws:
      IllegalArgumentException - if the integer is zero or less.
    • gt0

      public static long gt0(long value, String name)
      Verifies an long is greater than zero.
      Parameters:
      value - long value.
      name - the name to use in the exception message.
      Returns:
      the value.
      Throws:
      IllegalArgumentException - if the long is zero or less.
    • ge0

      public static int ge0(int value, String name)
      Verifies an integer is greater or equal to zero.
      Parameters:
      value - integer value.
      name - the name to use in the exception message.
      Returns:
      the value.
      Throws:
      IllegalArgumentException - if the integer is greater or equal to zero.
    • ge0

      public static long ge0(long value, String name)
      Verifies an long is greater or equal to zero.
      Parameters:
      value - integer value.
      name - the name to use in the exception message.
      Returns:
      the value.
      Throws:
      IllegalArgumentException - if the long is greater or equal to zero.