org.jfree.data

Class DefaultKeyedValues2D

public class DefaultKeyedValues2D extends Object implements KeyedValues2D, PublicCloneable, Cloneable, Serializable

A data structure that stores zero, one or many values, where each value is associated with two keys (a 'row' key and a 'column' key). The keys should be (a) instances of Comparable and (b) immutable.
Constructor Summary
DefaultKeyedValues2D()
Creates a new instance (initially empty).
DefaultKeyedValues2D(boolean sortRowKeys)
Creates a new instance (initially empty).
Method Summary
voidaddValue(Number value, Comparable rowKey, Comparable columnKey)
Adds a value to the table.
voidclear()
Clears all the data and associated keys.
Objectclone()
Returns a clone.
booleanequals(Object o)
Tests if this object is equal to another.
intgetColumnCount()
Returns the column count.
intgetColumnIndex(Comparable key)
Returns the column index for a given key.
ComparablegetColumnKey(int column)
Returns the key for a given column.
ListgetColumnKeys()
Returns the column keys in an unmodifiable list.
intgetRowCount()
Returns the row count.
intgetRowIndex(Comparable key)
Returns the row index for a given key.
ComparablegetRowKey(int row)
Returns the key for a given row.
ListgetRowKeys()
Returns the row keys in an unmodifiable list.
NumbergetValue(int row, int column)
Returns the value for a given row and column.
NumbergetValue(Comparable rowKey, Comparable columnKey)
Returns the value for the given row and column keys.
inthashCode()
Returns a hash code.
voidremoveColumn(int columnIndex)
Removes a column.
voidremoveColumn(Comparable columnKey)
Removes a column from the table.
voidremoveRow(int rowIndex)
Removes a row.
voidremoveRow(Comparable rowKey)
Removes a row from the table.
voidremoveValue(Comparable rowKey, Comparable columnKey)
Removes a value from the table by setting it to null.
voidsetValue(Number value, Comparable rowKey, Comparable columnKey)
Adds or updates a value.

Constructor Detail

DefaultKeyedValues2D

public DefaultKeyedValues2D()
Creates a new instance (initially empty).

DefaultKeyedValues2D

public DefaultKeyedValues2D(boolean sortRowKeys)
Creates a new instance (initially empty).

Parameters: sortRowKeys if the row keys should be sorted.

Method Detail

addValue

public void addValue(Number value, Comparable rowKey, Comparable columnKey)
Adds a value to the table. Performs the same function as #setValue(Number, Comparable, Comparable).

Parameters: value the value (null permitted). rowKey the row key (null not permitted). columnKey the column key (null not permitted).

See Also: DefaultKeyedValues2D DefaultKeyedValues2D

clear

public void clear()
Clears all the data and associated keys.

clone

public Object clone()
Returns a clone.

Returns: A clone.

Throws: CloneNotSupportedException this class will not throw this exception, but subclasses (if any) might.

equals

public boolean equals(Object o)
Tests if this object is equal to another.

Parameters: o the other object (null permitted).

Returns: A boolean.

getColumnCount

public int getColumnCount()
Returns the column count.

Returns: The column count.

See Also: getRowCount

getColumnIndex

public int getColumnIndex(Comparable key)
Returns the column index for a given key.

Parameters: key the key (null not permitted).

Returns: The column index.

See Also: DefaultKeyedValues2D getRowIndex

getColumnKey

public Comparable getColumnKey(int column)
Returns the key for a given column.

Parameters: column the column (in the range 0 to getColumnCount - 1).

Returns: The key.

See Also: getColumnIndex DefaultKeyedValues2D

getColumnKeys

public List getColumnKeys()
Returns the column keys in an unmodifiable list.

Returns: The column keys.

See Also: getRowKeys

getRowCount

public int getRowCount()
Returns the row count.

Returns: The row count.

See Also: getColumnCount

getRowIndex

public int getRowIndex(Comparable key)
Returns the row index for a given key.

Parameters: key the key (null not permitted).

Returns: The row index.

See Also: DefaultKeyedValues2D getColumnIndex

getRowKey

public Comparable getRowKey(int row)
Returns the key for a given row.

Parameters: row the row index (in the range 0 to getRowCount - 1).

Returns: The row key.

See Also: getRowIndex DefaultKeyedValues2D

getRowKeys

public List getRowKeys()
Returns the row keys in an unmodifiable list.

Returns: The row keys.

See Also: getColumnKeys

getValue

public Number getValue(int row, int column)
Returns the value for a given row and column.

Parameters: row the row index. column the column index.

Returns: The value.

See Also: DefaultKeyedValues2D

getValue

public Number getValue(Comparable rowKey, Comparable columnKey)
Returns the value for the given row and column keys. This method will throw an UnknownKeyException if either key is not defined in the data structure.

Parameters: rowKey the row key (null not permitted). columnKey the column key (null not permitted).

Returns: The value (possibly null).

See Also: DefaultKeyedValues2D DefaultKeyedValues2D

hashCode

public int hashCode()
Returns a hash code.

Returns: A hash code.

removeColumn

public void removeColumn(int columnIndex)
Removes a column.

Parameters: columnIndex the column index.

See Also: removeColumn DefaultKeyedValues2D

removeColumn

public void removeColumn(Comparable columnKey)
Removes a column from the table.

Parameters: columnKey the column key (null not permitted).

Throws: UnknownKeyException if the table does not contain a column with the specified key. IllegalArgumentException if columnKey is null.

See Also: DefaultKeyedValues2D removeRow

removeRow

public void removeRow(int rowIndex)
Removes a row.

Parameters: rowIndex the row index.

See Also: removeRow DefaultKeyedValues2D

removeRow

public void removeRow(Comparable rowKey)
Removes a row from the table.

Parameters: rowKey the row key (null not permitted).

Throws: UnknownKeyException if rowKey is not defined in the table.

See Also: DefaultKeyedValues2D

removeValue

public void removeValue(Comparable rowKey, Comparable columnKey)
Removes a value from the table by setting it to null. If all the values in the specified row and/or column are now null, the row and/or column is removed from the table.

Parameters: rowKey the row key (null not permitted). columnKey the column key (null not permitted).

See Also: DefaultKeyedValues2D

setValue

public void setValue(Number value, Comparable rowKey, Comparable columnKey)
Adds or updates a value.

Parameters: value the value (null permitted). rowKey the row key (null not permitted). columnKey the column key (null not permitted).

See Also: DefaultKeyedValues2D DefaultKeyedValues2D