Class Arrays

java.lang.Object
dev.prozilla.pine.common.util.Arrays

public final class Arrays extends Object
Static utility methods for checking certain conditions before operation on arrays.
  • Constructor Details

    • Arrays

      public Arrays()
  • Method Details

    • requireDisjunct

      public static <E> void requireDisjunct(E[] arrayA, E[] arrayB) throws InvalidArrayException
      Checks that the given arrays are disjunct and throws an InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      arrayA - The first array
      arrayB - The second array
      Throws:
      InvalidArrayException - If arrayA and arrayB 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 customized InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      arrayA - The first array
      arrayB - The second array
      message - The message to be used in the event that an InvalidArrayException is thrown
      Throws:
      InvalidArrayException - If arrayA and arrayB are not disjunct.
    • requireNonEmpty

      public static <E> E[] requireNonEmpty(E[] array) throws InvalidArrayException
      Checks that the given array is not empty and throws an InvalidArrayException 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 - If array is empty.
    • requireNonEmpty

      public static <E> E[] requireNonEmpty(E[] array, String message) throws InvalidArrayException
      Checks that the given array is not empty and throws a customized InvalidArrayException if it is.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      message - The message to be used in the event that an InvalidArrayException is thrown
      Returns:
      array if it is not empty.
      Throws:
      InvalidArrayException - If array is empty.
    • requireMinLength

      public static <E> E[] requireMinLength(E[] array, int minLength) throws InvalidArrayException
      Checks that the given array's length is greater than or equal to the minimum length and throws an InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      minLength - The minimum length of the array (inclusive)
      Returns:
      array if its length is greater or equal.
      Throws:
      InvalidArrayException - If length of array 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 customized InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      minLength - The minimum length of the array (inclusive)
      message - The message to be used in the event that an InvalidArrayException is thrown
      Returns:
      array if its length is greater or equal.
      Throws:
      InvalidArrayException - If length of array is less than the minimum length.
    • requireMaxLength

      public static <E> E[] requireMaxLength(E[] array, int maxLength) throws InvalidArrayException
      Checks that the given array's length is less than or equal to the maximum length and throws an InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      maxLength - The maximum length of the array (inclusive)
      Returns:
      array if its length is less or equal.
      Throws:
      InvalidArrayException - If length of array 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 customized InvalidArrayException if it is not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      maxLength - The maximum length of the array (inclusive)
      message - The message to be used in the event that an InvalidArrayException is thrown
      Returns:
      array if its length is less or equal.
      Throws:
      InvalidArrayException - If length of array is greater than the maximum length.
    • requireLength

      public static <E> E[] requireLength(E[] array, int length) throws InvalidArrayException
      Checks that the given array has a given length and throws an InvalidArrayException if it does not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      length - The required length of the array
      Returns:
      array if it matches the required length.
      Throws:
      InvalidArrayException - If array 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 customized InvalidArrayException if it does not.
      Type Parameters:
      E - Type of the array elements
      Parameters:
      array - The array to check
      length - The required length of the array
      message - The message to be used in the event that an InvalidArrayException is thrown
      Returns:
      array if it matches the required length.
      Throws:
      InvalidArrayException - If array matches the required length.