net.sf.jga.util
Class ArrayUtils

java.lang.Object
  extended by net.sf.jga.util.ArrayUtils

public class ArrayUtils
extends java.lang.Object

Miscellaneous utilities for working with arrays.

Copyright © 2004-2009 David A. Hall

Author:
David A. Hall

Nested Class Summary
static class ArrayUtils.ArrayIterable<T>
          Iterable wrapper around a given array.
static class ArrayUtils.ArrayIterator<T>
          Iterates over an array of objects.
 
Constructor Summary
ArrayUtils()
           
 
Method Summary
static
<T> T[]
allocate(java.lang.Class<? extends T[]> type, int len)
          Returns an uninitialized array of the given type, sized to the given length.
static
<T> T[]
insert(T[] arr, int idx, T... items)
          Returns an array containing the contents of the original array with the given items inserted at the given idx.
static
<T> java.lang.Iterable<T>
iterable(T[] ts)
          Adapts the array to the Iterable interface
static
<E> ArrayUtils.ArrayIterator<E>
iterate(E... arr)
          Produce an ArrayIterator over the given array.
static
<T> T[]
remove(T[] arr, int idx)
          Returns an array containing the contents of the original array with the given position removed; the size of the resulting array will be one less than the input array
static
<T> T[]
remove(T[] arr, int idx, int count)
          Returns an array containing the contents of the original array with the given positions removed; the size of the resulting array will be count less than the input array
static java.lang.String toString(java.lang.Object[] arr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

toString

public static java.lang.String toString(java.lang.Object[] arr)

insert

public static <T> T[] insert(T[] arr,
                             int idx,
                             T... items)
Returns an array containing the contents of the original array with the given items inserted at the given idx.

Type Parameters:
T - tye type of objects stored in the input array
Parameters:
arr - the input array
idx - the index at which to insert new items
items - the new items to be inserted.

remove

public static <T> T[] remove(T[] arr,
                             int idx)
Returns an array containing the contents of the original array with the given position removed; the size of the resulting array will be one less than the input array

Type Parameters:
T - tye type of objects stored in the input array
Parameters:
arr - the input array
idx - the index at which to insert new items

remove

public static <T> T[] remove(T[] arr,
                             int idx,
                             int count)
Returns an array containing the contents of the original array with the given positions removed; the size of the resulting array will be count less than the input array

Type Parameters:
T - tye type of objects stored in the input array
Parameters:
arr - the input array
idx - the index at which to insert new items
Throws:
java.lang.ArrayIndexOutOfBoundsException - if idx >= arr.length

allocate

public static <T> T[] allocate(java.lang.Class<? extends T[]> type,
                               int len)
Returns an uninitialized array of the given type, sized to the given length.

Type Parameters:
T - the type of objects to be stored in the array
Parameters:
type - the type of the array (ie, Array of T)
len - the length of the new array
Returns:

iterate

public static <E> ArrayUtils.ArrayIterator<E> iterate(E... arr)
Produce an ArrayIterator over the given array.


iterable

public static <T> java.lang.Iterable<T> iterable(T[] ts)
Adapts the array to the Iterable interface



Copyright © 2002-2006 David A. Hall. All Rights Reserved.