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:
StarTable
public class RowListStarTable extends RandomStarTable
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
Constructors Constructor Description RowListStarTable(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRow(java.lang.Object[] values)Adds a new row to the end of the table.voidclearRows()Removes all rows from the table.java.lang.ObjectgetCell(long lrow, int icol)The AbstractStarTable implementation of this method throws an UnsupportedOperationException, since unless otherwise provided there is no random access.intgetColumnCount()Returns the number of columns in this table.ColumnInfogetColumnInfo(int icol)Returns the object describing the data in a given column.java.lang.Object[]getRow(long lrow)The AbstractStarTable implementation of this method constructs a row by repeated invocation ofAbstractStarTable.getCell(long, int).longgetRowCount()The number of rows in this table.voidinsertRow(long lrow, java.lang.Object[] values)Adds a new row in the middle of the table.voidremoveRow(long lrow)Removes an existing row from the table.voidsetCell(long lrow, int icol, java.lang.Object value)Sets the value of a given cell in the table.voidsetRow(long lrow, java.lang.Object[] values)Sets the value of a given row in the table.-
Methods inherited from class uk.ac.starlink.table.RandomStarTable
getRowSequence, isRandom
-
Methods inherited from class uk.ac.starlink.table.AbstractStarTable
checkedLongToInt, getColumnAuxDataInfos, getName, getParameterByName, getParameters, getURL, setName, setParameter, setParameters, setURL
-
-
-
-
Constructor Detail
-
RowListStarTable
public RowListStarTable(ColumnInfo[] colInfos)
Constructs a new RowListStarTable specifying the columns that it will contain.- Parameters:
colInfos- array of objects defining the columns of the table
-
RowListStarTable
public RowListStarTable(StarTable template)
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 Detail
-
getRowCount
public long getRowCount()
Description copied from class:RandomStarTableThe number of rows in this table. Implementations 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
public ColumnInfo getColumnInfo(int icol)
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
public java.lang.Object getCell(long lrow, int icol)Description copied from class:AbstractStarTableThe AbstractStarTable implementation of this method throws an UnsupportedOperationException, since unless otherwise provided there is no random access.- Specified by:
getCellin interfaceStarTable- Overrides:
getCellin classAbstractStarTable- Parameters:
lrow- the index of the cell's rowicol- the index of the cell's column- Returns:
- the contents of this cell
-
getRow
public java.lang.Object[] getRow(long lrow)
Description copied from class:AbstractStarTableThe AbstractStarTable implementation 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
public void setCell(long lrow, int icol, java.lang.Object value)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:
java.lang.IllegalArgumentException- if value is not compatible with column icol
-
setRow
public void setRow(long lrow, java.lang.Object[] values)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:
java.lang.IllegalArgumentException- if values has the wrong number of elements or they are of the wrong class
-
addRow
public void addRow(java.lang.Object[] values)
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:
java.lang.IllegalArgumentException- if values has the wrong number of elements or they are of the wrong class
-
insertRow
public void insertRow(long lrow, java.lang.Object[] values)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:
java.lang.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.
-
-