Class ParamChecks
IllegalArgumentException naming that parameter.
Note: Do not use this class, internal use only!
- Since:
- 3.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublerequireFinite(double value, String name) Returnsvalueif it is finite.static StringrequireNonBlank(String value, String name) Returnsvalueif it is neithernullnor blank.static <T extends CharSequence>
TrequireNonEmpty(T value, String name) Returnsvalueif it is neithernullnor empty.static <T extends Collection<?>>
TrequireNonEmpty(T value, String name) Returnsvalueif it is neithernullnor empty.static voidrequireNonEmptyParallelArrays(Object[] first, String firstName, Object[] second, String secondName) Checks two arrays that hold corresponding values.static doublerequireNonNegative(double value, String name) Returnsvalueif it is not negative.static intrequireNonNegative(int value, String name) Returnsvalueif it is not negative.static longrequireNonNegative(long value, String name) Returnsvalueif it is not negative.static <T> TrequireNonNullArg(T value, String name) Returnsvalueif it is notnull.static doublerequirePositive(double value, String name) Returnsvalueif it is greater than zero.static intrequirePositive(int value, String name) Returnsvalueif it is greater than zero.static doublerequirePositiveFraction(double value, String name) Returnsvalueif it is in (0, 1].
-
Method Details
-
requireNonNullArg
Returnsvalueif it is notnull.The message of a thrown exception is
"<name> must not be null".- Type Parameters:
T- The argument type.- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, nevernull.- Throws:
IllegalArgumentException- Thrown ifvalueisnull.
-
requireNonEmpty
Returnsvalueif it is neithernullnor empty.The message of a thrown exception is
"<name> must not be null or empty".- Type Parameters:
T- The argument type.- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, nevernullor empty.- Throws:
IllegalArgumentException- Thrown ifvalueisnullor has a length of zero.
-
requireNonEmpty
Returnsvalueif it is neithernullnor empty.The message of a thrown exception is
"<name> must not be null or empty".- Type Parameters:
T- The argument type.- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, nevernullor empty.- Throws:
IllegalArgumentException- Thrown ifvalueisnullor contains no elements.
-
requireNonBlank
Returnsvalueif it is neithernullnor blank.A string is blank if it is empty or contains only Unicode
White_Spacecode points, as defined byStringUtil.isUnicodeBlank(CharSequence). The message of a thrown exception is"<name> must not be null or blank".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, nevernullor blank.- Throws:
IllegalArgumentException- Thrown ifvalueisnullor blank.
-
requireNonNegative
Returnsvalueif it is not negative.The message of a thrown exception is
"<name> must not be negative".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, never negative.- Throws:
IllegalArgumentException- Thrown ifvalueis less than zero.
-
requireNonNegative
Returnsvalueif it is not negative.The message of a thrown exception is
"<name> must not be negative".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, never negative.- Throws:
IllegalArgumentException- Thrown ifvalueis less than zero.
-
requireNonNegative
Returnsvalueif it is not negative.NaNis not less than zero and is returned unchanged, so check it withrequireFinite(double, String)first where it is not allowed. The message of a thrown exception is"<name> must not be negative".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, never negative.- Throws:
IllegalArgumentException- Thrown ifvalueis less than zero.
-
requirePositive
Returnsvalueif it is greater than zero.The message of a thrown exception is
"<name> must be positive".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, always greater than zero.- Throws:
IllegalArgumentException- Thrown ifvalueis zero or negative.
-
requirePositive
Returnsvalueif it is greater than zero. Positive infinity passes; callrequireFinite(double, String)first where it is not allowed. The message of a thrown exception is"<name> must be positive".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, always greater than zero.- Throws:
IllegalArgumentException- Thrown ifvalueis zero, negative, orNaN.
-
requireFinite
Returnsvalueif it is finite.The message of a thrown exception is
"<name> must be finite".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, neverNaNor infinite.- Throws:
IllegalArgumentException- Thrown ifvalueisNaNor infinite.
-
requirePositiveFraction
Returnsvalueif it is in (0, 1].The message of a thrown exception is
"<name> must be in (0, 1]".- Parameters:
value- The argument to check.name- The parameter name used in the exception message.- Returns:
value, always in(0, 1].- Throws:
IllegalArgumentException- Thrown ifvalueis not in(0, 1], includingNaN.
-
requireNonEmptyParallelArrays
public static void requireNonEmptyParallelArrays(Object[] first, String firstName, Object[] second, String secondName) Checks two arrays that hold corresponding values. Both arrays must be non-empty, have the same length, and contain nonullentries.- Parameters:
first- The first array to check.firstName- The first parameter name used in exception messages.second- The second array to check.secondName- The second parameter name used in exception messages.- Throws:
IllegalArgumentException- Thrown if either array isnullor empty, their lengths differ, or an entry isnull.
-