Package uk.ac.starlink.table
Class RandomWrapperStarTable
- java.lang.Object
-
- uk.ac.starlink.table.WrapperStarTable
-
- 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[])
andretrieveStoredRow(long)
methods.- Author:
- Mark Taylor (Starlnk)
-
-
Field Summary
-
Fields inherited from class uk.ac.starlink.table.WrapperStarTable
baseTable
-
-
Constructor Summary
Constructors Constructor Description RandomWrapperStarTable(StarTable baseTable)
Constructs a new random access table from a base table.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.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.java.lang.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.java.net.URL
getURL()
Returns the URL of the base table.boolean
isRandom()
Returns true.protected abstract java.lang.Object[]
retrieveStoredRow(long lrow)
Retrieves the row stored by the lrow'th invocation ofstoreNextRow(java.lang.Object[])
.protected abstract void
storeNextRow(java.lang.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
-
-
-
-
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 byretrieveStoredRow(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 ofstoreNextRow(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 interfaceStarTable
- Overrides:
isRandom
in classWrapperStarTable
- Returns:
- true
-
getColumnCount
public int getColumnCount()
Returns the number of columns. This is fixed for the life of this table.- Specified by:
getColumnCount
in interfaceStarTable
- Overrides:
getColumnCount
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getRowCount
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getURL
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getColumnInfo
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getRow
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getCell
in classWrapperStarTable
- Parameters:
lrow
- the index of the cell's rowicol
- 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 interfaceStarTable
- Overrides:
getRowSequence
in classWrapperStarTable
- Returns:
- a row iterator
- Throws:
java.io.IOException
- if there is an error providing access
-
-