Package dev.langchain4j.internal
Class ValidationUtils
java.lang.Object
dev.langchain4j.internal.ValidationUtils
Utility class for validating method arguments.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
ensureBetween
(Double d, double min, double max, String name) Ensures that the given Double value is in[min, max]
.static int
ensureBetween
(Integer i, int min, int max, String name) Ensures that the given Integer value is in[min, max]
.static long
ensureBetween
(Long i, long min, long max, String name) Ensures that the given Long value is in[min, max]
.static void
Ensure that the two values are equal.static int
ensureGreaterThanZero
(Integer i, String name) Ensures that the given expression is true.static String
ensureNotBlank
(String string, String name) Ensures that the given string is not null and not blank.static <K,
V> Map <K, V> ensureNotEmpty
(Map<K, V> map, String name) Ensures that the given map is not null and not empty.static <T extends Collection<?>>
TensureNotEmpty
(T collection, String name) Ensures that the given collection is not null and not empty.static <T> T
ensureNotNull
(T object, String name) Ensures that the given object is not null.static <T> T
ensureNotNull
(T object, String format, Object... args) Ensures that the given object is not null.static void
ensureTrue
(boolean expression, String msg) Ensures that the given expression is true.
-
Method Details
-
ensureEq
Ensure that the two values are equal.- Parameters:
lhs
- the left hand side value.rhs
- the right hand side value.format
- the format string for the exception message.args
- the format arguments for the exception message.
-
ensureNotNull
Ensures that the given object is not null.- Type Parameters:
T
- The type of the object.- Parameters:
object
- The object to check.name
- The name of the object to be used in the exception message.- Returns:
- The object if it is not null.
- Throws:
IllegalArgumentException
- if the object is null.
-
ensureNotNull
Ensures that the given object is not null.- Type Parameters:
T
- The type of the object.- Parameters:
object
- The object to check.format
- The format of the exception message.args
- The arguments for the exception message.- Returns:
- The object if it is not null.
-
ensureNotEmpty
Ensures that the given collection is not null and not empty.- Type Parameters:
T
- The type of the collection.- Parameters:
collection
- The collection to check.name
- The name of the collection to be used in the exception message.- Returns:
- The collection if it is not null and not empty.
- Throws:
IllegalArgumentException
- if the collection is null or empty.
-
ensureNotEmpty
Ensures that the given map is not null and not empty.- Type Parameters:
K
- The type of the key.V
- The type of the value.- Parameters:
map
- The map to check.name
- The name of the map to be used in the exception message.- Returns:
- The map if it is not null and not empty.
- Throws:
IllegalArgumentException
- if the collection is null or empty.
-
ensureNotBlank
Ensures that the given string is not null and not blank.- Parameters:
string
- The string to check.name
- The name of the string to be used in the exception message.- Returns:
- The string if it is not null and not blank.
- Throws:
IllegalArgumentException
- if the string is null or blank.
-
ensureTrue
Ensures that the given expression is true.- Parameters:
expression
- The expression to check.msg
- The message to be used in the exception.- Throws:
IllegalArgumentException
- if the expression is false.
-
ensureGreaterThanZero
Ensures that the given expression is true.- Parameters:
i
- The expression to check.name
- The message to be used in the exception.- Returns:
- The value if it is greater than zero.
- Throws:
IllegalArgumentException
- if the expression is false.
-
ensureBetween
Ensures that the given Double value is in[min, max]
.- Parameters:
d
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
- The value if it is in
[min, max]
. - Throws:
IllegalArgumentException
- if the value is not in[min, max]
.
-
ensureBetween
Ensures that the given Integer value is in[min, max]
.- Parameters:
i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
- The value if it is in
[min, max]
. - Throws:
IllegalArgumentException
- if the value is not in[min, max]
.
-
ensureBetween
Ensures that the given Long value is in[min, max]
.- Parameters:
i
- The value to check.min
- The minimum value.max
- The maximum value.name
- The value name to be used in the exception.- Returns:
- The value if it is in
[min, max]
. - Throws:
IllegalArgumentException
- if the value is not in[min, max]
.
-