Package dev.prozilla.pine.common.util
Class Checks
java.lang.Object
dev.prozilla.pine.common.util.Checks
Static utility methods for throwing exceptions if certain conditions are not met at runtime.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> void
areDisjunct
(E[] arrayA, E[] arrayB) Checks that the given arrays are disjunct and throws anInvalidArrayException
if it is not.static <E> void
areDisjunct
(E[] arrayA, E[] arrayB, String message) Checks that the given arrays are disjunct and throws a customizedInvalidArrayException
if it is not.static <E> E[]
hasLength
(E[] array, int length) Checks that the given array has a given length and throws anInvalidArrayException
if it does not.static <E> E[]
Checks that the given array has a given length and throws a customizedInvalidArrayException
if 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 anInvalidArrayException
if 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 customizedInvalidArrayException
if 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 anInvalidArrayException
if 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 customizedInvalidArrayException
if it is not.static String
Checks that the given string starts with a prefix and throws anInvalidStringException
if it doesn't.static String
Checks that the given string starts with a prefix and throws a customizedInvalidStringException
if it doesn't.static String
Checks that the given string ends with a suffix and throws anInvalidStringException
if it doesn't.static String
Checks that the given string ends with a suffix and throws a customizedInvalidStringException
if it doesn't.static String
isNotBlank
(String string) Checks that the given string is not blank and throws anInvalidStringException
if it is not.static String
isNotBlank
(String string, String message) Checks that the given string is not blank and throws a customizedInvalidStringException
if it is.static <E> E[]
isNotEmpty
(E[] array) Checks that the given array is not empty and throws anInvalidArrayException
if it is.static <E> E[]
isNotEmpty
(E[] array, String message) Checks that the given array is not empty and throws a customizedInvalidArrayException
if it is.static String
isNotEmpty
(String string) Checks that the given string is not empty and throws anInvalidStringException
if it is not.static String
isNotEmpty
(String string, String message) Checks that the given string is not empty and throws a customizedInvalidStringException
if it is.static float
isPositive
(float number, boolean strict) Checks that the given number is a positive number and throws anInvalidNumberException
if it is not.static float
isPositive
(float number, boolean strict, String message) Checks that the given number is a positive number and throws a customizedInvalidNumberException
if it is not.static int
isPositive
(int number, boolean strict) Checks that the given number is a positive number and throws anInvalidNumberException
if it is not.static int
isPositive
(int number, boolean strict, String message) Checks that the given number is a positive number and throws a customizedInvalidNumberException
if it is not.
-
Constructor Details
-
Checks
public Checks()
-
-
Method Details
-
areDisjunct
Checks that the given arrays are disjunct and throws anInvalidArrayException
if it is not.- Type Parameters:
E
- Type of the array elements- Parameters:
arrayA
- The first arrayarrayB
- The second array- Throws:
InvalidArrayException
- IfarrayA
andarrayB
are 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 customizedInvalidArrayException
if 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 anInvalidArrayException
is thrown- Throws:
InvalidArrayException
- IfarrayA
andarrayB
are not disjunct.
-
isNotEmpty
Checks that the given array is not empty and throws anInvalidArrayException
if it is.- Type Parameters:
E
- Type of the array elements- Parameters:
array
- The array to check- Returns:
array
if it is not empty.- Throws:
InvalidArrayException
- Ifarray
is empty.
-
isNotEmpty
Checks that the given array is not empty and throws a customizedInvalidArrayException
if 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 anInvalidArrayException
is thrown- Returns:
array
if it is not empty.- Throws:
InvalidArrayException
- Ifarray
is empty.
-
hasMinLength
Checks that the given array's length is greater than or equal to the minimum length and throws anInvalidArrayException
if 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:
array
if its length is greater or equal.- Throws:
InvalidArrayException
- If length ofarray
is 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 customizedInvalidArrayException
if 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 anInvalidArrayException
is thrown- Returns:
array
if its length is greater or equal.- Throws:
InvalidArrayException
- If length ofarray
is less than the minimum length.
-
hasMaxLength
Checks that the given array's length is less than or equal to the maximum length and throws anInvalidArrayException
if 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:
array
if its length is less or equal.- Throws:
InvalidArrayException
- If length ofarray
is 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 customizedInvalidArrayException
if 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 anInvalidArrayException
is thrown- Returns:
array
if its length is less or equal.- Throws:
InvalidArrayException
- If length ofarray
is greater than the maximum length.
-
hasLength
Checks that the given array has a given length and throws anInvalidArrayException
if it does not.- Type Parameters:
E
- Type of the array elements- Parameters:
array
- The array to checklength
- The required length of the array- Returns:
array
if it matches the required length.- Throws:
InvalidArrayException
- Ifarray
matches the required length.
-
hasLength
Checks that the given array has a given length and throws a customizedInvalidArrayException
if 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 anInvalidArrayException
is thrown- Returns:
array
if it matches the required length.- Throws:
InvalidArrayException
- Ifarray
matches the required length.
-
isNotBlank
Checks that the given string is not blank and throws anInvalidStringException
if it is not.- Parameters:
string
- The string to check- Returns:
string
if it is not blank.- Throws:
InvalidStringException
- Ifstring
is blank.
-
isNotBlank
public static String isNotBlank(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not blank and throws a customizedInvalidStringException
if it is.- Parameters:
string
- The string to checkmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it is not blank.- Throws:
InvalidStringException
- Ifstring
is blank.
-
isNotEmpty
Checks that the given string is not empty and throws anInvalidStringException
if it is not.- Parameters:
string
- The string to check- Returns:
string
if it is not empty.- Throws:
InvalidStringException
- Ifstring
is empty.
-
isNotEmpty
public static String isNotEmpty(@Nonnull String string, String message) throws InvalidStringException Checks that the given string is not empty and throws a customizedInvalidStringException
if it is.- Parameters:
string
- The string to checkmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it is not empty.- Throws:
InvalidStringException
- Ifstring
is 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 anInvalidStringException
if it doesn't.- Parameters:
string
- The string to checkprefix
- The required prefix of the string- Returns:
string
if it starts with a given prefix.- Throws:
InvalidStringException
- Ifstring
does 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 customizedInvalidStringException
if it doesn't.- Parameters:
string
- The string to checkprefix
- The required prefix of the stringmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it starts with a given prefix.- Throws:
InvalidStringException
- Ifstring
does 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 anInvalidStringException
if it doesn't.- Parameters:
string
- The string to checksuffix
- The required suffix of the string- Returns:
string
if it ends with a given suffix.- Throws:
InvalidStringException
- Ifstring
does 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 customizedInvalidStringException
if it doesn't.- Parameters:
string
- The string to checksuffix
- The required suffix of the stringmessage
- The message to be used in the event that anInvalidStringException
is thrown- Returns:
string
if it ends with a given suffix.- Throws:
InvalidStringException
- Ifstring
does not end with a given suffix.
-
isPositive
Checks that the given number is a positive number and throws anInvalidNumberException
if it is not.- Parameters:
number
- The number to checkstrict
- Whether to throw an exception ifnumber
is0f
- Returns:
number
if it is positive.- Throws:
InvalidNumberException
- Ifnumber
is 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 customizedInvalidNumberException
if it is not.- Parameters:
number
- The number to checkstrict
- Whether to throw an exception ifnumber
is0f
message
- The message to be used in the event that anInvalidNumberException
is thrown- Returns:
number
if it is positive.- Throws:
InvalidNumberException
- Ifnumber
is not positive.
-
isPositive
Checks that the given number is a positive number and throws anInvalidNumberException
if it is not.- Parameters:
number
- The number to checkstrict
- Whether to throw an exception ifnumber
is0
- Returns:
number
if it is positive.- Throws:
InvalidNumberException
- Ifnumber
is 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 customizedInvalidNumberException
if it is not.- Parameters:
number
- The number to checkstrict
- Whether to throw an exception ifnumber
is0
message
- The message to be used in the event that anInvalidNumberException
is thrown- Returns:
number
if it is positive.- Throws:
InvalidNumberException
- Ifnumber
is not positive.
-