Class ArrayUtils

java.lang.Object
panda.utilities.ArrayUtils

public final class ArrayUtils extends Object
  • Method Details

    • forEach

      public static <T> void forEach(T[] array, Consumer<T> consumer)
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to iterate
      consumer - array values consumer
    • forEachThrowing

      public static <T, E extends Exception> void forEachThrowing(T[] array, panda.std.function.ThrowingConsumer<T,E> consumer) throws E
      Iterable.forEach(java.util.function.Consumer) for arrays using ThrowingConsumer
      Type Parameters:
      T - type of array
      E - type of exception
      Parameters:
      array - the array to iterate
      consumer - array values consumer with exceptions support
      Throws:
      E - if consumer will throw exception
    • merge

      @SafeVarargs public static <T> T[] merge(T[]... arrays)
      Merge several arrays
      Parameters:
      arrays - arrays to merge
      Returns:
      array of merged arrays
    • merge

      @SafeVarargs public static <T> T[] merge(Function<Integer,T[]> arrayFunction, T[]... arrays)
      Merge arrays into one array
      Type Parameters:
      T - type of arrays
      Parameters:
      arrayFunction - array instance supplier
      arrays - arrays to merge
      Returns:
      the merged array
    • merge

      public static <T> T[] merge(T firstElement, T[] array, Function<Integer,T[]> arrayFunction)
      Create a new array with the given element at the first position and copy the rest of array
      Type Parameters:
      T - type of array
      Parameters:
      firstElement - the element to add at the first position
      array - the array to copy
      arrayFunction - array instance supplier with array size as an argument
      Returns:
      the merged array
    • findIn

      public static <T> panda.std.Option<T> findIn(T[] array, Predicate<T> condition)
      Find value in array using the predicate condition
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to search in
      condition - the condition
      Returns:
      the found element or null
    • containsNull

      public static boolean containsNull(Object[] array)
      Check if the specified array contains null
      Returns:
      the array to search
    • contains

      public static boolean contains(Object[] array, Object element)
      Check if the specified array contains the element
      Parameters:
      array - the array to search
      element - the element to search for
      Returns:
      true if the specified array contains the element, otherwise false
    • length

      @SafeVarargs public static <T> int length(T[]... arrays)
      Get length of all given arrays
      Type Parameters:
      T - type of arrays
      Parameters:
      arrays - the arrays to sum up
      Returns:
      arrays length
    • isArray

      public static boolean isArray(@Nullable @Nullable Object object)
      Check if the given object is array
      Parameters:
      object - the object to check
      Returns:
      true if object is not null and its class represents array, otherwise false
    • isEmpty

      public static boolean isEmpty(@Nullable @Nullable Object[] array)
      Checks if the specified array is null or empty
      Parameters:
      array - the array to check
      Returns:
      true if array is null or empty
    • getDimensionalArrayType

      public static Class<?> getDimensionalArrayType(Class<?> type, int dimensions)
      Get dimensional array for the specified type
      Parameters:
      type - the type of the array
      dimensions - the amount of dimensions
      Returns:
      the class of the dimensional array
    • getBaseClass

      public static Class<?> getBaseClass(Class<?> arrayClass)
      Get base class of any array, e.g. Integer from Integer[][][][][]
      Parameters:
      arrayClass - the array class
      Returns:
      the base type
    • getBaseClassWithDimensions

      public static panda.std.Pair<Class<?>,Integer> getBaseClassWithDimensions(Class<?> arrayClass)
      Get base class of any array, e.g. Integer from Integer[][][][][]
      Parameters:
      arrayClass - the array class
      Returns:
      the base type
    • getArrayClass

      public static Class<?> getArrayClass(Class<?> clazz)
      Get array class for the specified type
      Parameters:
      clazz - type of array
      Returns:
      array of type
    • getIndex

      public static <T> int getIndex(T[] array, Predicate<T> condition)
      Get index of element that pass the condition
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to search in
      condition - the condition to test elements
      Returns:
      index of element or -1 if element was not found
    • indexOf

      public static <T> int indexOf(T[] array, @Nullable T element)
      Get index of the given element
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to search in
      element - element to search for
      Returns:
      index of element or -1 if element was not found
    • getFirst

      public static <T> panda.std.Option<T> getFirst(T[] array)
      Get first element of the given array
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to search in
      Returns:
      first element of the given array or empty option
    • getLast

      public static <T> panda.std.Option<T> getLast(T[] array)
      Get last element of the given array
      Type Parameters:
      T - type of array
      Parameters:
      array - the array to search in
      Returns:
      last element of the given array or empty option
    • get

      public static <T> panda.std.Option<T> get(T[] array, int index)
      Get element of array at the given position without risk of ArrayIndexOutOfBoundsException
      Type Parameters:
      T - type of the array
      Parameters:
      array - the array to process
      index - the index of element to get
      Returns:
      the element at the index position, null if the index is less than 0 or greater than the size of the specified array
    • get

      public static <T> T get(T[] array, int index, T defaultValue)
      Get element of array at the given position without risk of ArrayIndexOutOfBoundsException
      Type Parameters:
      T - type of the array
      Parameters:
      array - the array to process
      index - the index of element to get
      defaultValue - the default value to return when there is no such an index in the array
      Returns:
      the element at the index position, null if the index is less than 0 or greater than the size of the specified array
    • of

      @SafeVarargs public static <T> T[] of(T... elements)
      Return array of the specified elements using varargs parameter
      Type Parameters:
      T - type of the array
      Parameters:
      elements - elements in array
      Returns:
      the array of the specified elements