|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jstatcom.model.AbstractJSCData com.jstatcom.model.JSCNArray
public final class JSCNArray
A wrapper for 2-dimensional number arrays that conforms to the
JSCData
interface. Number arrays are stored as
double[][]
. It provides some convenience methods for matrix
transformation, but it is not intended to serve as a general purpose matrix
class. Instead it provides an adapter to set and get instances of the
Jama.Matrix
class, which is probably the de facto standard
matrix class for JAVA .
A JSCNArray
is empty, if the stored array is null
or has either zero rows or columns. All rows of array values must have the
same length.
All array arguments are copied before they are set as values. The original
arrays are untouched. In a similar way all get
methods return
either a copy of a mutable object (like double[][]
) or a
reference to an immutable object.
Whenever the value of this data object changes, registered
JSCDataListeners
are notified via a JSCDataEvent
.
If not otherwise stated, the event objects always contain the values before
the change and after the change.
This class is thread-safe. All access to mutable data is synchronized. All events are fired outside the synchronized blocks.
Field Summary | |
---|---|
static javolution.xml.XmlFormat<JSCNArray> |
JSCNArray_XML
XML format field for (de)serialization. |
Constructor Summary | |
---|---|
JSCNArray(JSCNArray narray)
Copy-Constructor. |
|
JSCNArray(java.lang.String name)
Creates an empty JSCNArray . |
|
JSCNArray(java.lang.String name,
double... value)
Creates a JSCNArray from value . |
|
JSCNArray(java.lang.String name,
double[][] value)
Creates a JSCNArray from value . |
|
JSCNArray(java.lang.String name,
int[] value)
Creates a JSCNArray from value . |
|
JSCNArray(java.lang.String name,
int[][] value)
Creates a JSCNArray from value . |
Method Summary | |
---|---|
void |
appendCols(JSCNArray newCols)
Appends newCols to the right end of the value array. |
void |
appendRows(JSCNArray newRows)
Appends newRows to the bottom the value array. |
void |
clear()
Clears this data object. |
int |
cols()
Gets the number of columns in the stored array. |
JSCNArray |
copy()
Gets a copy of the current object. |
void |
delCol(int i)
Deletes column i from the value array. |
void |
delColsIf(int... index)
Deletes all columns of this that have a corresponding
nonzero element in index . |
void |
delRow(int i)
Deletes row i from the value array. |
void |
delRowsIf(int... index)
Deletes all rows of this that have a corresponding nonzero
element in index . |
java.lang.String |
display()
Gets a string representing the double[][] stored. |
double[][] |
doubleArray()
Gets a copy of the underlying value as a double[][] . |
double |
doubleAt(int i,
int j)
Gets the double element stored at index i, j. |
java.lang.Double |
doubleValAt(int i,
int j)
Gets the Double element stored at index i, j. |
double[] |
getCol(int colIndex)
Gets the column of the underlying double array specified with colIndex . |
double[][] |
getCols(int startCol,
int endCol)
Gets all columns of the underlying double array defined by startCol:endCol . |
double[][] |
getPow(double pow)
Gets a new double array with the elements raised to the power of pow . |
double[] |
getRow(int rowIndex)
Gets the row of the underlying double array specified with rowIndex . |
double[][] |
getRows(int startRow,
int endRow)
Gets all rows of the underlying double array defined by startRow:endRow . |
double[][] |
getTransposed()
Gets a new double array with elements transposed. |
int[][] |
intArray()
Gets a copy of the underlying value as a int[][] . |
int |
intAt(int i,
int j)
Gets the int element stored at index i, j. |
boolean |
isEmpty()
Gets whether this is empty. |
boolean |
isEqual(JSCData o)
Gets whether the values of this data object and other are
logically equal. |
boolean |
isNaN(int i,
int j)
Gets whether the element stored at index i, j is of type Double.NaN . |
Jama.Matrix |
jamaMatrix()
Gets the values stored in this JSCNArray as an instance of
Jama.Matrix . |
java.lang.String |
name()
Gets the name of the data object. |
int |
nanCount()
Gets the number of double elements that are equal to
Double.NaN . |
int |
rank()
Gets the rank of the stored value. |
int |
rows()
Gets the number of rows in the stored array. |
double[][] |
selColsIf(int... colIndex)
Gets all columns of the underlying double array that have a nonzero corresponding element in colIndex . |
double[][] |
selRowsIf(int... rowIndex)
Gets all rows of the underlying double array that have a nonzero corresponding element in rowIndex . |
void |
setFormatString(java.lang.String newFormatString)
Sets a new format string. |
void |
setVal(double[] newValue)
Sets the value of this to newValue , see
setVal(double[][] newValue) . |
void |
setVal(double[][] newValue)
Sets the value of this to newValue . |
void |
setVal(int[] newValue)
Sets the value of this to newValue , see
setVal(double[][] newValue) . |
void |
setVal(int[][] newValue)
Sets the value of this to newValue , see
setVal(double[][] newValue) . |
void |
setVal(JSCNArray val)
Sets the values stored in val to this
JSCNArray . |
void |
setVal(Jama.Matrix mat)
Sets the values stored in mat to this
JSCNArray . |
void |
setValAt(double val,
int i,
int j)
Sets the double element stored at index i, j. |
java.lang.String |
toString()
Gets a string representation of this JSCNArray instance. |
void |
transpose()
Transposes the underlying array. |
JSCTypes |
type()
Gets the type of this JSCData object. |
java.lang.Object |
value()
Gets a copy of the underlying value, which is stored as a double[][] . |
static JSCNArray |
valueOf(java.io.File file,
java.lang.String name)
Creates an instance of this class from a data file. |
double[] |
vec()
Gets a vector stacked with the columns of the underlying data array. |
int |
zeroCount()
Gets the number of double elements that are equal to zero. |
Methods inherited from class com.jstatcom.model.AbstractJSCData |
---|
addJSCDataListener, getJSCProperty, removeJSCDataListener, removeJSCProperty, setJSCProperty |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final javolution.xml.XmlFormat<JSCNArray> JSCNArray_XML
Constructor Detail |
---|
public JSCNArray(java.lang.String name)
JSCNArray
.
name
- the identifier of that object
java.lang.IllegalArgumentException
- if name
is not valid or
if (name == null)
JSCConstants.isValidName(java.lang.String)
public JSCNArray(java.lang.String name, double[][] value)
JSCNArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the double[][]
to be copied and used as value
java.lang.IllegalArgumentException
- if name
is not valid value
have different lengths or
if (name == null)
JSCConstants.isValidName(java.lang.String)
public JSCNArray(JSCNArray narray)
narray
- the number array to copy
java.lang.IllegalArgumentException
- if (narray == null)
JSCConstants.isValidName(java.lang.String)
public JSCNArray(java.lang.String name, double... value)
JSCNArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the double[]
to be copied and used as value
java.lang.IllegalArgumentException
- if name
is not valid or
if (name == null)
JSCConstants.isValidName(java.lang.String)
public JSCNArray(java.lang.String name, int[] value)
JSCNArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the int[]
to be copied and used as value
java.lang.IllegalArgumentException
- if name
is not valid or
if (name == null)
JSCConstants.isValidName(java.lang.String)
public JSCNArray(java.lang.String name, int[][] value)
JSCNArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the int[][]
to be copied and used as value
java.lang.IllegalArgumentException
- if name
is not valid value
have different lengths or
if (name == null)
JSCConstants.isValidName(java.lang.String)
Method Detail |
---|
public void appendCols(JSCNArray newCols)
newCols
to the right end of the value array. Fires
a JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
if
newCols
is not empty
JSCDataEventTypes.EMPTY_STATE
if newCols
is not empty and this was empty before
newCols
is empty,
nothing happens.
newCols
- the JSCNArray
to be appended
java.lang.IllegalArgumentException
- if (newCols == null)
or
if (rows() > 0 && newCols.rows() > 0 && rows() != newCols.rows())
public void appendRows(JSCNArray newRows)
newRows
to the bottom the value array. Fires a
JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
if
newRows
is not empty
JSCDataEventTypes.EMPTY_STATE
if newRows
is not empty and this was empty before
newRows
is empty,
nothing happens.
newRows
- the JSCNArray
to be appended
java.lang.IllegalArgumentException
- if (newRows == null)
or
if (cols() > 0 && newRows.cols() > 0 && cols() != newRows.cols())
public void clear()
this
data object. Fires:
JSCDataEventTypes.EMPTY_STATE
event
JSCDataEventTypes.VALUE_CHANGED
event
isEmpty
returns true
.
public int cols()
if (isEmpty())
public JSCNArray copy()
JSCData
a.isEqual(a.copy())
- compares values
a.getName().equals(a.copy().getName())
- compares
name
JSCDataListeners
attached to the original object should
not be copied.
JSCData
public void delCol(int i)
i
from the value array. Fires a
JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
in any case
JSCDataEventTypes.EMPTY_STATE
if this
is emtpy afterwards
i
- the index of the column to remove
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if column index is invalidpublic void delColsIf(int... index)
this
that have a corresponding
nonzero element in index
. If index
contains only zeros, nothing happens. If index
selects all
columns, this
is cleared.
This method fires a JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
if some column was
deleted
JSCDataEventTypes.EMPTY_STATE
if this
is emtpy afterwards
index
- the cols() x 1 int
array, nonzero entries
select columns
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if (index.length != cols())
if (index == null)
public void delRow(int i)
i
from the value array. Fires a
JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
in any case
JSCDataEventTypes.EMPTY_STATE
if this
is emtpy afterwards
i
- the index of the row to remove
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if row index is invalidpublic void delRowsIf(int... index)
this
that have a corresponding nonzero
element in index
. If index
contains only
zeros, nothing happens. If index
selects all rows,
this
is cleared.
This method fires a JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
if some row was
deleted
JSCDataEventTypes.EMPTY_STATE
if this
is emtpy afterwards
index
- the rows() x 1 int
array, nonzero entries
select rows
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if (index.length != rows()
or
if (index == null)
public java.lang.String display()
double[][]
stored.
display
in interface JSCData
display
in class AbstractJSCData
isEmpty == true
, otherwise a formatted
string with all elements in table form, the format parameters can
be changed via setFormatString
public double[][] doubleArray()
double[][]
.
this
is empty new double[0][0]
is returnedpublic double doubleAt(int i, int j)
double
element stored at index i, j.
i
- the row index, zero basedj
- the column index, zero based
double
stored at this array position
java.lang.IllegalArgumentException
- if indices out of rangepublic java.lang.Double doubleValAt(int i, int j)
Double
element stored at index i, j.
i
- the row index, zero basedj
- the column index, zero based
Double
stored at this array position
java.lang.IllegalArgumentException
- if indices out of rangepublic int[][] intArray()
int[][]
. The
following special int
values for element i, j
are returned:
value[i][j] == Double.NaN
Integer.MAX_VALUE if value[i][j] == Double.POSITIVE_INFINITY
Integer.MIN_VALUE if value[i][j] == Double.NEGATIVE_INFINITY
this
is empty, then either null
or new int[0][0]
is returned, depending on what
has been set beforepublic int intAt(int i, int j)
int
element stored at index i, j. Note that
during this operation information is potentially lost. Only the integer
part is preserved, which is different from rounding. The following
special int
values are returned:
value == Double.NaN
Integer.MAX_VALUE if value == Double.POSITIVE_INFINITY
Integer.MIN_VALUE if value == Double.NEGATIVE_INFINITY
i
- the row index, zero basedj
- the column index, zero based
int
stored at this array position
java.lang.IllegalArgumentException
- if indices out of rangepublic boolean isEmpty()
this
is empty. This method returns
true
if one of the following conditions is met:
value() == null
rows() == 0
cols() == 0
true
if emptypublic boolean isEqual(JSCData o)
JSCData
other
are
logically equal.
true
if considered equal according to the logic of
the representationJSCData
public boolean isNaN(int i, int j)
Double.NaN
.
i
- the row indexj
- the column index
true
if the array element is a missing value
java.lang.IllegalArgumentException
- if indices out of rangepublic Jama.Matrix jamaMatrix()
JSCNArray
as an instance of
Jama.Matrix
. The underlying array is copied before.
Jama.Matrix
initialized with the
stored values
java.lang.IllegalStateException
- if this
is emptyMatrix
public java.lang.String name()
JSCData
JSCConstants
.
JSCData
public int nanCount()
double
elements that are equal to
Double.NaN
.
public int rank()
Jama.Matrix
instance.
double[][]
value
java.lang.IllegalStateException
- if this
is emptypublic int rows()
if (isEmpty())
public void setFormatString(java.lang.String newFormatString)
display
method to format the double array. The default format string is
"%- 8.4f "
.
For a complete description of all legal arguments, see the
PrintfFormat
documentation. The string must contain
exactly one conversion character.
newFormatString
- the format string to be used for display
java.lang.IllegalArgumentException
- if newFormatString
is not validPrintfFormat
public void setVal(double[][] newValue)
newValue
. Fires a
JSCDataEvent
of type:
JSCDataEventTypes.VALUE_CHANGED
if
newValue
is different from current value
JSCDataEventTypes.EMPTY_STATE
if
newValue
is not empty and this was empty before
JSCDataEventTypes.EMPTY_STATE
if
newValue
is empty and this was not empty before
null
or at least one
dimension is zero. The newValue
is only compared to the
existing value if a listener to
JSCDataEventTypes.VALUE_CHANGED
is registered.
newValue
- the new value
java.lang.IllegalArgumentException
- if rows of newValue
have different lengthspublic void setVal(int[][] newValue)
newValue
, see
setVal(double[][] newValue)
.
newValue
- the new value
java.lang.IllegalArgumentException
- if rows of newValue
have different lengthspublic void setVal(double[] newValue)
newValue
, see
setVal(double[][] newValue)
.
newValue
- the new valuepublic void setVal(int[] newValue)
newValue
, see
setVal(double[][] newValue)
.
newValue
- the new valuepublic void setVal(JSCNArray val)
val
to this
JSCNArray
. Future changes in val
have no
effect on this
.
val
- instance of JSCNArray
java.lang.IllegalArgumentException
- if (val == null)
public void setVal(Jama.Matrix mat)
mat
to this
JSCNArray
. The underlying array is copied before.
mat
- instance of Jama.Matrix
Matrix
public void setValAt(double val, int i, int j)
double
element stored at index i, j. Fires a
JSCDataEvent
of type
JSCDataEventTypes.VALUE_CHANGED
if the new value is
different from the one currently stored at that position. The event
object contains the following values:
oldValue
-
new double[] { oldNumber, i, j }
newValue
-
new double[] { newNumber, i, j }
val
- the double
to store at the given positioni
- the row index, zero basedj
- the column index, zero based
java.lang.IllegalArgumentException
- if indices out of rangepublic java.lang.String toString()
JSCNArray
instance.
The value is only represented with a summary string, because the
underlying array might be large. To print the complete value, use
display
instead.
toString
in class AbstractJSCData
public void transpose()
this
is empty. Fires a JSCDataEvent
of type
JSCDataEventTypes.VALUE_CHANGED
if the stored array is not
symmetric.
public JSCTypes type()
JSCData
object.
JSCTypes.NARRAY
JSCTypes
public java.lang.Object value()
double[][]
.
this
is empty new double[0][0]
is returnedpublic int zeroCount()
double
elements that are equal to zero.
public static JSCNArray valueOf(java.io.File file, java.lang.String name)
file
into a double array according to the
following conventions:
file
Double.NaN
file
is empty, an empty
JSCNArray
will be returned.
file
- the file to parse the double array fromname
- the name of the new JSCNArray
to create
JSCNArray
java.lang.IllegalArgumentException
- if (file == null || name == null
), or if
name
is not legal or
if (!file.isFile())
public double[] getCol(int colIndex)
colIndex
. The index starts with 0 as usual.
colIndex
- the index of the column to extract (starting from 0)
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- colIndex
is outside of valid array boundspublic double[] vec()
public double[] getRow(int rowIndex)
rowIndex
. The index starts with 0 as usual.
rowIndex
- the index of the row to extract (starting from 0)
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- rowIndex
is outside of valid array boundspublic double[][] getCols(int startCol, int endCol)
startCol:endCol
. The indices start with 0 as usual.
startCol
- the index of the first column to extract (starting from 0)endCol
- the index of the last column to extract (starting from 0)
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if (startCol > endCol)
or if the indices
are outside the valid array boundspublic double[][] getRows(int startRow, int endRow)
startRow:endRow
. The indices start with 0 as usual.
startRow
- the index of the first row to extract (starting from 0)endRow
- the index of the last row to extract (starting from 0)
java.lang.IllegalStateException
- if this
is empty
java.lang.IllegalArgumentException
- if (startRow > endRow)
or if the indices
are outside the valid array boundspublic double[][] selColsIf(int... colIndex)
colIndex
.
colIndex
- this.cols() x 1
vector selecting columns
new double[0][0]
if index contains only 0's, a
copy of the underlying values if colIndex
contains
only nonzero elements
java.lang.IllegalArgumentException
- if (colIndex == null)
or
if (this.isEmpty() && colIndex > 0)
or
if (this.cols() != colIndex)
public double[][] selRowsIf(int... rowIndex)
rowIndex
.
rowIndex
- this.rows() x 1
vector selecting rows
new double[0][0]
if index contains only 0's, a copy of the underlying values if
rowIndex
contains only nonzero elements
java.lang.IllegalArgumentException
- if (rowIndex == null)
or
if (this.isEmpty() && rowIndex > 0)
or
if (this.rows() != rowIndex)
public double[][] getTransposed()
public double[][] getPow(double pow)
pow
.
pow
- the power to raise each element of the data array to
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |