Package utility

Class Validation

java.lang.Object
utility.Validation

public final class Validation extends Object
Utility class for performing various validation checks.

This class provides static methods to validate strings and file objects. It includes methods to check if a string represents a percentage or a positive double, and methods to validate file and directory objects.

  • Constructor Details

    • Validation

      public Validation()
  • Method Details

    • isPercentage

      public static Boolean isPercentage(String s)
      Checks if a String represents a percentage value.

      This method attempts to parse the input string as a double and checks if the value lies within the range [0.0, 1.0], inclusive. If the parsing fails or the value is out of range, the method returns false.

      Parameters:
      s - The String to validate as a percentage.
      Returns:
      true if the string represents a valid percentage, false otherwise.
    • isPositiveDouble

      public static Boolean isPositiveDouble(String s)
      Checks if a String represents a positive double value.

      This method attempts to parse the input string as a double and checks if the value is greater than 0.0. If the parsing fails or the value is not positive, the method returns false.

      Parameters:
      s - The String to validate as a positive double.
      Returns:
      true if the string represents a positive double, false otherwise.
    • checkFile

      public static void checkFile(File file) throws IOException
      Checks the validity of a File object.

      This method validates the given File object by ensuring it:

      • Represents a file (not a directory).
      • Exists in the file system.
      • Can be read by the application.
      • Is not empty.
      Parameters:
      file - The File object to validate.
      Throws:
      IOException - If the file is not valid; i.e., one of the conditions is not met.
    • checkDirectory

      public static void checkDirectory(File directory) throws IOException
      Checks if a File object exists, is a directory, and can be read.

      This method validates the given File object by ensuring it:

      • Represents a directory (not a file).
      • Exists in the file system.
      • Can be read by the application.
      Parameters:
      directory - The File object to validate.
      Throws:
      IOException - If the file is not valid; i.e., one of the conditions is not met.