Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.arrayND.ArrayND

java.lang.Object
  |
  +--ncsa.horizon.arrayND.ArrayND
Subclasses:
ChunkableArrayND

public abstract class ArrayND
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
an abstract wrapper class for holding and manipulating an N-dimensional array of arbitrary element type.

This abstract class provides a standard interface for accessing data in a virtual N-D array, regardless of how it is actually stored. This class does not assume that it has sole possesion of the array storage and therefore can not restrict updates to the data. ArrayND subclasses can store the data in different ways to optimize certain types of access.

The subclass may also implement a particular SingleObjectStorage interface that allows one to get a reference to the actual storage object. This can be used to allow objects to efficiently manipulate the data. The specific interface should specify exactly what that object is.

See Also:
ncsa.horizon.util.arrayND.SingleObjectStorage, Serialized Form

Field Summary
java.lang.Class elemClass
          the array element type
int[] size
          the size of the array
 
Constructor Summary
ArrayND(java.lang.Object array)
          create an array with a copy of this array
ArrayND(java.lang.Class type, int[] size)
          create an array with default values.
ArrayND()
          create an array whose type and size will be set by the subclass constructor
 
Method Summary
void checkBounds(int[] p)
          throw an NDArrayIndexOutOfBoundsException if the given index is out of the bounds of this array.
void checkBounds(int[] p, int[] sz)
          throw an NDArrayIndexOutOfBoundsException if the any index in the given subset is out of the bounds of this array.
void checkBounds(int[] p, int[] sz, int[] st)
          throw an NDArrayIndexOutOfBoundsException if the any index in the given subset is out of the bounds of this array.
void checkBounds(int[] p, int xaxis, int yaxis, int width, int height, int xstride, int ystride)
          throw an NDArrayIndexOutOfBoundsException if the any index in the given 2D subset is out of the bounds of this array.
void checkBounds(int[] p, int xaxis, int yaxis, int width, int height)
          throw an NDArrayIndexOutOfBoundsException if the any index in the given 2D subset is out of the bounds of this array.
java.lang.Object clone()
          create a mostly-deep clone of this array (elements of the array are not cloned).
static void copy(java.lang.Object src, int sstart, int slen, java.lang.Object dst, int dstart, int dlen, java.lang.Object defval)
          copy values from one 1-D array to another, filling missing values a given default.
void copyInto1DArray(int[] coordinate, int[] size, int[] stride, java.lang.Object array)
          copy a subset of the data into a raw, 1-dimensional array.
void copyInto1DArray(int[] coordinate, int[] size, java.lang.Object array)
          copy a subset of the data into a raw, multidimensional array.
void copyInto2DArray(int xaxis, int yaxis, int[] coord, int width, int height, int xstride, int ystride, java.lang.Object array)
          copy a 2-d subset of the data into a raw, 2-d array.
void copyInto2DArray(int xaxis, int yaxis, int[] coord, int width, int height, java.lang.Object array)
          copy a 2-d subset of the data into a raw, 2-d array.
void copyIntoArray(int[] coordinate, int[] size, int[] stride, java.lang.Object array)
          copy a subset of the data into a raw, multidimensional array
void copyIntoArray(int[] coordinate, int[] size, java.lang.Object array)
          copy a subset of the data into a raw, multidimensional array
java.lang.Object getArray(int[] coordinate, int[] size, int[] stride)
          return a multidimensional array containing a subset of the data
java.lang.Object getArray(int[] coordinate, int[] size)
          return a multidimensional array containing a subset of the data
java.lang.Object getArray()
          return a copy of the entire array as a multidimensional array
static java.lang.Object get(java.lang.Object array, int[] index)
          return an element from a raw multidimensional array.
ArrayND getArrayND(int[] coordinate, int[] size, int[] stride)
          return an ArrayND object containing a subset of the array data
ArrayND getArrayND(int[] coordinate, int[] size)
          return a multidimensional array containing a subset of the data
static int[] getArraySize(java.lang.Object array)
          calculate the size of a multidimensional array.
int getDimensionality()
          return the number of dimensions or axes in this multidimensional array.
static int getDimensionality(java.lang.Object array)
          determine the number dimensions covered by an array
static int getDimensionality(java.lang.String classname)
          determine the number dimensions covered by an array
java.lang.Object getElement(int[] coordinate)
          return an element from the array at a given coordinate.
static java.lang.Class getElementType(java.lang.Object array)
          determine the Class of the element of a multi-dimensional array
int getLength(int axis)
          return the length of the array along a given axis
static char getNameByPrimitiveClass(java.lang.Class cl)
          Converts the numeric Class into a char
static java.lang.Class getPrimitiveClassByName(char c)
           
int[] getSize()
          return the number of elements along each axis of the array
int getTotalSize()
          return the total number of elements in this multidimensional array
java.lang.Class getType()
          return the class type of the array elements
static void initialize(java.lang.Object array, java.lang.Object val)
          initialize a 1-D array with a given value
static void initialize(java.lang.Object array, int start, int length, java.lang.Object val)
          initialize a 1-D array with a given value
static void set(java.lang.Object array, int[] index, java.lang.Object value)
          set an element within a raw multidimensional array.
void setElement(int[] coordinate, java.lang.Object value)
          set an element of the array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

elemClass

protected transient java.lang.Class elemClass
the array element type

size

protected int[] size
the size of the array
Constructor Detail

ArrayND

protected ArrayND(java.lang.Object array)
create an array with a copy of this array

ArrayND

protected ArrayND(java.lang.Class type,
                  int[] size)
create an array with default values.

ArrayND

protected ArrayND()
create an array whose type and size will be set by the subclass constructor
Method Detail

getNameByPrimitiveClass

protected static char getNameByPrimitiveClass(java.lang.Class cl)
Converts the numeric Class into a char

getPrimitiveClassByName

protected static java.lang.Class getPrimitiveClassByName(char c)

getType

public final java.lang.Class getType()
return the class type of the array elements

getDimensionality

public final int getDimensionality()
return the number of dimensions or axes in this multidimensional array.

getSize

public final int[] getSize()
return the number of elements along each axis of the array

getTotalSize

public final int getTotalSize()
return the total number of elements in this multidimensional array

checkBounds

protected final void checkBounds(int[] p)
                         throws NDArrayIndexOutOfBoundsException
throw an NDArrayIndexOutOfBoundsException if the given index is out of the bounds of this array.

checkBounds

protected final void checkBounds(int[] p,
                                 int[] sz)
                         throws NDArrayIndexOutOfBoundsException
throw an NDArrayIndexOutOfBoundsException if the any index in the given subset is out of the bounds of this array. This method does this by checking position

and

+ -<1>.

Parameters:
p - origin of subset
sz - size of subset

checkBounds

protected final void checkBounds(int[] p,
                                 int[] sz,
                                 int[] st)
                         throws NDArrayIndexOutOfBoundsException
throw an NDArrayIndexOutOfBoundsException if the any index in the given subset is out of the bounds of this array. This method does this by checking position

and

+ . - <1>.

Parameters:
p - origin of subset
sz - size of subset

checkBounds

protected final void checkBounds(int[] p,
                                 int xaxis,
                                 int yaxis,
                                 int width,
                                 int height,
                                 int xstride,
                                 int ystride)
                         throws NDArrayIndexOutOfBoundsException
throw an NDArrayIndexOutOfBoundsException if the any index in the given 2D subset is out of the bounds of this array. This method does this by checking position

and

+ . - <1>.

Parameters:
p - origin of subset
xaxis - the index of the axis to be copied to the first dimension
yaxis - the index of the axis to be copied to the second dimension
width - the size of the array in the first direction
height - the size of the array in the second direction
xstride - the sampling to use along the first axis
ystride - the sampling to use along the second axis

checkBounds

protected final void checkBounds(int[] p,
                                 int xaxis,
                                 int yaxis,
                                 int width,
                                 int height)
                         throws NDArrayIndexOutOfBoundsException
throw an NDArrayIndexOutOfBoundsException if the any index in the given 2D subset is out of the bounds of this array. This method does this by checking position

and

+ - <1>.

Parameters:
p - origin of subset
xaxis - the index of the axis to be copied to the first dimension
yaxis - the index of the axis to be copied to the second dimension
width - the size of the array in the first direction
height - the size of the array in the second direction

getLength

public final int getLength(int axis)
return the length of the array along a given axis

getElement

public abstract java.lang.Object getElement(int[] coordinate)
                                    throws NDArrayIndexOutOfBoundsException
return an element from the array at a given coordinate. This method should not alter the elements in the input array.

setElement

public abstract void setElement(int[] coordinate,
                                java.lang.Object value)
                        throws NDArrayIndexOutOfBoundsException
set an element of the array. This method should not alter the elements in the input array.
Throws:
java.lang.IllegalArgumentException - if value if of the incorrect type.

getArray

public final java.lang.Object getArray(int[] coordinate,
                             int[] size,
                             int[] stride)
                               throws NDArrayIndexOutOfBoundsException
return a multidimensional array containing a subset of the data
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
stride - the sampling along each dimension.

getArray

public final java.lang.Object getArray(int[] coordinate,
                             int[] size)
                               throws NDArrayIndexOutOfBoundsException
return a multidimensional array containing a subset of the data
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension

getArray

public final java.lang.Object getArray()
return a copy of the entire array as a multidimensional array

getArrayND

public abstract ArrayND getArrayND(int[] coordinate,
                                   int[] size,
                                   int[] stride)
                                                throws NDArrayIndexOutOfBoundsException
return an ArrayND object containing a subset of the array data
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
stride - the sampling along each dimension.

getArrayND

public abstract ArrayND getArrayND(int[] coordinate,
                                   int[] size)
                                                throws NDArrayIndexOutOfBoundsException
return a multidimensional array containing a subset of the data
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension

copyIntoArray

public abstract void copyIntoArray(int[] coordinate,
                                   int[] size,
                                   int[] stride,
                                   java.lang.Object array)
                           throws NDArrayIndexOutOfBoundsException
copy a subset of the data into a raw, multidimensional array
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
stride - the sampling along each dimension.
array - the array to copy data into. This should be sufficient size and dimensionality to hold requested data.

copyIntoArray

public abstract void copyIntoArray(int[] coordinate,
                                   int[] size,
                                   java.lang.Object array)
                           throws NDArrayIndexOutOfBoundsException
copy a subset of the data into a raw, multidimensional array
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
array - the array to copy data into. This should be sufficient size and dimensionality to hold requested data.

copyInto1DArray

public abstract void copyInto1DArray(int[] coordinate,
                                     int[] size,
                                     int[] stride,
                                     java.lang.Object array)
                             throws NDArrayIndexOutOfBoundsException
copy a subset of the data into a raw, 1-dimensional array. The multi-dimensions of this array will be flattened to fit in the 1-d output array: data from the most rapidly changing axis will be copied first.
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
stride - the sampling along each dimension.
array - the 1-D array to copy data into. This should be sufficient size to hold requested data.

copyInto1DArray

public abstract void copyInto1DArray(int[] coordinate,
                                     int[] size,
                                     java.lang.Object array)
                             throws NDArrayIndexOutOfBoundsException
copy a subset of the data into a raw, multidimensional array. The multi-dimensions of this array will be flattened to fit in the 1-d output array: data from the most rapidly changing axis will be copied first.
Parameters:
coordinate - the origin of the array subset
size - the length of the subset along each dimension
array - the array to copy data into. This should be sufficient size and dimensionality to hold requested data.

copyInto2DArray

public abstract void copyInto2DArray(int xaxis,
                                     int yaxis,
                                     int[] coord,
                                     int width,
                                     int height,
                                     int xstride,
                                     int ystride,
                                     java.lang.Object array)
                             throws NDArrayIndexOutOfBoundsException
copy a 2-d subset of the data into a raw, 2-d array.
Parameters:
xaxis - the index of the axis to be copied to the first dimension
yaxis - the index of the axis to be copied to the second dimension
coord - the start position
width - the size of the array in the first direction
height - the size of the array in the second direction
xstride - the sampling to use along the first axis
ystride - the sampling to use along the second axis

copyInto2DArray

public abstract void copyInto2DArray(int xaxis,
                                     int yaxis,
                                     int[] coord,
                                     int width,
                                     int height,
                                     java.lang.Object array)
                             throws NDArrayIndexOutOfBoundsException
copy a 2-d subset of the data into a raw, 2-d array.
Parameters:
xaxis - the index of the axis to be copied to the first dimension
yaxis - the index of the axis to be copied to the second dimension
coord - the start position
width - the size of the array in the first direction
height - the size of the array in the second direction

clone

public java.lang.Object clone()
create a mostly-deep clone of this array (elements of the array are not cloned).
Overrides:
clone in class java.lang.Object

getDimensionality

public static final int getDimensionality(java.lang.Object array)
determine the number dimensions covered by an array
Parameters:
array - the array in question

getDimensionality

public static final int getDimensionality(java.lang.String classname)
determine the number dimensions covered by an array
Parameters:
classname - the string representation of class

getElementType

public static final java.lang.Class getElementType(java.lang.Object array)
determine the Class of the element of a multi-dimensional array

getArraySize

public static final int[] getArraySize(java.lang.Object array)
calculate the size of a multidimensional array. This assumes that the array is rectangular.

get

public static final java.lang.Object get(java.lang.Object array,
                               int[] index)
return an element from a raw multidimensional array.
Parameters:
array - the multidimensional array
index - the multidimensional index. The number of elements must equal that of the dimensionality of array. The indices should be in the order that one would give to an array-type object using [], e.g. an index of { 1, 2, 3 } corresponds to array[1][2][3].
Throws:
java.lang.IllegalArgumentException - if array is not a multidimensional array of index.length dimensionality.
java.lang.ArrayIndexOutOfBoundsException - if any element of index is out of range

set

public static final void set(java.lang.Object array,
                             int[] index,
                             java.lang.Object value)
                     throws NDArrayIndexOutOfBoundsException
set an element within a raw multidimensional array.
Parameters:
array - the multidimensional array
index - the multidimensional index. The number of elements must equal that of the dimensionality of array. The indices should be in the order that one would give to an array-type object using [], e.g. an index of { 1, 2, 3 } corresponds to array[1][2][3].
value - the value to set the element to. If the array holds values of a primitive type, this value should be of its corresponding wrapper type.
Throws:
java.lang.IllegalArgumentException - if array is not a multidimensional array of index.length dimensionality.
java.lang.ArrayIndexOutOfBoundsException - if any element of index is out of range

initialize

public static final void initialize(java.lang.Object array,
                                    java.lang.Object val)
                            throws java.lang.IllegalArgumentException
initialize a 1-D array with a given value

initialize

public static final void initialize(java.lang.Object array,
                                    int start,
                                    int length,
                                    java.lang.Object val)
                            throws java.lang.IllegalArgumentException
initialize a 1-D array with a given value

copy

public static final void copy(java.lang.Object src,
                              int sstart,
                              int slen,
                              java.lang.Object dst,
                              int dstart,
                              int dlen,
                              java.lang.Object defval)
                      throws java.lang.IllegalArgumentException
copy values from one 1-D array to another, filling missing values a given default. That is if slen < dlen, values in dst with index greater than dstart+slen will be set to defval. If slen > dlen, the extra values will be ignored. src can be null, meaning set all destination values to the default.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD