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 protectedAbstractGenericMatrix(int... size)Constructor that creates new blank matrix.protectedAbstractGenericMatrix(D dataA, int... size)Constructor that reuses data in the new object.protectedAbstractGenericMatrix(AbstractGenericMatrix<D,L> o)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidcheckDataSize(int dataLength)Check that the overall size given by the product ofsizedoes not exceed the length of the backed array.private voidcheckSize()Checks the fieldsize: dimension at lest two and each entry non-negative.intdataSize()The number of data entries.booleanequals(Object obj)protected abstract DgetDataA()Returns the data store as an array.abstract StringgetPlainString(int pos)Returns the string representation of the given plain position.intgetSize(int i)intgetSizeLength()inthashCode()protected abstract intinitL(D data, int size)static voidmain(String[] args)protected abstract LnewL(int size)Returns a new data store with given size and entries carrying the default value.intpos2ind(int... pos)private static intproduct(int... ns)voidresizeUp(int... pos)Resize matrix up to include pos if necessary, i.e. if an entry ofposis greater than the according entry insize.abstract voidsetPlain(String value, int pos)Sets the entry with plain positionposto value parsing the stringvalue.abstract OctaveObjectshallowCopy()Make a shallow copy of this object.StringtoString()
-
-
-
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 IllegalArgumentExceptionChecks 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 ofsizedoes 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 positionposto 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 ofposis greater than the according entry insize.- Parameters:
pos- an index vector with same dimension assize- Throws:
UnsupportedOperationException- ifposhas 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:OctaveObjectMake a shallow copy of this object. In general when anOctaveObjectis returned from a getter, e.g. onOctaveStructorOctaveStruct, a shallow copy is returned in order to follow the way octave behaves. This method is used to make that copy.- Specified by:
shallowCopyin interfaceOctaveObject- Returns:
- a shallow copy of this
-
main
public static void main(String[] args)
-
-