Package org.jfree.util
Class ObjectTable
java.lang.Object
org.jfree.util.ObjectTable
- All Implemented Interfaces:
Serializable
A lookup table for objects. This implementation is not synchronized, it is up
to the caller to synchronize it properly.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Defines how many object-slots get reserved each time we run out of space.private int
The number of columns.private Object[][]
An array of objects.private int
Defines how many object-slots get reserved each time we run out of space.private int
The number of rows.private static final long
For serialization. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new table.ObjectTable
(int increment) Creates a new table.ObjectTable
(int rowIncrement, int colIncrement) Creates a new table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the table.protected void
copyColumn
(int oldColumn, int newColumn) Copys the contents of the old column to the new column.protected void
copyRow
(int oldRow, int newRow) Copys the contents of the old row to the new row.void
ensureCapacity
(int row, int column) Ensures that there is storage capacity for the specified item.protected void
ensureRowCapacity
(int row) Checks that there is storage capacity for the specified row and resizes if necessary.boolean
Tests this paint table for equality with another object (typically also anObjectTable
).int
Returns the number of columns in the table.int
Returns the column size increment.protected Object[][]
getData()
Returns the table data.protected Object
getObject
(int row, int column) Returns the object from a particular cell in the table.int
Returns the number of rows in the table.int
Returns the row size increment.int
hashCode()
Returns a hash code value for the object.private void
readObject
(ObjectInputStream stream) Restores a serialized object.protected Object
readSerializedData
(ObjectInputStream stream) Handles the deserialization of a single element of the table.protected void
Sets the table data.protected void
Sets the object for a cell in the table.private void
writeObject
(ObjectOutputStream stream) Handles serialization.protected void
writeSerializedData
(ObjectOutputStream stream, Object o) Handles the serialization of an single element of this table.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor serialization.- See Also:
-
rows
private int rowsThe number of rows. -
columns
private int columnsThe number of columns. -
data
An array of objects. The array may containnull
values. -
rowIncrement
private int rowIncrementDefines how many object-slots get reserved each time we run out of space. -
columnIncrement
private int columnIncrementDefines how many object-slots get reserved each time we run out of space.
-
-
Constructor Details
-
ObjectTable
public ObjectTable()Creates a new table. -
ObjectTable
public ObjectTable(int increment) Creates a new table.- Parameters:
increment
- the row and column size increment.
-
ObjectTable
public ObjectTable(int rowIncrement, int colIncrement) Creates a new table.- Parameters:
rowIncrement
- the row size increment.colIncrement
- the column size increment.
-
-
Method Details
-
getColumnIncrement
public int getColumnIncrement()Returns the column size increment.- Returns:
- the increment.
-
getRowIncrement
public int getRowIncrement()Returns the row size increment.- Returns:
- the increment.
-
ensureRowCapacity
protected void ensureRowCapacity(int row) Checks that there is storage capacity for the specified row and resizes if necessary.- Parameters:
row
- the row index.
-
ensureCapacity
public void ensureCapacity(int row, int column) Ensures that there is storage capacity for the specified item.- Parameters:
row
- the row index.column
- the column index.
-
getRowCount
public int getRowCount()Returns the number of rows in the table.- Returns:
- The row count.
-
getColumnCount
public int getColumnCount()Returns the number of columns in the table.- Returns:
- The column count.
-
getObject
Returns the object from a particular cell in the table. Returns null, if there is no object at the given position.Note: throws IndexOutOfBoundsException if row or column is negative.
- Parameters:
row
- the row index (zero-based).column
- the column index (zero-based).- Returns:
- The object.
-
setObject
Sets the object for a cell in the table. The table is expanded if necessary.- Parameters:
row
- the row index (zero-based).column
- the column index (zero-based).object
- the object.
-
equals
Tests this paint table for equality with another object (typically also anObjectTable
). -
hashCode
public int hashCode()Returns a hash code value for the object. -
writeObject
Handles serialization.- Parameters:
stream
- the output stream.- Throws:
IOException
- if there is an I/O problem.
-
writeSerializedData
Handles the serialization of an single element of this table.- Parameters:
stream
- the stream which should write the objecto
- the object that should be serialized- Throws:
IOException
- if an IO error occured
-
readObject
Restores a serialized object.- Parameters:
stream
- the input stream.- Throws:
IOException
- if there is an I/O problem.ClassNotFoundException
- if a class cannot be found.
-
readSerializedData
protected Object readSerializedData(ObjectInputStream stream) throws ClassNotFoundException, IOException Handles the deserialization of a single element of the table.- Parameters:
stream
- the object input stream from which to read the object.- Returns:
- the deserialized object
- Throws:
ClassNotFoundException
- if a class cannot be found.IOException
- Any of the usual Input/Output related exceptions.
-
clear
public void clear()Clears the table. -
copyColumn
protected void copyColumn(int oldColumn, int newColumn) Copys the contents of the old column to the new column.- Parameters:
oldColumn
- the index of the old (source) columnnewColumn
- the index of the new column
-
copyRow
protected void copyRow(int oldRow, int newRow) Copys the contents of the old row to the new row. This uses raw access to the data and is remarkably faster than manual copying.- Parameters:
oldRow
- the index of the old rownewRow
- the index of the new row
-
setData
Sets the table data.- Parameters:
data
- the data.colCount
- the number of columns.
-
getData
Returns the table data.- Returns:
- The table data.
-