Class RandomWrapperStarTable

  • All Implemented Interfaces:
    StarTable
    Direct Known Subclasses:
    ColumnRandomWrapperStarTable, RowRandomWrapperStarTable

    public abstract class RandomWrapperStarTable
    extends WrapperStarTable
    Abstract wrapper table which can provide a random-access view of a non-random base table. The general strategy is to read through the table only once (one RowSequence is used), storing each row when it is read. A row is not read until it is requested by a client of this class, so if the latter rows of the resulting table are never requested, they never need to be read from the base table. The exception to this is if the base table does not know how many rows it contains (getRowCount()<0), in which a getRowCount on this table will force all the rows to be read straight away to count them (a random-access table must always know how many rows it has).

    Changes in the number of columns of the base table will not be reflected in this table. Changes in the data elements may or may not be reflected.

    Concrete subclasses have to provide implementations of the storeNextRow(java.lang.Object[]) and retrieveStoredRow(long) methods.

    Author:
    Mark Taylor (Starlnk)
    • Constructor Detail

      • RandomWrapperStarTable

        public RandomWrapperStarTable​(StarTable baseTable)
                               throws java.io.IOException
        Constructs a new random access table from a base table.
        Parameters:
        baseTable - the base StarTable
        Throws:
        java.io.IOException
    • Method Detail

      • storeNextRow

        protected abstract void storeNextRow​(java.lang.Object[] row)
        Stores the next row encountered in the base table's row sequence. This will be called up to getRowCount times with the contents of each row of the base table in sequence. Implementations should store it in some way that it can be retrieved by retrieveStoredRow(long).
        Parameters:
        row - the row to store
      • retrieveStoredRow

        protected abstract java.lang.Object[] retrieveStoredRow​(long lrow)
        Retrieves the row stored by the lrow'th invocation of storeNextRow(java.lang.Object[]). This method will not be called with a value of lrow greater than or equal to the number of times storeNextRow has been called already.
        Parameters:
        lrow - the index of the row to retrieve
        Returns:
        the lrow'th row to be stored by storeNextRow(java.lang.Object[])
      • getRowCount

        public long getRowCount()
        Description copied from interface: StarTable
        Returns the number of rows in this table, if known. If the number of rows cannot be (easily) determined, a value of -1 will be returned.
        Specified by:
        getRowCount in interface StarTable
        Overrides:
        getRowCount in class WrapperStarTable
        Returns:
        the number of rows, or -1
      • getURL

        public java.net.URL getURL()
        Returns the URL of the base table. Unlike most WrapperStarTables, this is a reasonable thing to do, since although this isn't identical to the base table, its data and metadata are identical, it's only the mode of access which is different.
        Specified by:
        getURL in interface StarTable
        Overrides:
        getURL in class WrapperStarTable
        Returns:
        URL of the base 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
        Overrides:
        getColumnInfo in class WrapperStarTable
        Parameters:
        icol - the column for which header information is required
        Returns:
        a ValueInfo object for column icol
      • getRow

        public java.lang.Object[] getRow​(long lrow)
                                  throws java.io.IOException
        Description copied from interface: StarTable
        Returns the contents of a given table row. The returned value is equivalent to an array formed of all the objects returned by getCell(irow,icol) for all the columns icol in sequence.
        Specified by:
        getRow in interface StarTable
        Overrides:
        getRow in class WrapperStarTable
        Parameters:
        lrow - the index of the row to retrieve
        Returns:
        an array of the objects in each cell in row irow
        Throws:
        java.io.IOException - if there is an error reading the data
      • getCell

        public java.lang.Object getCell​(long lrow,
                                        int icol)
                                 throws java.io.IOException
        Description copied from interface: StarTable
        Returns the contents of a given table cell. The class of the returned object should be the same as, or a subclass of, the class returned by getColumnInfo(icol).getContentClass().
        Specified by:
        getCell in interface StarTable
        Overrides:
        getCell in class WrapperStarTable
        Parameters:
        lrow - the index of the cell's row
        icol - the index of the cell's column
        Returns:
        the contents of this cell
        Throws:
        java.io.IOException - if there is an error reading the data
      • getRowSequence

        public RowSequence getRowSequence()
                                   throws java.io.IOException
        Returns a RowSequence object based on the random data access methods of this table.
        Specified by:
        getRowSequence in interface StarTable
        Overrides:
        getRowSequence in class WrapperStarTable
        Returns:
        a row iterator
        Throws:
        java.io.IOException - if there is an error providing access