Class Preconditions

java.lang.Object
com.ongres.scram.common.util.Preconditions

public final class Preconditions extends Object
Generic utility methods used to validate data.
  • Constructor Details

    • Preconditions

      private Preconditions()
  • Method Details

    • checkNotNull

      public static <T> T checkNotNull(T value, String valueName)
      Checks that the argument is not null.
      Type Parameters:
      T - The type of the value
      Parameters:
      value - The value to be checked
      valueName - The name of the value that is checked in the method
      Returns:
      The same value passed as argument
      Throws:
      IllegalArgumentException - If value is null.
    • castNonNull

      public static <T> T castNonNull(T ref)
    • checkNotEmpty

      public static String checkNotEmpty(String value, String valueName)
      Checks that the String is not null and not empty.
      Parameters:
      value - The String to check
      valueName - The name of the value that is checked in the method
      Returns:
      The same String passed as argument
      Throws:
      IllegalArgumentException - If value is null or empty
    • checkNotEmpty

      public static char[] checkNotEmpty(char[] value, String valueName)
      Checks that the char[] is not null and not empty.
      Parameters:
      value - The String to check
      valueName - The name of the value that is checked in the method
      Returns:
      The same String passed as argument
      Throws:
      IllegalArgumentException - If value is null or empty
    • checkArgument

      public static void checkArgument(boolean check, String valueName)
      Checks that the argument is valid, based in a check boolean condition.
      Parameters:
      check - The boolean check
      valueName - The name of the value that is checked in the method
      Throws:
      IllegalArgumentException - if check is not valid
    • checkArgument

      public static void checkArgument(boolean check, String valueName, String errMsg)
      Checks that the argument is valid, based in a check boolean condition.
      Parameters:
      check - The boolean check
      valueName - The name of the value that is checked in the method
      errMsg - Detail of the error message
      Throws:
      IllegalArgumentException - if check is not valid
    • gt0

      public static int gt0(int value, String valueName)
      Checks that the integer argument is positive.
      Parameters:
      value - The value to be checked
      valueName - The name of the value that is checked in the method
      Returns:
      The same value passed as argument
      Throws:
      IllegalArgumentException - If value is equal or less than 0
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String string)
      Returns true if the given string is null or is the empty string.
      Parameters:
      string - a String reference to check
      Returns:
      true if the string is null or the string is empty