# Class RowPermutedStarTable

java.lang.Object
uk.ac.starlink.table.WrapperStarTable
uk.ac.starlink.table.RowPermutedStarTable

All Implemented Interfaces:
  `Closeable, AutoCloseable, StarTable`

public class RowPermutedStarTable extends WrapperStarTable
Wrapper table which provides a view of a base table in which the rows are permuted. Each row 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.

A `long[]` array, `rowMap`, is used to keep track of which rows in this table correspond to which rows in the base table; the `n`'th row in this table corresponds to the `rowMap[n]`'th row in the base table. The `rowMap` array may contain duplicate entries, but should not contain any entries larger than the number of rows in the base table. Any negative entry is treated as a special case resulting in a 'blank' row of all null values. It can be modified during the life of the table, but it's not a good idea to do this while a `RowSequence` is active.

Author:
  Mark Taylor (Starlink)

## Field Summary

### Fields inherited from class WrapperStarTable

`baseTable`

## Constructor Summary

Constructors
Constructor
Description
`RowPermutedStarTable(StarTable baseTable)`
Constructs a new RowPermutedTable with rows initially in unpermuted order.
`RowPermutedStarTable(StarTable baseTable, long[] rowMap)`
Constructs a new `RowPermutedStarTable` from a base table and a `rowMap` array.

## Method Summary

Modifier and Type
Method
Description
`Object`
`getCell(long irow, int icol)`
Returns the contents of a given table cell.
`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.
`long`
`getRowCount()`
Returns the number of rows in this table, if known.
`long[]`
`getRowMap()`
Returns the mapping array.
`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.
`boolean`
`isRandom()`
Returns true.
`void`
`setRowMap(long[] rowMap)`
Sets the mapping array.

### Methods inherited from class WrapperStarTable

`checkedLongToInt, close, getBaseTable, getColumnAuxDataInfos, getColumnCount, getColumnInfo, getName, getParameterByName, getParameters, getURL, setName, setParameter, setURL, toString`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### RowPermutedStarTable

public RowPermutedStarTable(StarTable baseTable, long[] rowMap)
Constructs a new `RowPermutedStarTable` from a base table and a `rowMap` array.

`baseTable` must provide random access.

Parameters:
  `baseTable` - base table
  `rowMap` - array mapping rows in the new permuted table to rows in `baseTable`
Throws:
  `IllegalArgumentException` - if `baseTable.isRandom` returns `false`

### RowPermutedStarTable

public RowPermutedStarTable(StarTable baseTable)
Constructs a new RowPermutedTable with rows initially in unpermuted order.

Parameters:
  `baseTable` - base table

## Method Details

### getRowMap

public long[] getRowMap()
Returns the mapping array.

Returns:
  array mapping rows in this table to rows in the base table

### setRowMap

public void setRowMap(long[] rowMap)
Sets the mapping array.

Parameters:
  `rowMap` - array mapping rows in this table to rows in the base table

### 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

### isRandom

public boolean isRandom()
Returns true.

Specified by:
  `isRandom` in interface `StarTable`
Overrides:
  `isRandom` in class `WrapperStarTable`
Returns:
  `true` if table random access methods are available

### getRowAccess

public RowAccess getRowAccess() throws 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 interface `StarTable`
Overrides:
  `getRowAccess` in class `WrapperStarTable`
Returns:
  new RowAccess
Throws:
  `IOException` - if there is an error setting up access

### getRowSequence

public RowSequence getRowSequence() throws 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 interface `StarTable`
Overrides:
  `getRowSequence` in class `WrapperStarTable`
Returns:
  new RowSequence
Throws:
  `IOException` - if there is an error providing access

### getRowSplittable

public RowSplittable getRowSplittable() throws 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 return `Tables.getDefaultRowSplittable``(this)`.

Specified by:
  `getRowSplittable` in interface `StarTable`
Overrides:
  `getRowSplittable` in class `WrapperStarTable`
Returns:
  new RowSplittable
Throws:
  `IOException`
See Also:
  - `RowRunner`

### getCell

public Object getCell(long irow, 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()`.

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 interface `StarTable`
Overrides:
  `getCell` in class `WrapperStarTable`
Parameters:
  `irow` - 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

### getRow

public Object[] getRow(long irow) 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.

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 interface `StarTable`
Overrides:
  `getRow` in class `WrapperStarTable`
Parameters:
  `irow` - 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