java.lang.Object
com.agentforge4j.util.Validate
Provides static methods for validating arguments and paths.
-
Method Summary
Modifier and TypeMethodDescriptionstatic NumberValidates that the given value is between the specified bounds.static NumberValidates that the given value is between the specified bounds.static NumberisGreaterThan(Number value, Number lower, String message) Validates that the given value is greater than the specified lower bound.static NumberisGreaterThan(Number value, Number lower, Supplier<RuntimeException> exceptionSupplier) Validates that the given value is greater than the specified lower bound.static NumberisGreaterThanZero(Number value, String message) Validates that the given value is greater than zero.static NumberisGreaterThanZero(Number value, Supplier<RuntimeException> exceptionSupplier) Validates that the given value is greater than zero.static NumberisNotNegative(Number value, String message) Validates that the given value is not negative.static NumberisNotNegative(Number value, Supplier<RuntimeException> exceptionSupplier) Validates that the given value is not negative.static voidValidates that the given condition is true.static voidisTrue(boolean condition, Supplier<RuntimeException> exceptionSupplier) Validates that the given condition is true.static StringValidates that the given string is not blank.static StringnotBlank(String value, Supplier<RuntimeException> exceptionSupplier) Validates that the given string is not blank.static <T extends Collection<?>>
TValidates that the given collection is not empty.static <T extends Collection<?>>
TnotEmpty(T collection, Supplier<RuntimeException> exceptionSupplier) Validates that the given collection is not empty.static <T> TValidates that the given value is not null.static <T> TnotNull(T value, Supplier<RuntimeException> exceptionSupplier) Validates that the given value is not null.static PathrequireDirectory(Path path, String message) Validates that the given path is a directory.static PathrequireDirectory(Path path, Supplier<RuntimeException> exceptionSupplier) Validates that the given path is a directory.static PathrequireWithinBase(Path base, String relativePath, String message) Validates that the resolved path stays within the base directory.static PathrequireWithinBase(Path base, String relativePath, Supplier<RuntimeException> exceptionSupplier) Validates that the resolved path stays within the base directory.
-
Method Details
-
notBlank
Validates that the given string is not blank.- Parameters:
value- the string to validatemessage- the exception message if validation fails- Returns:
- the validated string; never
null - Throws:
IllegalArgumentException- if the string is blank
-
notBlank
Validates that the given string is not blank.- Parameters:
value- the string to validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated string; never
null
-
notNull
Validates that the given value is not null.- Parameters:
value- the value to validatemessage- the exception message if validation fails- Returns:
- the validated value; never
null - Throws:
IllegalArgumentException- if the value is null
-
notNull
Validates that the given value is not null.- Parameters:
value- the value to validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated value; never
null
-
isTrue
Validates that the given condition is true.- Parameters:
condition- the condition to validatemessage- the exception message if validation fails- Throws:
IllegalArgumentException- if the condition is false
-
isTrue
Validates that the given condition is true.- Parameters:
condition- the condition to validateexceptionSupplier- supplies the exception to throw if validation fails
-
notEmpty
Validates that the given collection is not empty.- Parameters:
collection- the collection to validatemessage- 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 validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated collection; never
null
-
requireWithinBase
Validates that the resolved path stays within the base directory.- Parameters:
base- the absolute base directory pathrelativePath- the relative path to resolvemessage- 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 pathrelativePath- the relative path to resolveexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the resolved and validated absolute path
-
requireDirectory
Validates that the given path is a directory.- Parameters:
path- the path to validatemessage- the exception message if validation fails- Returns:
- the validated directory path
- Throws:
IllegalArgumentException- if the path is not a directory
-
requireDirectory
Validates that the given path is a directory.- Parameters:
path- the path to validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated directory path
-
isBetween
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 validatemessage- 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 validateexceptionSupplier- supplies the exception to throw if validation fails- Throws:
IllegalArgumentException- if the value is outside the bounds
-
isGreaterThanZero
Validates that the given value is greater than zero.- Parameters:
value- the value to validatemessage- the exception message if validation fails- Returns:
- the validated value
- Throws:
IllegalArgumentException- if the value is not greater than zero
-
isGreaterThanZero
Validates that the given value is greater than zero.- Parameters:
value- the value to validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated value
-
isNotNegative
Validates that the given value is not negative.- Parameters:
value- the value to validatemessage- the exception message if validation fails- Returns:
- the validated value
- Throws:
IllegalArgumentException- if the value is negative
-
isNotNegative
Validates that the given value is not negative.- Parameters:
value- the value to validateexceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated value
-
isGreaterThan
Validates that the given value is greater than the specified lower bound.- Parameters:
value- the value to validatelower- 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 validatelower- the lower bound (exclusive)exceptionSupplier- supplies the exception to throw if validation fails- Returns:
- the validated value
-