Class 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 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 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: RandomStarTable
        The number of rows in this table. 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
      • 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 java.lang.Object getCell​(long lrow,
                                        int icol)
        Description copied from class: AbstractStarTable
        The AbstractStarTable implementation of this method throws an UnsupportedOperationException, since unless otherwise provided there is no random access.
        Specified by:
        getCell in interface StarTable
        Overrides:
        getCell in class AbstractStarTable
        Parameters:
        lrow - the index of the cell's row
        icol - the index of the cell's column
        Returns:
        the contents of this cell
      • 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 index
        icol - column index
        value - 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 index
        values - 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 row
        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
      • 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.