Class ColumnPermutedStarTable
- java.lang.Object
-
- uk.ac.starlink.table.WrapperStarTable
-
- uk.ac.starlink.table.ColumnPermutedStarTable
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,StarTable
public class ColumnPermutedStarTable extends WrapperStarTable
Wrapper table which provides a view of a base table in which the columns are permuted. Each column in the wrapper table is a view of one in the base table. It is permitted for the wrapper to contain multiple views of the same column in the base, but note that modifying a cell in one of these will modify it in the other.An int[] array, columnMap, is used to keep track of which columns in this table correspond to which columns in the base table; the n'th column in this table corresponds to the columnMap[n]'th column in the base table. The columnMap array may contain duplicate entries, but all its entries must be in the range 0..baseTable.getColumnCount()-1. This table will have columnMap.length entries.
One implementation decision to be made is how to implement the getRow methods on this table and on any RowSequence taken out on it. It could either invoke getRow on the base table/sequence, or invoke getCell multiple times. The performance characteristics are likely to be different for the two, though it's not obvious which will be best. In general, if this table has the same number of columns (or more) than the base table, then using getRow will be better, and if it has many fewer, then getCell will be. The user may choose between these behaviours using the readRow parameter in one of the constructors. If the other constructor (which doesn't have this argument) is used then a choice will be made on the basis of the ratio of columns in this table to the ratio of the columns in the base table (the threshold is given by
READROW_FRACTION
).- Author:
- Mark Taylor (Starlink)
-
-
Field Summary
Fields Modifier and Type Field Description static double
READROW_FRACTION
When readRow is not specified explicitly, this gives the threshold for determining how getRow methods are implemented.-
Fields inherited from class uk.ac.starlink.table.WrapperStarTable
baseTable
-
-
Constructor Summary
Constructors Constructor Description ColumnPermutedStarTable(StarTable baseTable, int[] columnMap)
Constructs a new ColumnPermutedStarTable from a base StarTable and a columnMap array, making its own decision about how to read rows.ColumnPermutedStarTable(StarTable baseTable, int[] columnMap, boolean readRow)
Constructs a new ColumnPermutedStarTable from a base StarTable and columnMap array, with explicit instruction about how to read rows.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ColumnPermutedStarTable
deleteColumns(StarTable baseTable, int[] icols)
Returns aColumnPermutedStarTable
with selected columns deleted.java.lang.Object
getCell(long irow, int icol)
Returns the contents of a given table cell.int
getColumnCount()
Returns the number of columns in this table.ColumnInfo
getColumnInfo(int icol)
Returns the object describing the data in a given column.int[]
getColumnMap()
Returns the mapping used to define the permutation of the columns of this table with respect to the base table.java.lang.Object[]
getRow(long irow)
Returns the contents of a given table row.RowAccess
getRowAccess()
Returns an object which can provide random access to this table's data, if random access is implemented.RowSequence
getRowSequence()
Returns an object which can iterate over all the rows in the table sequentially.RowSplittable
getRowSplittable()
Returns an object which can iterate over all the rows in the table, but which may also be requested to split recursively for potentially parallel processing.void
setColumnMap(int[] columnMap)
Sets the mapping used to define the permutation of the columns of this table with respect to the base table.-
Methods inherited from class uk.ac.starlink.table.WrapperStarTable
checkedLongToInt, close, getBaseTable, getColumnAuxDataInfos, getName, getParameterByName, getParameters, getRowCount, getURL, isRandom, setName, setParameter, setURL, toString
-
-
-
-
Field Detail
-
READROW_FRACTION
public static final double READROW_FRACTION
When readRow is not specified explicitly, this gives the threshold for determining how getRow methods are implemented. IfgetColumnCount() / getBaseTable().getColumnCount() > READROW_FRACTION
then the base getRow method is implemented, otherwise multiple calls of getCell are used.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ColumnPermutedStarTable
public ColumnPermutedStarTable(StarTable baseTable, int[] columnMap)
Constructs a new ColumnPermutedStarTable from a base StarTable and a columnMap array, making its own decision about how to read rows.- Parameters:
baseTable
- the table on which this one is basedcolumnMap
- array describing where each column of this table comes from in baseTable
-
ColumnPermutedStarTable
public ColumnPermutedStarTable(StarTable baseTable, int[] columnMap, boolean readRow)
Constructs a new ColumnPermutedStarTable from a base StarTable and columnMap array, with explicit instruction about how to read rows.- Parameters:
baseTable
- the table on which this one is basedcolumnMap
- array describing where each column of this table comes from in baseTablereadRow
- true if the readRow implementations should invoke readRow on the base table, false if they should use readCell instead
-
-
Method Detail
-
getColumnMap
public int[] getColumnMap()
Returns the mapping used to define the permutation of the columns of this table with respect to the base table.- Returns:
- column permutation map
-
setColumnMap
public void setColumnMap(int[] columnMap)
Sets the mapping used to define the permutation of the columns of this table with respect to the base table.- Parameters:
columnMap
- column permutation map
-
getColumnCount
public int getColumnCount()
Description copied from interface:StarTable
Returns the number of columns in this table.- Specified by:
getColumnCount
in interfaceStarTable
- Overrides:
getColumnCount
in classWrapperStarTable
- 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 interfaceStarTable
- Overrides:
getColumnInfo
in classWrapperStarTable
- Parameters:
icol
- the column for which header information is required- Returns:
- a ValueInfo object for column icol
-
getRowSequence
public RowSequence getRowSequence() throws java.io.IOException
Description copied from interface:StarTable
Returns an object which can iterate over all the rows in the table sequentially. Each such returned object is safe for use within a single thread, but not in general from multiple threads concurrently.- Specified by:
getRowSequence
in interfaceStarTable
- Overrides:
getRowSequence
in classWrapperStarTable
- Returns:
- new RowSequence
- Throws:
java.io.IOException
- if there is an error providing access
-
getRowAccess
public RowAccess getRowAccess() throws java.io.IOException
Description copied from interface:StarTable
Returns an object which can provide random access to this table's data, if random access is implemented. Each such returned object is safe for use within a single thread, but not in general from multiple threads concurrently.- Specified by:
getRowAccess
in interfaceStarTable
- Overrides:
getRowAccess
in classWrapperStarTable
- Returns:
- new RowAccess
- Throws:
java.io.IOException
- if there is an error setting up access
-
getRowSplittable
public RowSplittable getRowSplittable() throws java.io.IOException
Description copied from interface:StarTable
Returns an object which can iterate over all the rows in the table, but which may also be requested to split recursively for potentially parallel processing.The return value must be non-null, and may provide splitting arrangements specially appropriate for the implementation. If this table 'wraps' an upstream table, it is usually best to base the implementation on calls to the the upstream
getRowSplittable
method, so that upstream policy about how to divide up the table is respected. However, implementations without special requirements may returnTables.getDefaultRowSplittable
(this)
.- Specified by:
getRowSplittable
in interfaceStarTable
- Overrides:
getRowSplittable
in classWrapperStarTable
- Returns:
- new RowSplittable
- Throws:
java.io.IOException
- See Also:
RowRunner
-
getCell
public java.lang.Object getCell(long irow, 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().This method is safe for concurrent use from multiple threads, but in general it is recommended to use a
RowAccess
instead.- Specified by:
getCell
in interfaceStarTable
- Overrides:
getCell
in classWrapperStarTable
- Parameters:
irow
- 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
-
getRow
public java.lang.Object[] getRow(long irow) 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.This method is safe for concurrent use from multiple threads, but in general it is recommended to use a
RowAccess
instead.- Specified by:
getRow
in interfaceStarTable
- Overrides:
getRow
in classWrapperStarTable
- Parameters:
irow
- 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
-
deleteColumns
public static ColumnPermutedStarTable deleteColumns(StarTable baseTable, int[] icols)
Returns aColumnPermutedStarTable
with selected columns deleted. This utility method simply works out a permutation map which corresponds to deletion of the columns indexed by the elements of theicols
array and passes it to the constructor. A single column index may harmlessly be listed multiple times in theicols
array. It is not permitted for any element oficols
to be less than zero or greater or equal than the number of columns inbaseTable
.- Parameters:
baseTable
- table whose columns are to be deletedicols
- array with elements listing the column indices which are to be removed
-
-