toxi.util.datatypes
Class ArrayUtil

java.lang.Object
  extended by toxi.util.datatypes.ArrayUtil

public class ArrayUtil
extends java.lang.Object

A collection of array utilities.

Author:
toxi

Constructor Summary
ArrayUtil()
           
 
Method Summary
static
<T> void
addArrayToCollection(T[] array, java.util.Collection<T> collection)
          Adds all array elements to the given collection of the same type.
static
<T> java.util.ArrayList<T>
arrayToList(T[] array)
          Converts the generic array into an ArrayList of the same type.
static int indexInArray(float needle, float[] stack, int maxLen)
          Returns the index of the element where the given value is found in the array.
static int indexInArray(int needle, int[] stack, int maxLen)
          Returns the index of the element where the given value is found in the array.
static void reverse(byte[] array)
          Reverses the item order of the supplied byte array.
static void reverse(char[] array)
          Reverses the item order of the supplied char array.
static void reverse(float[] array)
          Reverses the item order of the supplied float array.
static void reverse(int[] array)
          Reverses the item order of the supplied int array.
static void reverse(short[] array)
          Reverses the item order of the supplied short array.
static
<T> void
reverse(T[] array)
          Reverses the item order of the supplied array (generic types).
static
<T> void
shuffle(T[] array)
          Rearranges the array items in random order using the default java.util.Random generator.
static
<T> void
shuffle(T[] array, java.util.Random rnd)
          Rearranges the array items in random order using the given RNG.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtil

public ArrayUtil()
Method Detail

addArrayToCollection

public static <T> void addArrayToCollection(T[] array,
                                            java.util.Collection<T> collection)
Adds all array elements to the given collection of the same type.

Type Parameters:
T -
Parameters:
array - array
collection - existing collection or null (to create a new ArrayList automatically)

arrayToList

public static <T> java.util.ArrayList<T> arrayToList(T[] array)
Converts the generic array into an ArrayList of the same type.

Parameters:
array -
Returns:
array list version

indexInArray

public static int indexInArray(float needle,
                               float[] stack,
                               int maxLen)
Returns the index of the element where the given value is found in the array.

Parameters:
needle - number to find
stack - array to search
maxLen - number of elements to search
Returns:
array index or -1 if value couldn't be found in array

indexInArray

public static int indexInArray(int needle,
                               int[] stack,
                               int maxLen)
Returns the index of the element where the given value is found in the array.

Parameters:
needle - number to find
stack - array to search
maxLen - number of elements to search
Returns:
array index or -1 if value couldn't be found in array

reverse

public static void reverse(byte[] array)
Reverses the item order of the supplied byte array.

Parameters:
array -

reverse

public static void reverse(char[] array)
Reverses the item order of the supplied char array.

Parameters:
array -

reverse

public static void reverse(float[] array)
Reverses the item order of the supplied float array.

Parameters:
array -

reverse

public static void reverse(int[] array)
Reverses the item order of the supplied int array.

Parameters:
array -

reverse

public static void reverse(short[] array)
Reverses the item order of the supplied short array.

Parameters:
array -

reverse

public static <T> void reverse(T[] array)
Reverses the item order of the supplied array (generic types).

Parameters:
array -

shuffle

public static <T> void shuffle(T[] array)
Rearranges the array items in random order using the default java.util.Random generator. Operation is in-place, no copy is created.

Parameters:
array -

shuffle

public static <T> void shuffle(T[] array,
                               java.util.Random rnd)
Rearranges the array items in random order using the given RNG. Operation is in-place, no copy is created.

Parameters:
array -
rnd -