Class ArrayUtil

java.lang.Object
dev.quantumfusion.hyphen.util.ArrayUtil

public class ArrayUtil extends Object
T lot of very useful code that helps with handling Arrays for better code readability.
  • Constructor Details

    • ArrayUtil

      public ArrayUtil()
  • Method Details

    • dualForEach

      public static <A,​ B> void dualForEach(A[] a, B[] b, ArrayUtil.DualForEach<? super A,​? super B> dualForEach)
      Loops over 2 arrays at the same time.
      So if you have to array's that have linked content, and you want to combine the values or do something else you can use this method.

      This is the version with the index included.
      To exclude the index use the method below instead

      Type Parameters:
      A - Array 1 Type
      B - Array 2 Type
      Parameters:
      a - Array 1
      b - Array 2
      dualForEach - The Consumer that iterates.
      See Also:
      dualFor(Object[], Object[], BiConsumer)
    • dualFor

      public static <A,​ B> void dualFor(A[] a, B[] b, BiConsumer<? super A,​? super B> dualFor)
      Same as above but with the index excluded.
    • map

      public static <A,​ B> B[] map(A[] a, IntFunction<B[]> creator, ArrayUtil.IndexedMap<? super A,​? extends B> mapper)
      Map a given array to another type or something else.
      Equivalent to Arrays.stream(Object[]) and then Stream.map(Function)
      This method is however much faster and cleaner.

      This version has the index included. If you want to exclude the index use
      map(Object[], IntFunction, Function) instead.

    • map

      public static <A,​ B> B[] map(A[] a, IntFunction<B[]> creator, Function<? super A,​? extends B> mapper)
      Same as map(Object[], IntFunction, IndexedMap) but with the index excluded.
    • map

      public static <A,​ B,​ D> B[] map(A[] a, IntFunction<B[]> creator, D data, BiFunction<? super A,​? super D,​? extends B> mapper)
    • combine

      public static <T> T[] combine(T[] a1, T[] a2, IntFunction<T[]> creator)
      Combines 2 arrays into 1.
      Type Parameters:
      T - The Array Type
      Parameters:
      a1 - Array 1
      a2 - Array y
      creator - Creates the resulting array.
      Returns:
      The combined array.
    • combine

      public static <T> T[] combine(T[] a1, T[] a2)
      Combines 2 arrays into 1.
      Type Parameters:
      T - The Array Type
      Parameters:
      a1 - Array 1
      a2 - Array y
      Returns:
      The combined array.
    • filter

      public static <T> T[] filter(T[] array, Predicate<? super T> predicate)
      Filters the array's content.
      Type Parameters:
      T - The Array Elements.
      Parameters:
      array - The Array
      predicate - The Predicate. Matching entries will be included.
      Returns:
      The Filtered array.
    • copyAndAppend

      public static <T> T[] copyAndAppend(T[] oldArray, T newEntry)