danger.util
Class ArrayUtils

java.lang.Object
  extended by danger.util.ArrayUtils


public final class ArrayUtils
extends Object

Generic array utilities.


Method Summary
static List<Integer> asList(int[] a)
          List adapter for primitive int array.
static
<T> T[]
extractUnique(T[] array)
          Filter duplicates out of an array.
static int idealByteArrayLength(int minSize)
          Return the "ideal length" for a byte[] that must be at least the given number of elements in length.
static int idealCharArrayLength(int minSize)
          Return the "ideal length" for a char[] that must be at least the given number of elements in length.
static int idealIntArrayLength(int minSize)
          Return the "ideal length" for an int[] that must be at least the given number of elements in length.
static int idealLongArrayLength(int minSize)
          Return the "ideal length" for a long[] that must be at least the given number of elements in length.
static int idealObjectArrayLength(int minSize)
          Return the "ideal length" for an Object[] (or subclass thereof) that must be at least the given number of elements in length.
static int idealShortArrayLength(int minSize)
          Return the "ideal length" for a short[] that must be at least the given number of elements in length.
static int lowerIdealByteArrayLength(int minSize)
          Return the portion of a byte[] of the specified size that would fit into an ideal-sized array.
static int[] toArray(Collection<Integer> c)
          Convert an Integer collection to an int[].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractUnique

public static <T> T[] extractUnique(T[] array)
Filter duplicates out of an array.

Since:
4.0

asList

public static List<Integer> asList(int[] a)
List adapter for primitive int array. Modified from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4348595

Since:
4.0
See Also:
java.util.Arrays.asList(T...)

toArray

public static int[] toArray(Collection<Integer> c)
Convert an Integer collection to an int[].

Since:
4.0
See Also:
java.util.Collection.toArray(T[])

idealByteArrayLength

public static int idealByteArrayLength(int minSize)
Return the "ideal length" for a byte[] that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

idealCharArrayLength

public static int idealCharArrayLength(int minSize)
Return the "ideal length" for a char[] that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

idealShortArrayLength

public static int idealShortArrayLength(int minSize)
Return the "ideal length" for a short[] that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

idealIntArrayLength

public static int idealIntArrayLength(int minSize)
Return the "ideal length" for an int[] that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

idealLongArrayLength

public static int idealLongArrayLength(int minSize)
Return the "ideal length" for a long[] that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

idealObjectArrayLength

public static int idealObjectArrayLength(int minSize)
Return the "ideal length" for an Object[] (or subclass thereof) that must be at least the given number of elements in length. This takes into account the underlying allocation strategy.

Parameters:
minSize - the minimum length of the array
Returns:
the ideal length for the array

lowerIdealByteArrayLength

public static int lowerIdealByteArrayLength(int minSize)
Return the portion of a byte[] of the specified size that would fit into an ideal-sized array.

Parameters:
minSize - the preferred length of the array
Returns:
the length for the array that would fit