Package uk.ac.starlink.table
Class RowListStarTable
java.lang.Object
uk.ac.starlink.table.AbstractStarTable
uk.ac.starlink.table.RandomStarTable
uk.ac.starlink.table.RowListStarTable
- All Implemented Interfaces:
Closeable
,AutoCloseable
,StarTable
Simple modifiable StarTable implementation.
It has a fixed number of columns and a variable number of rows;
rows can be added, removed and modified.
The current implementation stores the data in a List of Object[] arrays - each list element contains the cells of one row of the table. Thus currently you can't store more than Integer.MAX_VALUE rows.
Some validation is performed when objects are inserted into the table, but it is possible to subvert this - the table itself can't guarantee that its data structures represent a legal table.
- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
ConstructorsConstructorDescriptionRowListStarTable
(ColumnInfo[] colInfos) Constructs a new RowListStarTable specifying the columns that it will contain.RowListStarTable
(StarTable template) Constructs a new RowListStarTable with its column and table metadata copied from an existing table. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new row to the end of the table.void
Removes all rows from the table.getCell
(long lrow, int icol) Implementations of this method must be safe for concurrent calls from multiple threads.int
Returns the number of columns in this table.getColumnInfo
(int icol) Returns the object describing the data in a given column.Object[]
getRow
(long lrow) The AbstractStarTable implementation of this method constructs a row by repeated invocation ofAbstractStarTable.getCell(long, int)
.long
Implementations must supply a non-negative return value.void
Adds a new row in the middle of the table.void
removeRow
(long lrow) Removes an existing row from the table.void
Sets the value of a given cell in the table.void
Sets the value of a given row in the table.Methods inherited from class uk.ac.starlink.table.RandomStarTable
getRowAccess, getRowSequence, isRandom
Methods inherited from class uk.ac.starlink.table.AbstractStarTable
checkedLongToInt, close, getColumnAuxDataInfos, getName, getParameters, getRowSplittable, getURL, setName, setParameters, setURL
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.starlink.table.StarTable
getParameterByName, setParameter
-
Constructor Details
-
RowListStarTable
Constructs a new RowListStarTable specifying the columns that it will contain.- Parameters:
colInfos
- array of objects defining the columns of the table
-
RowListStarTable
Constructs a new RowListStarTable with its column and table metadata copied from an existing table. The data of the template is ignored.- Parameters:
template
- template table supplying column and table metadata
-
-
Method Details
-
getRowCount
public long getRowCount()Description copied from class:RandomStarTable
Implementations must supply a non-negative return value.- Specified by:
getRowCount
in interfaceStarTable
- Specified by:
getRowCount
in classRandomStarTable
- Returns:
- the number of rows in the table
-
getColumnCount
public int getColumnCount()Description copied from interface:StarTable
Returns the number of columns in this table.- Specified by:
getColumnCount
in interfaceStarTable
- Specified by:
getColumnCount
in classAbstractStarTable
- Returns:
- the number of columns
-
getColumnInfo
Description copied from interface:StarTable
Returns the object describing the data in a given column.- Specified by:
getColumnInfo
in interfaceStarTable
- Specified by:
getColumnInfo
in classAbstractStarTable
- Parameters:
icol
- the column for which header information is required- Returns:
- a ValueInfo object for column icol
-
getCell
Description copied from class:RandomStarTable
Implementations of this method must be safe for concurrent calls from multiple threads.- Specified by:
getCell
in interfaceStarTable
- Specified by:
getCell
in classRandomStarTable
- Parameters:
lrow
- the index of the cell's rowicol
- the index of the cell's column- Returns:
- the contents of this cell
-
getRow
Description copied from class:AbstractStarTable
The AbstractStarTable implementation of this method constructs a row by repeated invocation ofAbstractStarTable.getCell(long, int)
.- Specified by:
getRow
in interfaceStarTable
- Overrides:
getRow
in classAbstractStarTable
- Parameters:
lrow
- the index of the row to retrieve- Returns:
- an array of the objects in each cell in row irow
-
setCell
Sets the value of a given cell in the table. value has to have a class compatible with its column.- Parameters:
lrow
- row indexicol
- column indexvalue
- new value for the cell at lrow, icol- Throws:
IllegalArgumentException
- if value is not compatible with column icol
-
setRow
Sets the value of a given row in the table. Overwrites the existing values of the cells in that row. values has to have the same number of elements as there are columns in this table, and its elements have to have classes compatible with the table columns.- Parameters:
lrow
- row indexvalues
- new values for the cells in row lrow- Throws:
IllegalArgumentException
- if values has the wrong number of elements or they are of the wrong class
-
addRow
Adds a new row to the end of the table. values has to have the same number of elements as there are columns in this table, and its elements have to have classes compatible with the table columns.- Parameters:
values
- values for the cells in the new row- Throws:
IllegalArgumentException
- if values has the wrong number of elements or they are of the wrong class
-
insertRow
Adds a new row in the middle of the table. Rows after lrow will be shoved down by one. values has to have the same number of elements as there are columns in this table, and its elements have to have classes compatible with the table columns.- Parameters:
lrow
- row index for the new rowvalues
- values for the cells in the new row- Throws:
IllegalArgumentException
- if values has the wrong number of elements or they are of the wrong class
-
removeRow
public void removeRow(long lrow) Removes an existing row from the table. Rows after lrow will be moved up by one.- Parameters:
lrow
- index of the row to remove
-
clearRows
public void clearRows()Removes all rows from the table.
-