Class PreConditions

java.lang.Object
com.thebuzzmedia.exiftool.commons.lang.PreConditions

public final class PreConditions extends Object
Static PreConditions Utilities.
  • Method Details

    • notBlank

      public static String notBlank(String val, String message)
      Ensures that a string is:
      • Not null.
      • Not empty.
      • Not blank (i.e contains at least one character other than space).
      Parameters:
      val - Value to check.
      message - Message passed to thrown exception.
      Returns:
      Original value if it is not null.
      Throws:
      NullPointerException - If val is null.
      IllegalArgumentException - If val is empty or blank.
    • notEmpty

      public static <T> T[] notEmpty(T[] val, String message)
      Ensures that array is:
      • Not null.
      • Not empty.
      Type Parameters:
      T - Type of elements in array.
      Parameters:
      val - Value to check.
      message - Message passed to thrown exception.
      Returns:
      Original value if it is not empty.
      Throws:
      NullPointerException - If val is null.
      IllegalArgumentException - If val is empty.
    • notEmpty

      public static <T, U> Map<T,U> notEmpty(Map<T,U> val, String message)
      Ensures that map is:
      • Not null.
      • Not empty.
      Type Parameters:
      T - Type of keys in map.
      U - Type of values in map.
      Parameters:
      val - Value to check.
      message - Message passed to thrown exception.
      Returns:
      Original value if it is not empty.
      Throws:
      NullPointerException - If val is null.
      IllegalArgumentException - If val is empty.
    • notEmpty

      public static <T> Iterable<T> notEmpty(Iterable<T> val, String message)
      Ensures that iterable element is:
      • Not null.
      • Not empty.
      Type Parameters:
      T - Type of elements in iterable structure.
      Parameters:
      val - Value to check.
      message - Message passed to thrown exception.
      Returns:
      Original value if it is not empty.
      Throws:
      NullPointerException - If val is null.
      IllegalArgumentException - If val is empty.
    • isPositive

      public static <T extends Number> T isPositive(T nb, String message)
      Check if given number is strictly positive (strictly greater than zero).
      Type Parameters:
      T - Type of number.
      Parameters:
      nb - Number.
      message - Error message.
      Returns:
      Original number.
      Throws:
      NullPointerException - If nb is null.
      IllegalArgumentException - If nb is less than or equal to zero.
    • isReadable

      public static File isReadable(File file, String message)
      Check that a given file exist and is readable.
      Parameters:
      file - File to check.
      message - Error message.
      Returns:
      Original file.
      Throws:
      NullPointerException - If file is null.
      UnreadableFileException - If file does not exist.
      UnreadableFileException - If file cannot be read.
    • isWritable

      public static File isWritable(File file, String message)
      Check that a given file exist and is writable.
      Parameters:
      file - File to check.
      message - Error message.
      Returns:
      Original file.
      Throws:
      NullPointerException - If file is null.
      UnreadableFileException - If file does not exist.
      UnreadableFileException - If file cannot be updated.