|
||||||||||
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.JSCSArray
public final class JSCSArray
A wrapper for string arrays that conforms to the JSCData
interface.
A JSCSArray
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 String[][]
) 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.
Nested Class Summary | |
---|---|
static class |
JSCSArray.Row
Inner class for storing rows of this array as XML elements. |
Field Summary | |
---|---|
static javolution.xml.XmlFormat<JSCSArray> |
JSCSArray_XML
XML format field for (de)serialization. |
Constructor Summary | |
---|---|
JSCSArray(JSCSArray sarray)
Copy-Constructor. |
|
JSCSArray(java.lang.String name)
Creates an empty JSCSArray . |
|
JSCSArray(java.lang.String name,
java.lang.String... value)
Creates a JSCSArray from value . |
|
JSCSArray(java.lang.String name,
java.lang.String[][] value)
Creates a JSCSArray from value . |
Method Summary | |
---|---|
void |
appendCols(JSCSArray newCols)
Appends newCols to the right end of the value array. |
void |
appendRows(JSCSArray 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. |
JSCSArray |
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 String[][] stored. |
java.lang.String[] |
getCol(int colIndex)
Gets the column of the underlying string array specified with colIndex . |
boolean |
isEmpty()
Gets whether this is empty. |
boolean |
isEqual(JSCData o)
Gets whether the values of this data object and other are
logically equal. |
java.lang.String |
name()
Gets the name of the data object. |
int |
rows()
Gets the number of rows in the stored array. |
java.lang.String[][] |
selRowsIf(int[] rowIndex)
Gets all rows of the underlying string array that have a nonzero corresponding element in rowIndex . |
void |
setFormatString(java.lang.String newFormatString)
Sets a new format string. |
void |
setVal(JSCSArray val)
Sets the values stored in val to this
JSCSArray . |
void |
setVal(java.lang.String... newValue)
Sets the value of this to newValue , see
setVal(String[][] newValue) . |
void |
setVal(java.lang.String[][] newValue)
Sets the value of this to newValue . |
void |
setValAt(java.lang.String val,
int i,
int j)
Sets the String element stored at index i, j. |
java.lang.String[][] |
stringArray()
Gets a copy of the underlying value as a String[][] . |
java.lang.String |
stringAt(int i,
int j)
Gets the String element stored at index i, j. |
java.lang.String |
toString()
Gets a string representation of this JSCSArray 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 String[][] . |
java.lang.String[] |
vec()
Gets the columns of this object stacked into a String[] . |
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<JSCSArray> JSCSArray_XML
Constructor Detail |
---|
public JSCSArray(java.lang.String name)
JSCSArray
.
name
- the identifier of that object
java.lang.IllegalArgumentException
- if name
is not valid or
if (name == null)
JSCConstants.isValidName(java.lang.String)
public JSCSArray(java.lang.String name, java.lang.String[][] value)
JSCSArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the String[][]
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 JSCSArray(JSCSArray sarray)
sarray
- the string array to copy
java.lang.IllegalArgumentException
- if (sarray == null)
JSCConstants.isValidName(java.lang.String)
public JSCSArray(java.lang.String name, java.lang.String... value)
JSCSArray
from value
. The
elements of value
are copied before.
name
- the identifier of that objectvalue
- the String[]
to be copied and used as value
java.lang.IllegalArgumentException
- if name
is not valid if (name == null)
JSCConstants.isValidName(java.lang.String)
Method Detail |
---|
public void appendCols(JSCSArray 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 JSCSArray
to be appended
java.lang.IllegalArgumentException
- if (newCols == null)
or
if (rows() > 0 && newCols.rows() > 0 && rows() != newCols.rows())
public void appendRows(JSCSArray 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 JSCSArray
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 JSCSArray 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())
or
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()
String[][]
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 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 java.lang.String name()
JSCData
JSCConstants
.
JSCData
public int rows()
if (isEmpty())
public void setFormatString(java.lang.String newFormatString)
display
method to format the string array. The default format string is
"%-12s "
.
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(java.lang.String[][] 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(java.lang.String... newValue)
newValue
, see
setVal(String[][] newValue)
.
newValue
- the new valuepublic void setVal(JSCSArray val)
val
to this
JSCSArray
. Future changes in val
have no
effect on this
.
val
- instance of JSCSArray
java.lang.IllegalArgumentException
- if (val == null)
public void setValAt(java.lang.String val, int i, int j)
String
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 Object[] { oldString, new Integer(i), new Integer(j) }
newValue
-
new Object[] { newString, new Integer(i), new Integer(j) }
val
- the String
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[][] stringArray()
String[][]
.
this
is empty new String[0][0]
is returnedpublic java.lang.String[] vec()
String[]
.
this
is empty new String[0]
is
returnedpublic java.lang.String stringAt(int i, int j)
String
element stored at index i, j.
i
- the row index, zero basedj
- the column index, zero based
String
stored at this array position
java.lang.IllegalArgumentException
- if indices out of rangepublic java.lang.String toString()
JSCSArray
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 JSCTypes type()
JSCData
object.
JSCTypes.SARRAY
JSCTypes
public java.lang.Object value()
String[][]
.
this
is empty new String[0][0]
is returnedpublic void transpose()
this
is empty. Fires a JSCDataEvent
of type
JSCDataEventTypes.VALUE_CHANGED
if the stored array is not
symmetric.
public java.lang.String[][] selRowsIf(int[] rowIndex)
rowIndex
.
rowIndex
- this.rows() x 1
vector selecting rows
new string[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 java.lang.String[] 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 bounds
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |