Class ArrayUtils

java.lang.Object
redempt.redlex.processing.ArrayUtils

public class ArrayUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    concat(T[] first, T[] second, Function<Integer,T[]> arrayConstructor)
    Concatenates two arrays
    static <T> T[]
    remove(T[] arr, int index, Function<Integer,T[]> arrayConstructor)
    Creates a new array with a single element removed from the input array
    static <T> T[]
    remove(T[] arr, Function<Integer,T[]> arrayConstructor, T... toRemove)
    Remove elements from an array
    static <T> T[]
    removeRange(T[] arr, int start, int end, Function<Integer,T[]> arrayConstructor)
    Removes a range of elements from an array
    static <T> T[]
    replaceRange(T[] first, T[] second, int start, int end, Function<Integer,T[]> arrayConstructor)
    Replaces a range of an array with the contents of another array

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayUtils

      public ArrayUtils()
  • Method Details

    • remove

      public static <T> T[] remove(T[] arr, Function<Integer,T[]> arrayConstructor, T... toRemove)
      Remove elements from an array
      Type Parameters:
      T - The type of the array
      Parameters:
      arr - The array to remove elements from
      arrayConstructor - A function to create a new array of the given type with the given size
      toRemove - The elements to remove, must all map to elements already in the array
      Returns:
      The array with elements removed
    • concat

      public static <T> T[] concat(T[] first, T[] second, Function<Integer,T[]> arrayConstructor)
      Concatenates two arrays
      Type Parameters:
      T - The type of the array
      Parameters:
      first - The first array
      second - The second array
      arrayConstructor - A function to create a new array of the given type with the given size
      Returns:
      The concatenated array
    • replaceRange

      public static <T> T[] replaceRange(T[] first, T[] second, int start, int end, Function<Integer,T[]> arrayConstructor)
      Replaces a range of an array with the contents of another array
      Type Parameters:
      T - The type of the array
      Parameters:
      first - The array to replace the range in
      second - The array to insert in place of the replaced range
      start - The starting index to replace from in the first array, inclusive
      end - The ending index to replace to in the first array, exclusive
      arrayConstructor - A function to create a new array of the given type with the given size
      Returns:
      The resulting array
    • remove

      public static <T> T[] remove(T[] arr, int index, Function<Integer,T[]> arrayConstructor)
      Creates a new array with a single element removed from the input array
      Type Parameters:
      T - The type of the array
      Parameters:
      arr - The array to remove the element from
      index - The index of the element to remove
      arrayConstructor - A function to create a new array of the given type with the given size
      Returns:
      The array with the element removed
    • removeRange

      public static <T> T[] removeRange(T[] arr, int start, int end, Function<Integer,T[]> arrayConstructor)
      Removes a range of elements from an array
      Type Parameters:
      T - The type of the array
      Parameters:
      arr - The array to remove elements from
      start - The start index to remove elements from, inclusive
      end - The end index to remove elements to, exclusive
      arrayConstructor - A function to create a new array of the given type with the given size
      Returns:
      The array with the range removed