uk.ac.starlink.table
Class RandomWrapperStarTable

java.lang.Object
  extended by uk.ac.starlink.table.WrapperStarTable
      extended by uk.ac.starlink.table.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)

Field Summary
 
Fields inherited from class uk.ac.starlink.table.WrapperStarTable
baseTable
 
Constructor Summary
RandomWrapperStarTable(StarTable baseTable)
          Constructs a new random access table from a base table.
 
Method Summary
 Object getCell(long lrow, int icol)
          Returns the contents of a given table cell.
 int getColumnCount()
          Returns the number of columns.
 ColumnInfo getColumnInfo(int icol)
          Returns the object describing the data in a given column.
 Object[] getRow(long lrow)
          Returns the contents of a given table row.
 long getRowCount()
          Returns the number of rows in this table, if known.
 RowSequence getRowSequence()
          Returns a RowSequence object based on the random data access methods of this table.
 URL getURL()
          Returns the URL of the base table.
 boolean isRandom()
          Returns true.
protected abstract  Object[] retrieveStoredRow(long lrow)
          Retrieves the row stored by the lrow'th invocation of storeNextRow(java.lang.Object[]).
protected abstract  void storeNextRow(Object[] row)
          Stores the next row encountered in the base table's row sequence.
 
Methods inherited from class uk.ac.starlink.table.WrapperStarTable
checkedLongToInt, getBaseTable, getColumnAuxDataInfos, getName, getParameterByName, getParameters, setName, setParameter, setURL, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RandomWrapperStarTable

public RandomWrapperStarTable(StarTable baseTable)
                       throws IOException
Constructs a new random access table from a base table.

Parameters:
baseTable - the base StarTable
Throws:
IOException
Method Detail

storeNextRow

protected abstract void storeNextRow(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 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[])

isRandom

public boolean isRandom()
Returns true.

Specified by:
isRandom in interface StarTable
Overrides:
isRandom in class WrapperStarTable
Returns:
true

getColumnCount

public int getColumnCount()
Returns the number of columns. This is fixed for the life of this table.

Specified by:
getColumnCount in interface StarTable
Overrides:
getColumnCount in class WrapperStarTable
Returns:
number of columns

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 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 Object[] getRow(long lrow)
                throws 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:
IOException - if there is an error reading the data

getCell

public Object getCell(long lrow,
                      int icol)
               throws 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:
IOException - if there is an error reading the data

getRowSequence

public RowSequence getRowSequence()
                           throws 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:
IOException - if there is an error providing access


Copyright © 2017 Central Laboratory of the Research Councils. All Rights Reserved.