Package ch.systemsx.cisd.base.mdarray
Class MDAbstractArray<T>
- java.lang.Object
-
- ch.systemsx.cisd.base.mdarray.MDAbstractArray<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<MDAbstractArray.ArrayEntry>
- Direct Known Subclasses:
MDArray
,MDByteArray
,MDDoubleArray
,MDFloatArray
,MDIntArray
,MDLongArray
,MDShortArray
public abstract class MDAbstractArray<T> extends java.lang.Object implements java.io.Serializable, java.lang.Iterable<MDAbstractArray.ArrayEntry>
Base class of a multi-dimensional array. The dimensions of an array are provided separately from the data as aint[]
.The array can grow or shrink in the first dimension (dimensions[0]). Dimensions
1...n
are static. They are said to form a hyper-row.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MDAbstractArray.ArrayEntry
A class to represent an entry (index and value) of aMDArray
, used for iteration.
-
Field Summary
Fields Modifier and Type Field Description protected int
capacityHyperRows
protected int[]
dimensions
protected int
hyperRowLength
protected int
size
-
Constructor Summary
Constructors Modifier Constructor Description protected
MDAbstractArray(int[] dimensions, int arrayLength, int capacityHyperRows)
protected
MDAbstractArray(MDAbstractArray<T> template)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
adaptCapacityHyperRows()
abstract int
capacity()
Returns the capacity of elements in the array.protected int
computeHyperRowLength(int[] dimensions)
int
computeIndex(int... indices)
Computes the linear index for the multi-dimensional indices provided.int
computeIndex(int indexX, int indexY)
Computes the linear index for the two-dimensional (indexX, indexY) provided.int
computeIndex(int indexX, int indexY, int indexZ)
Computes the linear index for the three-dimensional (indexX, indexY, indexZ) provided.int[]
computeReverseIndex(int linearIndex)
Computes the multi-dimensional index from the linearIndex.int
decNumberOfHyperRows(int count)
Decrease the number of hyper-rows by count.int[]
dimensions()
Returns a copy of the dimensions of the multi-dimensional array.abstract java.lang.Object
getAsFlatArray()
Returns the array in flattened form.abstract T
getAsObject(int linearIndex)
Return an object which has the same value as the element of the array specified by linearIndex.abstract T
getAsObject(int... indices)
Return an object which has the same value as the element of the array specified by indices.abstract java.lang.Object
getCopyAsFlatArray()
Returns a copy of the array in flattened form.static int
getLength(int[] dimensions)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.static int
getLength(int[] dimensions, int capacityHyperRows)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.static int
getLength(long[] dimensions)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.static int
getLength(long[] dimensions, long capacityHyperRows)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.int
incNumberOfHyperRows(int count)
Increase the number of hyper-rows by count.java.util.Iterator<MDAbstractArray.ArrayEntry>
iterator()
long[]
longDimensions()
Returns a copy of the dimensions of the multi-dimensional array aslong[]
.int
numberOfHyperRows()
Returns the current number of hyper rows of of this array.int
rank()
Returns the rank of the array.abstract void
setToObject(T value, int linearIndex)
Sets the element of the array specified by linearIndex to the particular value.abstract void
setToObject(T value, int... indices)
Sets the element of the array specified by indices to the particular value.int
size()
Returns the number of elements in the array.int
size(int dim)
Returns the extent of the array along its dim-th axis.static int[]
toInt(long[] dimensions)
Converts the dimensions fromlong[]
toint[]
.static long[]
toLong(int[] dimensions)
Converts the dimensions fromint[]
tolong[]
.java.lang.String
toString()
-
-
-
Constructor Detail
-
MDAbstractArray
protected MDAbstractArray(int[] dimensions, int arrayLength, int capacityHyperRows)
-
MDAbstractArray
protected MDAbstractArray(MDAbstractArray<T> template)
-
-
Method Detail
-
computeHyperRowLength
protected int computeHyperRowLength(int[] dimensions)
-
rank
public int rank()
Returns the rank of the array.
-
size
public int size(int dim)
Returns the extent of the array along its dim-th axis.
-
dimensions
public int[] dimensions()
Returns a copy of the dimensions of the multi-dimensional array.
-
longDimensions
public long[] longDimensions()
Returns a copy of the dimensions of the multi-dimensional array aslong[]
.
-
size
public int size()
Returns the number of elements in the array.
-
numberOfHyperRows
public int numberOfHyperRows()
Returns the current number of hyper rows of of this array.
-
getAsObject
public abstract T getAsObject(int linearIndex)
Return an object which has the same value as the element of the array specified by linearIndex.- Parameters:
linearIndex
- The index in the linear array returned bygetAsFlatArray()
.- Returns:
- The value at the specified index.
-
getAsObject
public abstract T getAsObject(int... indices)
Return an object which has the same value as the element of the array specified by indices.
-
setToObject
public abstract void setToObject(T value, int... indices)
Sets the element of the array specified by indices to the particular value.
-
setToObject
public abstract void setToObject(T value, int linearIndex)
Sets the element of the array specified by linearIndex to the particular value.- Parameters:
value
- The new value to set.linearIndex
- The index in the linear array returned bygetAsFlatArray()
.
-
getAsFlatArray
public abstract java.lang.Object getAsFlatArray()
Returns the array in flattened form. Changes to the returned object will change the multi-dimensional array directly.
-
getCopyAsFlatArray
public abstract java.lang.Object getCopyAsFlatArray()
Returns a copy of the array in flattened form. Changes to the returned object will not change the multi-dimensional array directly.
-
adaptCapacityHyperRows
protected abstract void adaptCapacityHyperRows()
-
capacity
public abstract int capacity()
Returns the capacity of elements in the array.
-
incNumberOfHyperRows
public int incNumberOfHyperRows(int count)
Increase the number of hyper-rows by count. Doubles the capacity if needed.- Returns:
- The new number of rows.
-
decNumberOfHyperRows
public int decNumberOfHyperRows(int count)
Decrease the number of hyper-rows by count.- Returns:
- The new number of rows.
-
computeIndex
public int computeIndex(int... indices)
Computes the linear index for the multi-dimensional indices provided.
-
computeReverseIndex
public int[] computeReverseIndex(int linearIndex)
Computes the multi-dimensional index from the linearIndex.
-
computeIndex
public int computeIndex(int indexX, int indexY)
Computes the linear index for the two-dimensional (indexX, indexY) provided.
-
computeIndex
public int computeIndex(int indexX, int indexY, int indexZ)
Computes the linear index for the three-dimensional (indexX, indexY, indexZ) provided.
-
toInt
public static int[] toInt(long[] dimensions)
Converts the dimensions fromlong[]
toint[]
.
-
toLong
public static long[] toLong(int[] dimensions)
Converts the dimensions fromint[]
tolong[]
.
-
getLength
public static int getLength(int[] dimensions)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.- Throws:
java.lang.IllegalArgumentException
- If dimensions overflow theint
type.
-
getLength
public static int getLength(int[] dimensions, int capacityHyperRows)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions. IfcapacityHyperRows > dimensions[0]
, then it will replace dimensions[0] by capacityHyperRows- Throws:
java.lang.IllegalArgumentException
- If dimensions overflow theint
type.
-
getLength
public static int getLength(long[] dimensions)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions.- Throws:
java.lang.IllegalArgumentException
- If dimensions overflow theint
type.
-
getLength
public static int getLength(long[] dimensions, long capacityHyperRows)
Returns the one-dimensional length of the multi-dimensional array defined by dimensions. IfcapacityHyperRows > dimensions[0]
, then it will replace dimensions[0] by capacityHyperRows- Throws:
java.lang.IllegalArgumentException
- If dimensions overflow theint
type.
-
iterator
public java.util.Iterator<MDAbstractArray.ArrayEntry> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-