# 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`

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

Modifier and Type
Method
Description
`void`
`addRow(Object[] values)`
Adds a new row to the end of the table.
`void`
`clearRows()`
Removes all rows from the table.
`Object`
`getCell(long lrow, int icol)`
Implementations of this method must be safe for concurrent calls from multiple threads.
`int`
`getColumnCount()`
Returns the number of columns in this table.
`ColumnInfo`
`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 of `AbstractStarTable.getCell(long, int)`.
`long`
`getRowCount()`
Implementations must supply a non-negative return value.
`void`
`insertRow(long lrow, Object[] values)`
Adds a new row in the middle of the table.
`void`
`removeRow(long lrow)`
Removes an existing row from the table.
`void`
`setCell(long lrow, int icol, Object value)`
Sets the value of a given cell in the table.
`void`
`setRow(long lrow, Object[] values)`
Sets the value of a given row in the table.

### Methods inherited from class RandomStarTable

`getRowAccess, getRowSequence, isRandom`

### Methods inherited from class AbstractStarTable

`checkedLongToInt, close, getColumnAuxDataInfos, getName, getParameters, getRowSplittable, getURL, setName, setParameters, setURL`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface StarTable

`getParameterByName, setParameter`

## Constructor Details

### 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 Details

### getRowCount

public long getRowCount()
Description copied from class: `RandomStarTable`
Implementations must supply a non-negative return value.

Specified by:
  `getRowCount` in interface `StarTable`
Specified by:
  `getRowCount` in class `RandomStarTable`
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 interface `StarTable`
Specified by:
  `getColumnCount` in class `AbstractStarTable`
Returns:
  the number of columns

### getColumnInfo

public ColumnInfo getColumnInfo(int icol)
Description copied from interface: `StarTable`
Returns the object describing the data in a given column.

Specified by:
  `getColumnInfo` in interface `StarTable`
Specified by:
  `getColumnInfo` in class `AbstractStarTable`
Parameters:
  `icol` - the column for which header information is required
Returns:
  a ValueInfo object for column `icol`

### getCell

public Object getCell(long lrow, int icol)
Description copied from class: `RandomStarTable`
Implementations of this method must be safe for concurrent calls from multiple threads.

Specified by:
  `getCell` in interface `StarTable`
Specified by:
  `getCell` in class `RandomStarTable`
Parameters:
  `lrow` - the index of the cell's row
  `icol` - the index of the cell's column
Returns:
  the contents of this cell

### getRow

public Object[] getRow(long lrow)
Description copied from class: `AbstractStarTable`
The `AbstractStarTable` implementation of this method constructs a row by repeated invocation of `AbstractStarTable.getCell(long, int)`.

Specified by:
  `getRow` in interface `StarTable`
Overrides:
  `getRow` in class `AbstractStarTable`
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, 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 index
  `icol` - column index
  `value` - new value for the cell at `lrow`, `icol`
Throws:
  `IllegalArgumentException` - if `value` is not compatible with column `icol`

### setRow

public void setRow(long lrow, 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 index
  `values` - 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

public void addRow(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:
  `IllegalArgumentException` - if `values` has the wrong number of elements or they are of the wrong class

### insertRow

public void insertRow(long lrow, 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 row
  `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

### 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.