Class Validate

java.lang.Object
com.agentforge4j.util.Validate

public final class Validate extends Object
Provides static methods for validating arguments and paths.
  • Method Details

    • notBlank

      @NonNull public static String notBlank(String value, String message)
      Validates that the given string is not blank.
      Parameters:
      value - the string to validate
      message - the exception message if validation fails
      Returns:
      the validated string; never null
      Throws:
      IllegalArgumentException - if the string is blank
    • notBlank

      @NonNull public static String notBlank(String value, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given string is not blank.
      Parameters:
      value - the string to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated string; never null
    • notNull

      @NonNull public static <T> T notNull(T value, String message)
      Validates that the given value is not null.
      Parameters:
      value - the value to validate
      message - the exception message if validation fails
      Returns:
      the validated value; never null
      Throws:
      IllegalArgumentException - if the value is null
    • notNull

      @NonNull public static <T> T notNull(T value, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given value is not null.
      Parameters:
      value - the value to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated value; never null
    • isTrue

      public static void isTrue(boolean condition, String message)
      Validates that the given condition is true.
      Parameters:
      condition - the condition to validate
      message - the exception message if validation fails
      Throws:
      IllegalArgumentException - if the condition is false
    • isTrue

      public static void isTrue(boolean condition, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given condition is true.
      Parameters:
      condition - the condition to validate
      exceptionSupplier - supplies the exception to throw if validation fails
    • notEmpty

      @NonNull public static <T extends Collection<?>> T notEmpty(T collection, String message)
      Validates that the given collection is not empty.
      Parameters:
      collection - the collection to validate
      message - the exception message if validation fails
      Returns:
      the validated collection; never null
      Throws:
      IllegalArgumentException - if the collection is null or empty
    • notEmpty

      @NonNull public static <T extends Collection<?>> T notEmpty(T collection, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given collection is not empty.
      Parameters:
      collection - the collection to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated collection; never null
    • requireWithinBase

      public static Path requireWithinBase(Path base, String relativePath, String message)
      Validates that the resolved path stays within the base directory.
      Parameters:
      base - the absolute base directory path
      relativePath - the relative path to resolve
      message - the exception message if validation fails
      Returns:
      the resolved and validated absolute path
      Throws:
      IllegalArgumentException - if the base is not absolute, or the resolved path is outside the base
    • requireWithinBase

      public static Path requireWithinBase(Path base, String relativePath, Supplier<RuntimeException> exceptionSupplier)
      Validates that the resolved path stays within the base directory.
      Parameters:
      base - the absolute base directory path
      relativePath - the relative path to resolve
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the resolved and validated absolute path
    • requireDirectory

      public static Path requireDirectory(Path path, String message)
      Validates that the given path is a directory.
      Parameters:
      path - the path to validate
      message - the exception message if validation fails
      Returns:
      the validated directory path
      Throws:
      IllegalArgumentException - if the path is not a directory
    • requireDirectory

      public static Path requireDirectory(Path path, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given path is a directory.
      Parameters:
      path - the path to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated directory path
    • isBetween

      public static Number isBetween(Number lower, Number upper, Number value, String message)
      Validates that the given value is between the specified bounds.
      Parameters:
      lower - the lower bound (inclusive)
      upper - the upper bound (inclusive)
      value - the value to validate
      message - the exception message if validation fails
      Throws:
      IllegalArgumentException - if the value is outside the bounds
    • isBetween

      public static Number isBetween(Number lower, Number upper, Number value, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given value is between the specified bounds.
      Parameters:
      lower - the lower bound (inclusive)
      upper - the upper bound (inclusive)
      value - the value to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Throws:
      IllegalArgumentException - if the value is outside the bounds
    • isGreaterThanZero

      public static Number isGreaterThanZero(Number value, String message)
      Validates that the given value is greater than zero.
      Parameters:
      value - the value to validate
      message - the exception message if validation fails
      Returns:
      the validated value
      Throws:
      IllegalArgumentException - if the value is not greater than zero
    • isGreaterThanZero

      public static Number isGreaterThanZero(Number value, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given value is greater than zero.
      Parameters:
      value - the value to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated value
    • isNotNegative

      public static Number isNotNegative(Number value, String message)
      Validates that the given value is not negative.
      Parameters:
      value - the value to validate
      message - the exception message if validation fails
      Returns:
      the validated value
      Throws:
      IllegalArgumentException - if the value is negative
    • isNotNegative

      public static Number isNotNegative(Number value, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given value is not negative.
      Parameters:
      value - the value to validate
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated value
    • isGreaterThan

      public static Number isGreaterThan(Number value, Number lower, String message)
      Validates that the given value is greater than the specified lower bound.
      Parameters:
      value - the value to validate
      lower - the lower bound (exclusive)
      message - the exception message if validation fails
      Returns:
      the validated value
      Throws:
      IllegalArgumentException - if the value is not greater than the lower bound
    • isGreaterThan

      public static Number isGreaterThan(Number value, Number lower, Supplier<RuntimeException> exceptionSupplier)
      Validates that the given value is greater than the specified lower bound.
      Parameters:
      value - the value to validate
      lower - the lower bound (exclusive)
      exceptionSupplier - supplies the exception to throw if validation fails
      Returns:
      the validated value