Package eu.simuline.octave.type.matrix
Class AbstractGenericMatrix<D,L extends List<?>>
- java.lang.Object
-
- eu.simuline.octave.type.matrix.AbstractGenericMatrix<D,L>
-
- Type Parameters:
D
- an array type, partially of primitive element typeL
- a list corresponding with the array of type D
- All Implemented Interfaces:
OctaveObject
- Direct Known Subclasses:
AbstractObjectMatrix
,OctaveBoolean
,OctaveDouble
,OctaveInt
,OctaveLong
public abstract class AbstractGenericMatrix<D,L extends List<?>> extends Object implements OctaveObject
A general matrix that does not even know that it is an array it stores its in.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractGenericMatrix(int... size)
Constructor that creates new blank matrix.protected
AbstractGenericMatrix(D dataA, int... size)
Constructor that reuses data in the new object.protected
AbstractGenericMatrix(AbstractGenericMatrix<D,L> o)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
checkDataSize(int dataLength)
Check that the overall size given by the product ofsize
does not exceed the length of the backed array.private void
checkSize()
Checks the fieldsize
: dimension at lest two and each entry non-negative.int
dataSize()
The number of data entries.boolean
equals(Object obj)
protected abstract D
getDataA()
Returns the data store as an array.abstract String
getPlainString(int pos)
Returns the string representation of the given plain position.int
getSize(int i)
int
getSizeLength()
int
hashCode()
protected abstract int
initL(D data, int size)
static void
main(String[] args)
protected abstract L
newL(int size)
Returns a new data store with given size and entries carrying the default value.int
pos2ind(int... pos)
private static int
product(int... ns)
void
resizeUp(int... pos)
Resize matrix up to include pos if necessary, i.e. if an entry ofpos
is greater than the according entry insize
.abstract void
setPlain(String value, int pos)
Sets the entry with plain positionpos
to value parsing the stringvalue
.abstract OctaveObject
shallowCopy()
Make a shallow copy of this object.String
toString()
-
-
-
Field Detail
-
PRIME
private static final int PRIME
- See Also:
- Constant Field Values
-
size
protected final int[] size
The dimensions, rows x columns x depth x ....
-
-
Constructor Detail
-
AbstractGenericMatrix
protected AbstractGenericMatrix(int... size)
Constructor that creates new blank matrix.- Parameters:
size
-
-
AbstractGenericMatrix
protected AbstractGenericMatrix(D dataA, int... size)
Constructor that reuses data in the new object.- Parameters:
dataA
- data as an arraysize
- must have at least two dimensions
-
AbstractGenericMatrix
protected AbstractGenericMatrix(AbstractGenericMatrix<D,L> o)
Copy constructor.- Parameters:
o
-
-
-
Method Detail
-
checkSize
private void checkSize() throws IllegalArgumentException
Checks the fieldsize
: dimension at lest two and each entry non-negative.- Throws:
IllegalArgumentException
-
checkDataSize
private void checkDataSize(int dataLength)
Check that the overall size given by the product ofsize
does not exceed the length of the backed array.
-
newL
protected abstract L newL(int size)
Returns a new data store with given size and entries carrying the default value. The latter depends on the types: false for boolean, 0 for int, 0.0 for double and null for GenericMatrix's.- Parameters:
size
-- Returns:
- new D[size]
-
initL
protected abstract int initL(D data, int size)
-
dataSize
public final int dataSize()
The number of data entries. Note that it is heavy load to compute this at the moment.
-
getDataA
protected abstract D getDataA()
Returns the data store as an array. There are subclasses with array of primitive types.
-
setPlain
public abstract void setPlain(String value, int pos)
Sets the entry with plain positionpos
to value parsing the stringvalue
. Note that this base class cannot provide setter methods for java's primitive data types.- Parameters:
value
-pos
- see e.g.AbstractObjectMatrix.setPlain(String, int)
andOctaveDouble.setPlain(String, int)
-
product
private static int product(int... ns)
- Parameters:
ns
-- Returns:
- product of ns
-
resizeUp
public final void resizeUp(int... pos)
Resize matrix up to include pos if necessary, i.e. if an entry ofpos
is greater than the according entry insize
.- Parameters:
pos
- an index vector with same dimension assize
- Throws:
UnsupportedOperationException
- ifpos
has dimension other than that ofsize
.
-
pos2ind
public final int pos2ind(int... pos)
- Parameters:
pos
-- Returns:
- the index into data() for the position
-
getPlainString
public abstract String getPlainString(int pos)
Returns the string representation of the given plain position.
-
getSizeLength
public final int getSizeLength()
-
getSize
public final int getSize(int i)
- Parameters:
i
- dimension number in 1 based numbering, 1=row, 2=column- Returns:
- the size in dimension i
-
shallowCopy
public abstract OctaveObject shallowCopy()
Description copied from interface:OctaveObject
Make a shallow copy of this object. In general when anOctaveObject
is returned from a getter, e.g. onOctaveStruct
orOctaveStruct
, a shallow copy is returned in order to follow the way octave behaves. This method is used to make that copy.- Specified by:
shallowCopy
in interfaceOctaveObject
- Returns:
- a shallow copy of this
-
main
public static void main(String[] args)
-
-