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 TypeMethodDescriptionvoidAdds a new row to the end of the table.voidRemoves all rows from the table.getCell(long lrow, int icol) Implementations of this method must be safe for concurrent calls from multiple threads.intReturns the number of columns in this table.getColumnInfo(int icol) Returns the object describing the data in a given column.Object[]getRow(long lrow) TheAbstractStarTableimplementation of this method constructs a row by repeated invocation ofAbstractStarTable.getCell(long, int).longImplementations must supply a non-negative return value.voidAdds a new row in the middle of the table.voidremoveRow(long lrow) Removes an existing row from the table.voidSets the value of a given cell in the table.voidSets the value of a given row in the table.Methods inherited from class RandomStarTable
getRowAccess, getRowSequence, isRandomMethods inherited from class AbstractStarTable
checkedLongToInt, close, getColumnAuxDataInfos, getName, getParameters, getRowSplittable, getURL, setName, setParameters, setURLMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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 thetemplateis ignored.- Parameters:
template- template table supplying column and table metadata
-
-
Method Details
-
getRowCount
public long getRowCount()Description copied from class:RandomStarTableImplementations must supply a non-negative return value.- Specified by:
getRowCountin interfaceStarTable- Specified by:
getRowCountin classRandomStarTable- Returns:
- the number of rows in the table
-
getColumnCount
public int getColumnCount()Description copied from interface:StarTableReturns the number of columns in this table.- Specified by:
getColumnCountin interfaceStarTable- Specified by:
getColumnCountin classAbstractStarTable- Returns:
- the number of columns
-
getColumnInfo
Description copied from interface:StarTableReturns the object describing the data in a given column.- Specified by:
getColumnInfoin interfaceStarTable- Specified by:
getColumnInfoin classAbstractStarTable- Parameters:
icol- the column for which header information is required- Returns:
- a ValueInfo object for column
icol
-
getCell
Description copied from class:RandomStarTableImplementations of this method must be safe for concurrent calls from multiple threads.- Specified by:
getCellin interfaceStarTable- Specified by:
getCellin 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:AbstractStarTableTheAbstractStarTableimplementation of this method constructs a row by repeated invocation ofAbstractStarTable.getCell(long, int).- Specified by:
getRowin interfaceStarTable- Overrides:
getRowin 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.valuehas to have a class compatible with its column.- Parameters:
lrow- row indexicol- column indexvalue- new value for the cell atlrow,icol- Throws:
IllegalArgumentException- ifvalueis not compatible with columnicol
-
setRow
Sets the value of a given row in the table. Overwrites the existing values of the cells in that row.valueshas 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 rowlrow- Throws:
IllegalArgumentException- ifvalueshas the wrong number of elements or they are of the wrong class
-
addRow
Adds a new row to the end of the table.valueshas 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- ifvalueshas the wrong number of elements or they are of the wrong class
-
insertRow
Adds a new row in the middle of the table. Rows afterlrowwill be shoved down by one.valueshas 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- ifvalueshas 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 afterlrowwill be moved up by one.- Parameters:
lrow- index of the row to remove
-
clearRows
public void clearRows()Removes all rows from the table.
-