java.lang.Object
ushiosan.jvm.internal.collections.arrays.generic.UArraysGeneric
All Implemented Interfaces:
UArraysConstants
Direct Known Subclasses:
UArrayPrimitive

public abstract class UArraysGeneric extends Object implements UArraysConstants
  • Constructor Details

    • UArraysGeneric

      public UArraysGeneric()
  • Method Details

    • makeEmpty

      public static <T> T[] makeEmpty()
    • make

      @SafeVarargs public static <T> T[] make(T... elements)
      Generate an 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:
    • make

      public static Object @NotNull [] make(@NotNull @NotNull Iterator<?> iterator)
      Generate an 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 an 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 an 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

      This method checks if two arrays have the same length and the same elements. It utilizes a labeled block and a conditional break to optimize the process and avoid redundant return statements. By using a single return statement outside the block, we achieve a more dynamic flow while minimizing code duplication.

      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> Object @NotNull [] transform(@NotNull @NotNull T[] original, @NotNull @NotNull Function<T,Object> mapper)
      Converts one array to another but with a different data type.
      Type Parameters:
      T - the original 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