Class Checks
java.lang.Object
dev.prozilla.pine.common.util.checks.Checks
Static utility methods for throwing exceptions if certain conditions are not met at runtime.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> voidareDisjunct(E[] arrayA, E[] arrayB) Checks that the given arrays are disjunct and throws anInvalidArrayExceptionif it is not.static <E> voidareDisjunct(E[] arrayA, E[] arrayB, String message) Checks that the given arrays are disjunct and throws a customizedInvalidArrayExceptionif it is not.static <E> ArrayChecks<E> static <E> CollectionChecks<E> collection(Collection<E> value, String name) static <E> E[]hasLength(E[] array, int length) Checks that the given array has a given length and throws anInvalidArrayExceptionif it does not.static <E> E[]Checks that the given array has a given length and throws a customizedInvalidArrayExceptionif it does not.static <E> E[]hasMaxLength(E[] array, int maxLength) Checks that the given array's length is less than or equal to the maximum length and throws anInvalidArrayExceptionif it is not.static <E> E[]hasMaxLength(E[] array, int maxLength, String message) Checks that the given array's length is less than or equal to the maximum length and throws a customizedInvalidArrayExceptionif it is not.static <E> E[]hasMinLength(E[] array, int minLength) Checks that the given array's length is greater than or equal to the minimum length and throws anInvalidArrayExceptionif it is not.static <E> E[]hasMinLength(E[] array, int minLength, String message) Checks that the given array's length is greater than or equal to the minimum length and throws a customizedInvalidArrayExceptionif it is not.static StringChecks that the given string starts with a prefix and throws anInvalidStringExceptionif it doesn't.static StringChecks that the given string starts with a prefix and throws a customizedInvalidStringExceptionif it doesn't.static StringChecks that the given string ends with a suffix and throws anInvalidStringExceptionif it doesn't.static StringChecks that the given string ends with a suffix and throws a customizedInvalidStringExceptionif it doesn't.static IntChecksstatic intisInRange(int number, int min, int max) Checks that the given number is in the given range and throws anInvalidNumberExceptionif it is not.static intChecks that the given number is in the given range and throws a customizedInvalidNumberExceptionif it is not.static StringisNotBlank(String string) Checks that the given string is not blank and throws anInvalidStringExceptionif it is not.static StringisNotBlank(String string, String message) Checks that the given string is not blank and throws a customizedInvalidStringExceptionif it is.static <E> E[]isNotEmpty(E[] array) Checks that the given array is not empty and throws anInvalidArrayExceptionif it is.static <E> E[]isNotEmpty(E[] array, String message) Checks that the given array is not empty and throws a customizedInvalidArrayExceptionif it is.static StringisNotEmpty(String string) Checks that the given string is not empty and throws anInvalidStringExceptionif it is not.static StringisNotEmpty(String string, String message) Checks that the given string is not empty and throws a customizedInvalidStringExceptionif it is.static <O> OisNotNull(O object) static <O> Ostatic floatisPositive(float number, boolean strict) Checks that the given number is a positive number and throws anInvalidNumberExceptionif it is not.static floatisPositive(float number, boolean strict, String message) Checks that the given number is a positive number and throws a customizedInvalidNumberExceptionif it is not.static intisPositive(int number, boolean strict) Checks that the given number is a positive number and throws anInvalidNumberExceptionif it is not.static intisPositive(int number, boolean strict, String message) Checks that the given number is a positive number and throws a customizedInvalidNumberExceptionif it is not.static ObjectChecksstatic StringChecks
-
Method Details
-
isNotNull
- Throws:
InvalidObjectException
-
isNotNull
@Contract("null, _ -> fail") public static <O> O isNotNull(O object, String name) throws InvalidObjectException - Throws:
InvalidObjectException
-
areDisjunct
Checks that the given arrays are disjunct and throws anInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
arrayA- The first arrayarrayB- The second array- Throws:
InvalidArrayException- IfarrayAandarrayBare not disjunct.
-
areDisjunct
public static <E> void areDisjunct(E[] arrayA, E[] arrayB, String message) throws InvalidArrayException Checks that the given arrays are disjunct and throws a customizedInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
arrayA- The first arrayarrayB- The second arraymessage- The message to be used in the event that anInvalidArrayExceptionis thrown- Throws:
InvalidArrayException- IfarrayAandarrayBare not disjunct.
-
isNotEmpty
Checks that the given array is not empty and throws anInvalidArrayExceptionif it is.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to check- Returns:
arrayif it is not empty.- Throws:
InvalidArrayException- Ifarrayis empty.
-
isNotEmpty
Checks that the given array is not empty and throws a customizedInvalidArrayExceptionif it is.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checkmessage- The message to be used in the event that anInvalidArrayExceptionis thrown- Returns:
arrayif it is not empty.- Throws:
InvalidArrayException- Ifarrayis empty.
-
hasMinLength
Checks that the given array's length is greater than or equal to the minimum length and throws anInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checkminLength- The minimum length of the array (inclusive)- Returns:
arrayif its length is greater or equal.- Throws:
InvalidArrayException- If length ofarrayis less than the minimum length.
-
hasMinLength
public static <E> E[] hasMinLength(E[] array, int minLength, String message) throws InvalidArrayException Checks that the given array's length is greater than or equal to the minimum length and throws a customizedInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checkminLength- The minimum length of the array (inclusive)message- The message to be used in the event that anInvalidArrayExceptionis thrown- Returns:
arrayif its length is greater or equal.- Throws:
InvalidArrayException- If length ofarrayis less than the minimum length.
-
hasMaxLength
Checks that the given array's length is less than or equal to the maximum length and throws anInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checkmaxLength- The maximum length of the array (inclusive)- Returns:
arrayif its length is less or equal.- Throws:
InvalidArrayException- If length ofarrayis greater than the maximum length.
-
hasMaxLength
public static <E> E[] hasMaxLength(E[] array, int maxLength, String message) throws InvalidArrayException Checks that the given array's length is less than or equal to the maximum length and throws a customizedInvalidArrayExceptionif it is not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checkmaxLength- The maximum length of the array (inclusive)message- The message to be used in the event that anInvalidArrayExceptionis thrown- Returns:
arrayif its length is less or equal.- Throws:
InvalidArrayException- If length ofarrayis greater than the maximum length.
-
hasLength
Checks that the given array has a given length and throws anInvalidArrayExceptionif it does not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checklength- The required length of the array- Returns:
arrayif it matches the required length.- Throws:
InvalidArrayException- Ifarraymatches the required length.
-
hasLength
Checks that the given array has a given length and throws a customizedInvalidArrayExceptionif it does not.- Type Parameters:
E- Type of the array elements- Parameters:
array- The array to checklength- The required length of the arraymessage- The message to be used in the event that anInvalidArrayExceptionis thrown- Returns:
arrayif it matches the required length.- Throws:
InvalidArrayException- Ifarraymatches the required length.
-
isNotBlank
Checks that the given string is not blank and throws anInvalidStringExceptionif it is not.- Parameters:
string- The string to check- Returns:
stringif it is not blank.- Throws:
InvalidStringException- Ifstringis blank.
-
isNotBlank
public static String isNotBlank(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not blank and throws a customizedInvalidStringExceptionif it is.- Parameters:
string- The string to checkmessage- The message to be used in the event that anInvalidStringExceptionis thrown- Returns:
stringif it is not blank.- Throws:
InvalidStringException- Ifstringis blank.
-
isNotEmpty
Checks that the given string is not empty and throws anInvalidStringExceptionif it is not.- Parameters:
string- The string to check- Returns:
stringif it is not empty.- Throws:
InvalidStringException- Ifstringis empty.
-
isNotEmpty
public static String isNotEmpty(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not empty and throws a customizedInvalidStringExceptionif it is.- Parameters:
string- The string to checkmessage- The message to be used in the event that anInvalidStringExceptionis thrown- Returns:
stringif it is not empty.- Throws:
InvalidStringException- Ifstringis empty.
-
hasPrefix
public static String hasPrefix(@Nonnull String string, @Nonnull String prefix) throws InvalidStringException Checks that the given string starts with a prefix and throws anInvalidStringExceptionif it doesn't.- Parameters:
string- The string to checkprefix- The required prefix of the string- Returns:
stringif it starts with a given prefix.- Throws:
InvalidStringException- Ifstringdoes not start with a given prefix.
-
hasPrefix
public static String hasPrefix(@Nonnull String string, @Nonnull String prefix, String message) throws InvalidStringException Checks that the given string starts with a prefix and throws a customizedInvalidStringExceptionif it doesn't.- Parameters:
string- The string to checkprefix- The required prefix of the stringmessage- The message to be used in the event that anInvalidStringExceptionis thrown- Returns:
stringif it starts with a given prefix.- Throws:
InvalidStringException- Ifstringdoes not start with a given prefix.
-
hasSuffix
public static String hasSuffix(@Nonnull String string, @Nonnull String suffix) throws InvalidStringException Checks that the given string ends with a suffix and throws anInvalidStringExceptionif it doesn't.- Parameters:
string- The string to checksuffix- The required suffix of the string- Returns:
stringif it ends with a given suffix.- Throws:
InvalidStringException- Ifstringdoes not end with a given suffix.
-
hasSuffix
public static String hasSuffix(@Nonnull String string, @Nonnull String suffix, String message) throws InvalidStringException Checks that the given string ends with a suffix and throws a customizedInvalidStringExceptionif it doesn't.- Parameters:
string- The string to checksuffix- The required suffix of the stringmessage- The message to be used in the event that anInvalidStringExceptionis thrown- Returns:
stringif it ends with a given suffix.- Throws:
InvalidStringException- Ifstringdoes not end with a given suffix.
-
isPositive
Checks that the given number is a positive number and throws anInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkstrict- Whether to throw an exception ifnumberis0f- Returns:
numberif it is positive.- Throws:
InvalidNumberException- Ifnumberis not positive.
-
isPositive
public static float isPositive(float number, boolean strict, String message) throws InvalidNumberException Checks that the given number is a positive number and throws a customizedInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkstrict- Whether to throw an exception ifnumberis0fmessage- The message to be used in the event that anInvalidNumberExceptionis thrown- Returns:
numberif it is positive.- Throws:
InvalidNumberException- Ifnumberis not positive.
-
isPositive
Checks that the given number is a positive number and throws anInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkstrict- Whether to throw an exception ifnumberis0- Returns:
numberif it is positive.- Throws:
InvalidNumberException- Ifnumberis not positive.
-
isPositive
public static int isPositive(int number, boolean strict, String message) throws InvalidNumberException Checks that the given number is a positive number and throws a customizedInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkstrict- Whether to throw an exception ifnumberis0message- The message to be used in the event that anInvalidNumberExceptionis thrown- Returns:
numberif it is positive.- Throws:
InvalidNumberException- Ifnumberis not positive.
-
isInRange
Checks that the given number is in the given range and throws anInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkmin- Lower bound (inclusive)max- Upper bound (inclusive)- Returns:
numberif it is in the range.- Throws:
InvalidNumberException- Ifnumberis not in the range.
-
isInRange
public static int isInRange(int number, int min, int max, String message) throws InvalidNumberException Checks that the given number is in the given range and throws a customizedInvalidNumberExceptionif it is not.- Parameters:
number- The number to checkmin- Lower bound (inclusive)max- Upper bound (inclusive)message- The message to be used in the event that anInvalidNumberExceptionis thrown- Returns:
numberif it is in the range.- Throws:
InvalidNumberException- Ifnumberis not in the range.
-
array
-
collection
-
integer
-
object
-
string
-