Class ArrayUtils

java.lang.Object
net.dermetfan.utils.ArrayUtils
Direct Known Subclasses:
ArrayUtils

public class ArrayUtils extends Object
array utility methods
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Boolean[]
    box(boolean[] values)
     
    static Float[]
    box(float[] values)
     
    static Integer[]
    box(int[] values)
     
    static void
    checkRegion(float[] array, int offset, int length)
     
    static void
    checkRegion(int[] array, int offset, int length)
     
    static void
    checkRegion(Object[] array, int offset, int length)
     
    static <T, T2 extends T>
    boolean
    contains(T[] array, T2[] other, boolean identity)
     
    static <T> boolean
    contains(T[] array, T value, boolean identity)
     
    static <T, T2 extends T>
    boolean
    containsAny(T[] array, T2[] other, boolean identity)
     
    static boolean
    equalsAny(Object obj, Object[] array)
     
    static boolean
    equalsAny(Object obj, Object[] array, int offset, int length)
     
    static float
    getRepeated(float[] array, int index)
     
    static int
    getRepeated(int[] array, int index)
     
    static <T> T
    getRepeated(T[] array, int index)
     
    static boolean
    regionEquals(byte[] array, int offset, byte[] other)
     
    static boolean
    regionEquals(byte[] array, int offset, int length, byte[] other)
     
    static boolean
    regionEquals(byte[] array, int offset, int length, byte[] other, int otherOffset)
     
    static boolean
    regionEquals(double[] array, int offset, double[] other, double epsilon)
     
    static boolean
    regionEquals(double[] array, int offset, int length, double[] other, double epsilon)
     
    static boolean
    regionEquals(double[] array, int offset, int length, double[] other, int otherOffset, double epsilon)
     
    static boolean
    regionEquals(float[] array, int offset, float[] other, float epsilon)
     
    static boolean
    regionEquals(float[] array, int offset, int length, float[] other, float epsilon)
     
    static boolean
    regionEquals(float[] array, int offset, int length, float[] other, int otherOffset, float epsilon)
     
    static boolean
    regionEquals(int[] array, int offset, int[] other)
     
    static boolean
    regionEquals(int[] array, int offset, int length, int[] other)
     
    static boolean
    regionEquals(int[] array, int offset, int length, int[] other, int otherOffset)
     
    static boolean
    regionEquals(long[] array, int offset, int length, long[] other)
     
    static boolean
    regionEquals(long[] array, int offset, int length, long[] other, int otherOffset)
     
    static boolean
    regionEquals(long[] array, int offset, long[] other)
     
    static boolean
    regionEquals(short[] array, int offset, int length, short[] other)
     
    static boolean
    regionEquals(short[] array, int offset, int length, short[] other, int otherOffset)
     
    static boolean
    regionEquals(short[] array, int offset, short[] other)
     
    static boolean
    regionEquals(Object[] array, int offset, int length, Object[] other, boolean identity)
     
    static boolean
    regionEquals(Object[] array, int offset, int length, Object[] other, int otherOffset, boolean identity)
     
    static boolean
    regionEquals(Object[] array, int offset, Object[] other, boolean identity)
     
    static int
    repeat(int length, int index)
     
    static int
    repeat(int offset, int length, int index)
    Repeats the given index within the given length (of an array).
    static void
    requireCapacity(float[] source, int offset, int length, float[] dest, int destOffset)
    throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
    static void
    requireCapacity(int[] source, int offset, int length, int[] dest, int destOffset)
    throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
    static void
    requireCapacity(Object[] source, int offset, int length, Object[] dest, int destOffset)
    throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
    static float[]
    select(float[] items, int everyXth)
     
    static float[]
    select(float[] items, int[] indices)
     
    static float[]
    select(float[] items, int[] indices, float[] dest)
     
    static float[]
    select(float[] items, int[] indices, float[] dest, int destOffset)
     
    static float[]
    select(float[] items, int[] indices, int indicesOffset, int indicesLength, float[] dest, int destOffset)
     
    static float[]
    select(float[] items, int everyXth, float[] dest)
     
    static float[]
    select(float[] items, int start, int everyXth)
     
    static float[]
    select(float[] items, int start, int everyXth, float[] dest)
     
    static float[]
    select(float[] items, int offset, int length, int start, int everyXth)
     
    static float[]
    select(float[] items, int offset, int length, int start, int everyXth, float[] dest)
     
    static float[]
    select(float[] items, int offset, int length, int start, int everyXth, float[] dest, int destOffset)
     
    static int[]
    select(int[] items, int everyXth)
     
    static int[]
    select(int[] items, int[] indices)
     
    static int[]
    select(int[] items, int[] indices, int[] dest)
     
    static int[]
    select(int[] items, int[] indices, int[] dest, int destOffset)
     
    static int[]
    select(int[] items, int[] indices, int indicesOffset, int indicesLength, int[] dest, int destOffset)
     
    static int[]
    select(int[] items, int start, int everyXth)
     
    static int[]
    select(int[] items, int everyXth, int[] dest)
     
    static int[]
    select(int[] items, int start, int everyXth, int[] dest)
     
    static int[]
    select(int[] items, int offset, int length, int start, int everyXth)
     
    static int[]
    select(int[] items, int offset, int length, int start, int everyXth, int[] dest)
     
    static int[]
    select(int[] items, int offset, int length, int start, int everyXth, int[] dest, int destOffset)
     
    static <T> T[]
    select(T[] items, int everyXth)
     
    static <T> T[]
    select(T[] items, int[] indices)
     
    static <T> T[]
    select(T[] items, int[] indices, int indicesOffset, int indicesLength, T[] dest, int destOffset)
     
    static <T> T[]
    select(T[] items, int[] indices, T[] dest)
     
    static <T> T[]
    select(T[] items, int[] indices, T[] dest, int destOffset)
     
    static <T> T[]
    select(T[] items, int start, int everyXth)
     
    static <T> T[]
    select(T[] items, int offset, int length, int start, int everyXth)
     
    static <T> T[]
    select(T[] items, int offset, int length, int start, int everyXth, T[] dest)
     
    static <T> T[]
    select(T[] items, int offset, int length, int start, int everyXth, T[] dest, int destOffset)
     
    static <T> T[]
    select(T[] items, int start, int everyXth, T[] dest)
     
    static <T> T[]
    select(T[] items, int everyXth, T[] dest)
     
    static int
    selectCount(int offset, int length, int start, int everyXth)
     
    static void
    shift(float[] array, int shift)
     
    static void
    shift(float[] array, int offset, int length, int shift)
     
    static void
    shift(int[] array, int shift)
     
    static void
    shift(int[] array, int offset, int length, int shift)
     
    static void
    shift(Object[] array, int shift)
     
    static void
    shift(Object[] array, int offset, int length, int shift)
     
    static void
    shuffle(float[] array)
     
    static void
    shuffle(float[] array, int offset, int length)
    shuffles the given array
    static void
    shuffle(int[] array)
     
    static void
    shuffle(int[] array, int offset, int length)
    shuffles the given array
    static void
    shuffle(Object[] array)
     
    static void
    shuffle(Object[] array, int offset, int length)
    shuffles the given array
    static String
    toString(float[] array)
     
    static String
    toString(float[] array, int offset, int length)
     
    static String
    toString(float[] array, int offset, int length, String separator)
    a more sophisticated version of Arrays.toString(Object[])
    static String
    toString(float[] array, String separator)
     
    static String
    toString(int[] array)
     
    static String
    toString(int[] array, int offset, int length)
     
    static String
    toString(int[] array, int offset, int length, String separator)
    a more sophisticated version of Arrays.toString(Object[])
    static String
    toString(int[] array, String separator)
     
    static String
    toString(Object[] array)
     
    static String
    toString(Object[] array, int offset, int length)
     
    static String
    toString(Object[] array, int offset, int length, String separator)
    a more sophisticated version of Arrays.toString(Object[])
    static String
    toString(Object[] array, String separator)
     
    static boolean[]
    unbox(Boolean[] values)
     
    static float[]
    unbox(Float[] values)
     
    static int[]
    unbox(Integer[] values)
     

    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

    • toString

      public static String toString(Object[] array)
      See Also:
    • toString

      public static String toString(Object[] array, String separator)
      See Also:
    • toString

      public static String toString(Object[] array, int offset, int length)
      See Also:
    • toString

      public static String toString(Object[] array, int offset, int length, String separator)
      a more sophisticated version of Arrays.toString(Object[])
    • toString

      public static String toString(int[] array)
      See Also:
    • toString

      public static String toString(int[] array, String separator)
      See Also:
    • toString

      public static String toString(int[] array, int offset, int length)
      See Also:
    • toString

      public static String toString(int[] array, int offset, int length, String separator)
      a more sophisticated version of Arrays.toString(Object[])
    • toString

      public static String toString(float[] array)
      See Also:
    • toString

      public static String toString(float[] array, String separator)
      See Also:
    • toString

      public static String toString(float[] array, int offset, int length)
      See Also:
    • toString

      public static String toString(float[] array, int offset, int length, String separator)
      a more sophisticated version of Arrays.toString(Object[])
    • getRepeated

      public static <T> T getRepeated(T[] array, int index)
      Parameters:
      array - the array from which to access a value at the wrapped index
      Returns:
      the value at the wrapped index
      See Also:
    • getRepeated

      public static int getRepeated(int[] array, int index)
      See Also:
    • getRepeated

      public static float getRepeated(float[] array, int index)
      See Also:
    • repeat

      public static int repeat(int length, int index)
      See Also:
    • repeat

      public static int repeat(int offset, int length, int index)
      Repeats the given index within the given length (of an array). For example for a length of 10:
      index and return value
      indexreturns
      00
      55
      100
      155
      200
      555
      Parameters:
      length - the length of the array
      index - the index to repeat
      Returns:
      the repeated index
    • contains

      public static <T> boolean contains(T[] array, T value, boolean identity)
      Parameters:
      array - the array that may contain the given value
      value - the value to search for in the given array
      identity - if == comparison should be used instead of equals(Object)
      Returns:
      if the given value is contained in the given array
    • contains

      public static <T, T2 extends T> boolean contains(T[] array, T2[] other, boolean identity)
      Type Parameters:
      T - the type of the containing array
      T2 - the type of the contained array
      Parameters:
      array - the array to check if it contains the other array's values
      other - the array to check if it is contained in the other array
      Returns:
      if the second given array's values are completely contained in the first array
    • containsAny

      public static <T, T2 extends T> boolean containsAny(T[] array, T2[] other, boolean identity)
      Type Parameters:
      T - the type of the containing array
      T2 - the type of the contained array
      Parameters:
      array - the array to check if it contains the other array's values
      other - the array to check if any of its values is contained in the other array
      Returns:
      if any value from the second array is contained in the first array
    • regionEquals

      public static boolean regionEquals(Object[] array, int offset, int length, Object[] other, int otherOffset, boolean identity)
      Parameters:
      offset - the region offset in the array
      length - the region length in the array
      otherOffset - the region offset in the other array
      identity - if == comparison should be used instead of equals(Object)
      Returns:
      whether the specified region in both arrays matches
      Since:
      0.13.5
    • regionEquals

      public static boolean regionEquals(Object[] array, int offset, int length, Object[] other, boolean identity)
      See Also:
    • regionEquals

      public static boolean regionEquals(Object[] array, int offset, Object[] other, boolean identity)
      See Also:
    • regionEquals

      public static boolean regionEquals(long[] array, int offset, int length, long[] other, int otherOffset)
      See Also:
    • regionEquals

      public static boolean regionEquals(long[] array, int offset, int length, long[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(long[] array, int offset, long[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(int[] array, int offset, int length, int[] other, int otherOffset)
      See Also:
    • regionEquals

      public static boolean regionEquals(int[] array, int offset, int length, int[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(int[] array, int offset, int[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(double[] array, int offset, int length, double[] other, int otherOffset, double epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(double[] array, int offset, int length, double[] other, double epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(double[] array, int offset, double[] other, double epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(float[] array, int offset, int length, float[] other, int otherOffset, float epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(float[] array, int offset, int length, float[] other, float epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(float[] array, int offset, float[] other, float epsilon)
      See Also:
    • regionEquals

      public static boolean regionEquals(short[] array, int offset, int length, short[] other, int otherOffset)
      See Also:
    • regionEquals

      public static boolean regionEquals(short[] array, int offset, int length, short[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(short[] array, int offset, short[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(byte[] array, int offset, int length, byte[] other, int otherOffset)
      See Also:
    • regionEquals

      public static boolean regionEquals(byte[] array, int offset, int length, byte[] other)
      See Also:
    • regionEquals

      public static boolean regionEquals(byte[] array, int offset, byte[] other)
      See Also:
    • equalsAny

      public static boolean equalsAny(Object obj, Object[] array, int offset, int length)
      Parameters:
      obj - the object to compare
      array - the array which items to compare
      Returns:
      if the given object equals any of the items in the given array
    • equalsAny

      public static boolean equalsAny(Object obj, Object[] array)
      See Also:
    • shift

      public static void shift(Object[] array, int shift)
      See Also:
    • shift

      public static void shift(Object[] array, int offset, int length, int shift)
      Parameters:
      array - the array to shift
      shift - The amount by which to shift. 1 means that every item will be moved 1 index to the right.
    • shift

      public static void shift(int[] array, int shift)
      See Also:
    • shift

      public static void shift(int[] array, int offset, int length, int shift)
      Parameters:
      array - the array to shift
      shift - The amount by which to shift. 1 means that every item will be moved 1 index to the right.
    • shift

      public static void shift(float[] array, int shift)
      See Also:
    • shift

      public static void shift(float[] array, int offset, int length, int shift)
      Parameters:
      array - the array to shift
      shift - The amount by which to shift. 1 means that every item will be moved 1 index to the right.
    • shuffle

      public static void shuffle(Object[] array)
      See Also:
    • shuffle

      public static void shuffle(Object[] array, int offset, int length)
      shuffles the given array
      Parameters:
      array - the array to shuffle
    • shuffle

      public static void shuffle(int[] array)
      See Also:
    • shuffle

      public static void shuffle(int[] array, int offset, int length)
      shuffles the given array
      Parameters:
      array - the array to shuffle
    • shuffle

      public static void shuffle(float[] array)
      See Also:
    • shuffle

      public static void shuffle(float[] array, int offset, int length)
      shuffles the given array
      Parameters:
      array - the array to shuffle
    • unbox

      public static float[] unbox(Float[] values)
      Returns:
      an array of the unboxed values from the given values
      See Also:
    • box

      public static Float[] box(float[] values)
      Returns:
      an array of the boxed values from the given values
      See Also:
    • unbox

      public static int[] unbox(Integer[] values)
      Returns:
      an array of the unboxed values from the given values
      See Also:
    • box

      public static Integer[] box(int[] values)
      Returns:
      an array of the boxed values from the given values
      See Also:
    • unbox

      public static boolean[] unbox(Boolean[] values)
      Returns:
      an array of the unboxed values from the given values
      See Also:
    • box

      public static Boolean[] box(boolean[] values)
      Returns:
      an array of the boxed values from the given values
      See Also:
    • checkRegion

      public static void checkRegion(Object[] array, int offset, int length)
      Throws:
      ArrayIndexOutOfBoundsException - if an invalid region is specified
      IllegalArgumentException - if the array is null
    • requireCapacity

      public static void requireCapacity(Object[] source, int offset, int length, Object[] dest, int destOffset)
      throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
      Throws:
      ArrayIndexOutOfBoundsException
      IllegalArgumentException
      See Also:
    • selectCount

      public static int selectCount(int offset, int length, int start, int everyXth)
      Parameters:
      offset - the index at which the array interval to use
      length - the length of the array interval to use
      start - the index at which to start (may be negative)
      everyXth - select every xth item
      Returns:
      the capacity needed in the output array
      See Also:
    • select

      public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth, T[] dest, int destOffset)
      Parameters:
      items - the items to select from
      start - the array index at which to start (may be negative)
      everyXth - select every xth of items
      dest - The array to put the values in. Must have at least the capacity returned by selectCount.
      Returns:
      the dest array containing everyXth item of the given items array
      Throws:
      IllegalArgumentException - if the given dest array is not null and smaller than the required length
    • select

      public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth, T[] dest)
      See Also:
    • select

      public static <T> T[] select(T[] items, int start, int everyXth, T[] dest)
      See Also:
    • select

      public static <T> T[] select(T[] items, int everyXth, T[] dest)
      See Also:
    • select

      public static <T> T[] select(T[] items, int offset, int length, int start, int everyXth)
      See Also:
    • select

      public static <T> T[] select(T[] items, int start, int everyXth)
      See Also:
    • select

      public static <T> T[] select(T[] items, int everyXth)
      See Also:
    • select

      public static <T> T[] select(T[] items, int[] indices, int indicesOffset, int indicesLength, T[] dest, int destOffset)
      Parameters:
      items - the items to select from
      indices - the indices to select
      dest - the array to fill
      Returns:
      the given dest array
    • select

      public static <T> T[] select(T[] items, int[] indices, T[] dest, int destOffset)
      See Also:
    • select

      public static <T> T[] select(T[] items, int[] indices, T[] dest)
      See Also:
    • select

      public static <T> T[] select(T[] items, int[] indices)
      See Also:
    • checkRegion

      public static void checkRegion(float[] array, int offset, int length)
      Throws:
      ArrayIndexOutOfBoundsException - if an invalid region is specified
      NullPointerException - if the array is null
    • requireCapacity

      public static void requireCapacity(float[] source, int offset, int length, float[] dest, int destOffset)
      throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
      Throws:
      ArrayIndexOutOfBoundsException
      IllegalArgumentException
      See Also:
    • select

      public static float[] select(float[] items, int offset, int length, int start, int everyXth, float[] dest, int destOffset)
      Parameters:
      items - the items to select from
      start - the array index at which to start (may be negative)
      everyXth - select every xth of items
      dest - The array to put the values in. Must have at least the capacity returned by selectCount.
      Returns:
      the dest array containing everyXth item of the given items array
      Throws:
      IllegalArgumentException - if the given dest array is not null and smaller than the required length
    • select

      public static float[] select(float[] items, int offset, int length, int start, int everyXth, float[] dest)
      See Also:
    • select

      public static float[] select(float[] items, int start, int everyXth, float[] dest)
      See Also:
    • select

      public static float[] select(float[] items, int everyXth, float[] dest)
      See Also:
    • select

      public static float[] select(float[] items, int offset, int length, int start, int everyXth)
      See Also:
    • select

      public static float[] select(float[] items, int start, int everyXth)
      See Also:
    • select

      public static float[] select(float[] items, int everyXth)
      See Also:
    • select

      public static float[] select(float[] items, int[] indices, int indicesOffset, int indicesLength, float[] dest, int destOffset)
      Parameters:
      items - the items to select from
      indices - the indices to select
      dest - the array to fill
      Returns:
      the given dest array
    • select

      public static float[] select(float[] items, int[] indices, float[] dest, int destOffset)
      See Also:
    • select

      public static float[] select(float[] items, int[] indices, float[] dest)
      See Also:
    • select

      public static float[] select(float[] items, int[] indices)
      See Also:
    • checkRegion

      public static void checkRegion(int[] array, int offset, int length)
      Throws:
      ArrayIndexOutOfBoundsException - if an invalid region is specified
      IllegalArgumentException - if the array is null
    • requireCapacity

      public static void requireCapacity(int[] source, int offset, int length, int[] dest, int destOffset)
      throws an appropriate exception if the specified region of the source array cannot be copied to the destination array starting at the given offset
      Throws:
      ArrayIndexOutOfBoundsException
      IllegalArgumentException
      See Also:
    • select

      public static int[] select(int[] items, int offset, int length, int start, int everyXth, int[] dest, int destOffset)
      Parameters:
      items - the items to select from
      start - the array index at which to start (may be negative)
      everyXth - select every xth of items
      dest - The array to put the values in. Must have at least the capacity returned by selectCount.
      Returns:
      the dest array containing everyXth item of the given items array
      Throws:
      IllegalArgumentException - if the given dest array is not null and smaller than the required length
    • select

      public static int[] select(int[] items, int offset, int length, int start, int everyXth, int[] dest)
      See Also:
    • select

      public static int[] select(int[] items, int start, int everyXth, int[] dest)
      See Also:
    • select

      public static int[] select(int[] items, int everyXth, int[] dest)
      See Also:
    • select

      public static int[] select(int[] items, int offset, int length, int start, int everyXth)
      See Also:
    • select

      public static int[] select(int[] items, int start, int everyXth)
      See Also:
    • select

      public static int[] select(int[] items, int everyXth)
      See Also:
    • select

      public static int[] select(int[] items, int[] indices, int indicesOffset, int indicesLength, int[] dest, int destOffset)
      Parameters:
      items - the items to select from
      indices - the indices to select
      dest - the array to fill
      Returns:
      the given dest array
    • select

      public static int[] select(int[] items, int[] indices, int[] dest, int destOffset)
      See Also:
    • select

      public static int[] select(int[] items, int[] indices, int[] dest)
      See Also:
    • select

      public static int[] select(int[] items, int[] indices)
      See Also: