Package ch.systemsx.cisd.base.mdarray
Class MDArray<T>
- java.lang.Object
-
- ch.systemsx.cisd.base.mdarray.MDAbstractArray<T>
-
- ch.systemsx.cisd.base.mdarray.MDArray<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<MDAbstractArray.ArrayEntry>
public class MDArray<T> extends MDAbstractArray<T>
A multi-dimensional array of generic typeT
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ch.systemsx.cisd.base.mdarray.MDAbstractArray
MDAbstractArray.ArrayEntry
-
-
Field Summary
-
Fields inherited from class ch.systemsx.cisd.base.mdarray.MDAbstractArray
capacityHyperRows, dimensions, hyperRowLength, size
-
-
Constructor Summary
Constructors Constructor Description MDArray(java.lang.Class<T> componentClass, int[] dimensions)
Creates an emptyMDArray
with the dimensions.MDArray(java.lang.Class<T> componentClass, int[] dimensions, int capacityHyperRows)
Creates an emptyMDArray
with the dimensions.MDArray(java.lang.Class<T> componentClass, long[] dimensions)
Creates an emptyMDArray
with the dimensions.MDArray(java.lang.Class<T> componentClass, long[] dimensions, long capacityHyperRows)
Creates an emptyMDArray
with the dimensions.MDArray(T[] flattenedArray, int[] dimensions)
MDArray(T[] flattenedArray, int[] dimensions, boolean checkdimensions)
Creates aMDArray
from the given flattenedArray and dimensions.MDArray(T[] flattenedArray, long[] dimensions)
MDArray(T[] flattenedArray, long[] dimensions, boolean checkdimensions)
Creates aMDArray
from the given flattenedArray and dimensions.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
adaptCapacityHyperRows()
int
capacity()
Returns the capacity of elements in the array.boolean
equals(java.lang.Object obj)
T
get(int index)
Returns the value of a one-dimensional array at the position defined by index.T
get(int... indices)
Returns the value of array at the position defined by indices.T
get(int indexX, int indexY)
Returns the value of a two-dimensional array at the position defined by indexX and indexY.T
get(int indexX, int indexY, int indexZ)
Returns the value of a three-dimensional array at the position defined by indexX, indexY and indexZ.T[]
getAsFlatArray()
Returns the array in flattened form.T
getAsObject(int linearIndex)
Return an object which has the same value as the element of the array specified by linearIndex.T
getAsObject(int... indices)
Return an object which has the same value as the element of the array specified by indices.java.lang.Class<T>
getComponentClass()
Returns the component type of this array.T[]
getCopyAsFlatArray()
Returns a copy of the array in flattened form.int
hashCode()
void
set(T value, int index)
Sets the value of a one-dimension array at the position defined by index.void
set(T value, int... indices)
Sets the value of array at the position defined by indices.void
set(T value, int indexX, int indexY)
Sets the value of a two-dimensional array at the position defined by indexX and indexY.void
set(T value, int indexX, int indexY, int indexZ)
Sets the value of a three-dimensional array at the position defined by indexX, indexY and indexZ.void
setToObject(T value, int linearIndex)
Sets the element of the array specified by linearIndex to the particular value.void
setToObject(T value, int... indices)
Sets the element of the array specified by indices to the particular value.-
Methods inherited from class ch.systemsx.cisd.base.mdarray.MDAbstractArray
computeHyperRowLength, computeIndex, computeIndex, computeIndex, computeReverseIndex, decNumberOfHyperRows, dimensions, getLength, getLength, getLength, getLength, incNumberOfHyperRows, iterator, longDimensions, numberOfHyperRows, rank, size, size, toInt, toLong, toString
-
-
-
-
Constructor Detail
-
MDArray
public MDArray(java.lang.Class<T> componentClass, long[] dimensions)
Creates an emptyMDArray
with the dimensions. Convenience method if dimensions are available aslong[]
.
-
MDArray
public MDArray(java.lang.Class<T> componentClass, long[] dimensions, long capacityHyperRows)
Creates an emptyMDArray
with the dimensions. IfcapacityHyperRows > dimensions[0]
, then it will create an array with a capacity of capacityHyperRows hyper-rows. Convenience method if dimensions are available aslong[]
.
-
MDArray
public MDArray(T[] flattenedArray, long[] dimensions)
Creates aMDArray
from the givenflattenedArray
anddimensions
. It is checked that the arguments are compatible. Convenience method if dimensions are available aslong[]
.
-
MDArray
public MDArray(T[] flattenedArray, long[] dimensions, boolean checkdimensions)
Creates aMDArray
from the given flattenedArray and dimensions. If checkDimensions istrue
, it is checked that the arguments are compatible. Convenience method if dimensions are available aslong[]
.
-
MDArray
public MDArray(java.lang.Class<T> componentClass, int[] dimensions)
Creates an emptyMDArray
with the dimensions.
-
MDArray
public MDArray(java.lang.Class<T> componentClass, int[] dimensions, int capacityHyperRows)
Creates an emptyMDArray
with the dimensions. IfcapacityHyperRows > dimensions[0]
, then it will create an array with a capacity of capacityHyperRows hyper-rows.
-
MDArray
public MDArray(T[] flattenedArray, int[] dimensions)
Creates aMDArray
from the givenflattenedArray
anddimensions
. It is checked that the arguments are compatible.
-
-
Method Detail
-
capacity
public int capacity()
Description copied from class:MDAbstractArray
Returns the capacity of elements in the array.- Specified by:
capacity
in classMDAbstractArray<T>
-
getAsObject
public T getAsObject(int... indices)
Description copied from class:MDAbstractArray
Return an object which has the same value as the element of the array specified by indices.- Specified by:
getAsObject
in classMDAbstractArray<T>
-
setToObject
public void setToObject(T value, int... indices)
Description copied from class:MDAbstractArray
Sets the element of the array specified by indices to the particular value.- Specified by:
setToObject
in classMDAbstractArray<T>
-
getAsObject
public T getAsObject(int linearIndex)
Description copied from class:MDAbstractArray
Return an object which has the same value as the element of the array specified by linearIndex.- Specified by:
getAsObject
in classMDAbstractArray<T>
- Parameters:
linearIndex
- The index in the linear array returned byMDAbstractArray.getAsFlatArray()
.- Returns:
- The value at the specified index.
-
setToObject
public void setToObject(T value, int linearIndex)
Description copied from class:MDAbstractArray
Sets the element of the array specified by linearIndex to the particular value.- Specified by:
setToObject
in classMDAbstractArray<T>
- Parameters:
value
- The new value to set.linearIndex
- The index in the linear array returned byMDAbstractArray.getAsFlatArray()
.
-
getAsFlatArray
public T[] getAsFlatArray()
Description copied from class:MDAbstractArray
Returns the array in flattened form. Changes to the returned object will change the multi-dimensional array directly.- Specified by:
getAsFlatArray
in classMDAbstractArray<T>
-
getCopyAsFlatArray
public T[] getCopyAsFlatArray()
Description copied from class:MDAbstractArray
Returns a copy of the array in flattened form. Changes to the returned object will not change the multi-dimensional array directly.- Specified by:
getCopyAsFlatArray
in classMDAbstractArray<T>
-
adaptCapacityHyperRows
protected void adaptCapacityHyperRows()
- Specified by:
adaptCapacityHyperRows
in classMDAbstractArray<T>
-
get
public T get(int... indices)
Returns the value of array at the position defined by indices.
-
get
public T get(int index)
Returns the value of a one-dimensional array at the position defined by index.Do not call for arrays other than one-dimensional!
-
get
public T get(int indexX, int indexY)
Returns the value of a two-dimensional array at the position defined by indexX and indexY.Do not call for arrays other than two-dimensional!
-
get
public T get(int indexX, int indexY, int indexZ)
Returns the value of a three-dimensional array at the position defined by indexX, indexY and indexZ.Do not call for arrays other than three-dimensional!
-
set
public void set(T value, int... indices)
Sets the value of array at the position defined by indices.
-
set
public void set(T value, int index)
Sets the value of a one-dimension array at the position defined by index.Do not call for arrays other than one-dimensional!
-
set
public void set(T value, int indexX, int indexY)
Sets the value of a two-dimensional array at the position defined by indexX and indexY.Do not call for arrays other than two-dimensional!
-
set
public void set(T value, int indexX, int indexY, int indexZ)
Sets the value of a three-dimensional array at the position defined by indexX, indexY and indexZ.Do not call for arrays other than three-dimensional!
-
getComponentClass
public java.lang.Class<T> getComponentClass()
Returns the component type of this array.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-