java.lang.Object
ushiosan.jvm_utilities.internal.collection.ArrsGeneric
All Implemented Interfaces:
IArrsConstants
Direct Known Subclasses:
ArrsPrimitive

public abstract class ArrsGeneric extends Object implements IArrsConstants
Base class used for manipulating arrays of type object. This means that it has no methods for manipulating primitive types.
See Also:
  • Constructor Details

    • ArrsGeneric

      public ArrsGeneric()
  • Method Details

    • of

      @SafeVarargs public static <T> T[] of(T... elements)
      Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types.
      Type Parameters:
      T - element types
      Parameters:
      elements - the elements to add
      Returns:
      an array with all values
      See Also:
    • of

      public static Object @NotNull [] of(Iterator<?> iterator)
      Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types.
      Parameters:
      iterator - the iterator to convert
      Returns:
      an array with all values
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(Object @NotNull [] array, @Nullable @Nullable Object element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      @Contract(pure=true) public static int lastIndexOf(Object @NotNull [] array, @Nullable @Nullable Object element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(Object @NotNull [] array, @Nullable @Nullable Object element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • lastElement

      @NotNull public static <T> @NotNull Optional<T> lastElement(T @NotNull [] array)
      Returns the last element of the array
      Type Parameters:
      T - generic array type
      Parameters:
      array - base array to search
      Returns:
      the last element of the array or Optional.empty() if array is empty
    • unsafeLastElement

      @Nullable public static <T> T unsafeLastElement(T @NotNull [] array)
      Returns the last element of the array
      Type Parameters:
      T - generic array type
      Parameters:
      array - base array to search
      Returns:
      the last element of the array or null if array is empty
    • contentEquals

      public static <T> boolean contentEquals(T @NotNull [] ar1, T @NotNull [] ar2)
      Verify that the contents of two arrays are the same
      Type Parameters:
      T - the data type of each array
      Parameters:
      ar1 - the array to check
      ar2 - the array to check
      Returns:
      true if the content is the same or false if the size is different or the content is different
    • transform

      public static <T, V> V @NotNull [] transform(@NotNull @NotNull T[] original, @NotNull @NotNull Function<T,V> mapper, @NotNull @NotNull IntFunction<V[]> arrFn)
      Converts one array to another but with a different data type.
      Type Parameters:
      T - the original data type
      V - the target data type
      Parameters:
      original - the original array that you want to convert
      mapper - function in charge of transforming each element of the array
      arrFn - function that generates the required type of array
      Returns:
      the new array with the converted data
    • transform

      public static <T, V> Object @NotNull [] transform(@NotNull @NotNull T[] original, @NotNull @NotNull Function<T,V> mapper)
      Converts one array to another but with a different data type.
      Type Parameters:
      T - the original data type
      V - the target data type
      Parameters:
      original - the original array that you want to convert
      mapper - function in charge of transforming each element of the array
      Returns:
      the new array with the converted data
    • join

      public static <T> T @NotNull [] join(@NotNull @NotNull T[] a1, @NotNull @NotNull T[] a2)
      Merge two arrays into one
      Type Parameters:
      T - the type of array that the method will generate
      Parameters:
      a1 - array you want to combine
      a2 - array you want to combine
      Returns:
      a new array with all the content of the two arrays passed as parameter
    • join

      public static <T> T @NotNull [] join(@NotNull @NotNull Class<T> cls, @NotNull @NotNull T[] a1, @NotNull @NotNull T[] a2)
      Merge two arrays into one
      Type Parameters:
      T - the type of array that the method will generate
      Parameters:
      cls - the type of data to be processed
      a1 - array you want to combine
      a2 - array you want to combine
      Returns:
      a new array with all the content of the two arrays passed as parameter
    • joinAll

      @SafeVarargs public static <T> T @NotNull [] joinAll(@NotNull @NotNull Class<T> cls, T[] @NotNull ... arrays)
      Combine multiple arrays into one
      Type Parameters:
      T - the type of array that the method will generate
      Parameters:
      cls - the type of data to be processed
      arrays - all the arrays you want to combine
      Returns:
      a new array with all the content of the arrays passed as parameter
    • joinAll

      @SafeVarargs public static <T> T @NotNull [] joinAll(T[] @NotNull ... arrays)
      Combine multiple arrays into one
      Type Parameters:
      T - the type of array that the method will generate
      Parameters:
      arrays - all the arrays you want to combine
      Returns:
      a new array with all the content of the arrays passed as parameter