Package dev.prozilla.pine.common.util
Class Arrays
java.lang.Object
dev.prozilla.pine.common.util.Arrays
Static utility methods for checking certain conditions before operation on arrays.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> void
requireDisjunct
(E[] arrayA, E[] arrayB) Checks that the given arrays are disjunct and throws anInvalidArrayException
if it is not.static <E> void
requireDisjunct
(E[] arrayA, E[] arrayB, String message) Checks that the given arrays are disjunct and throws a customizedInvalidArrayException
if it is not.static <E> E[]
requireLength
(E[] array, int length) Checks that the given array has a given length and throws anInvalidArrayException
if it does not.static <E> E[]
requireLength
(E[] array, int length, String message) Checks that the given array has a given length and throws a customizedInvalidArrayException
if it does not.static <E> E[]
requireMaxLength
(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[]
requireMaxLength
(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[]
requireMinLength
(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[]
requireMinLength
(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 <E> E[]
requireNonEmpty
(E[] array) Checks that the given array is not empty and throws anInvalidArrayException
if it is.static <E> E[]
requireNonEmpty
(E[] array, String message) Checks that the given array is not empty and throws a customizedInvalidArrayException
if it is.
-
Constructor Details
-
Arrays
public Arrays()
-
-
Method Details
-
requireDisjunct
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.
-
requireDisjunct
public static <E> void requireDisjunct(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.
-
requireNonEmpty
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.
-
requireNonEmpty
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.
-
requireMinLength
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.
-
requireMinLength
public static <E> E[] requireMinLength(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.
-
requireMaxLength
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.
-
requireMaxLength
public static <E> E[] requireMaxLength(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.
-
requireLength
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.
-
requireLength
public static <E> E[] requireLength(E[] array, int length, String message) throws InvalidArrayException 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.
-