|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.data.ArrayUtilities
public class ArrayUtilities
Utility functions for manipulating arrays.
Constructor Summary | |
---|---|
protected |
ArrayUtilities()
Since this class is a static utility class, its sole constructor is protected. |
Method Summary | |
---|---|
static java.util.Collection |
addElements(java.util.Collection c,
java.lang.Object[] elements)
Add the elements in the argument array to the argument collection. |
static java.lang.Object[] |
arrayCopyWithoutNull(java.lang.Object[] src,
int srcPos,
java.lang.Object[] dest,
int destPos,
int length)
Copy up to length elements from the source array (starting
at index srcPos ) to the destination array (starting at
index destPos ). |
static java.util.List |
asList(int[] array)
Return a list of instances of Integer backed by the
argument array. |
static java.util.Collection |
fromMatrix(java.lang.Object[][] matrix,
ICollectionFactory factory,
boolean mustCopy)
Return a collection of collections representing the matrix. |
static java.util.LinkedList |
prependElements(java.lang.Object[] elements,
java.util.LinkedList list)
Add the elements in the array to the front of the argument list, in the order that they appear in the array (The first element of the array becomes the first element of the list). |
static java.lang.Object[] |
remove(java.lang.Object[] src,
java.lang.Object obj)
Remove all elements that match obj (via ==, not
equals() ) and return a possibly differently sized array
that just has the non-matching elements. |
static java.util.Collection |
removeElements(java.util.Collection c,
java.lang.Object[] elements)
Remove the elements in the argument array from the argument collection. |
static int[] |
resize(int[] array,
int size)
Resize the int array to have the argument size, truncating elements if necessary. |
static int[] |
resize(int[] array,
int size,
IIntMapper mapper)
Resize the int array to have the argument size, truncating elements if necessary. |
static java.lang.Object[][] |
toMatrix(java.util.Collection rows,
java.lang.Object[][] a)
Given a collection of sub-collections that represent row data, convert the collection into a 2D array with the same type as the argument matrix. |
static java.lang.String |
toString(int[] array)
Return the comma-separated string representing the elements of array , surrounded by brackets. |
static java.lang.Object[] |
unpack(java.util.Collection c,
java.lang.Object[] dest,
int startIndex)
Copy the elements in the collection to the argument array, starting from startIndex . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ArrayUtilities()
Method Detail |
---|
public static final java.util.LinkedList prependElements(java.lang.Object[] elements, java.util.LinkedList list)
public static final java.util.Collection addElements(java.util.Collection c, java.lang.Object[] elements)
c
- The collection to add to and return.elements
- An array of elements to add.
java.lang.NullPointerException
- if either c
or
elements
is null
public static final java.util.Collection removeElements(java.util.Collection c, java.lang.Object[] elements)
c
- The collection to remove from and return.elements
- An array of elements to remove.
java.lang.NullPointerException
- if either c
or
elements
is null
public static final java.lang.Object[] remove(java.lang.Object[] src, java.lang.Object obj)
obj
(via ==, not
equals()
) and return a possibly differently sized array
that just has the non-matching elements. This method may modify the
argument array, but if there are no matching elements, the array will
be returned unchanged.
public static final java.lang.Object[] arrayCopyWithoutNull(java.lang.Object[] src, int srcPos, java.lang.Object[] dest, int destPos, int length)
length
elements from the source array (starting
at index srcPos
) to the destination array (starting at
index destPos
). If an element in the source array is
null
, do not copy it; do not copy an additional source
element to compensate. Return dest
.
public static final java.lang.Object[][] toMatrix(java.util.Collection rows, java.lang.Object[][] a)
null
or too small,
allocate a new matrix with the same type that is big enough to hold the
data. If the argument matrix is null
, return a matrix
whose element type is Object
. If the argument matrix
is bigger than needed, set all unused locations to null
.
public static final java.lang.Object[] unpack(java.util.Collection c, java.lang.Object[] dest, int startIndex)
startIndex
. The argument array must be big enough or
else an ArrayIndexOutOfBoundsException
will be thrown.
Return the argument array.
public static final java.util.Collection fromMatrix(java.lang.Object[][] matrix, ICollectionFactory factory, boolean mustCopy)
matrix
have a different
number of elements, so will the return collection.
matrix
- The matrix to convert.factory
- The factory used to create the overall collection and
also the collections representing each row.mustCopy
- If false, each row vector will be a wrapper (see
Arrays.asList()
) over each row in the argument matrix.
This means if the returned collection is modified, it will be reflected
in the argument matrix. Also, this means that each row vector will not
be created by the factory. If true, each element will be copied into a
collection created by the factory.
java.lang.NullPointerException
- if matrix
or
factory
is null.public static final int[] resize(int[] array, int size)
size
is greater than the size of
array
, leave the additional elements set to zero. If
array
has the same size as size
, return
array
unchanged.
public static final int[] resize(int[] array, int size, IIntMapper mapper)
size
is greater than the size of
array
, set each element at the end of the array to be the
result of mapper.map(i)
, where i
is the index
of element in the returned array. If mapper is null
, leave
the elements set to zero. If array
has the same size as
size
, return array
unchanged.
public static final java.util.List asList(int[] array)
Integer
backed by the
argument array. Changes to the list are reflected in the argument
array. The returned list does not support the add()
or
remove()
methods. It implements Cloneable
,
RandomAccess
, and Serializable
. This method
does not allocate instances instances if Integer
right
away -- they are allocated on demand.
public static final java.lang.String toString(int[] array)
array
, surrounded by brackets. This is more efficient than
using StringListUtilities.createCollectionString()
, but
not as flexible.
array
- An array of integers
java.lang.NullPointerException
- if array
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |