Package tech.tablesaw.table
Class TableSlice
- java.lang.Object
-
- tech.tablesaw.table.Relation
-
- tech.tablesaw.table.TableSlice
-
public class TableSlice extends Relation
A TableSlice is a facade around a Relation that acts as a filter. Requests for data are forwarded to the underlying table. A TableSlice can be sorted independently of the underlying table.A TableSlice is only good until the structure of the underlying table changes.
-
-
Constructor Summary
Constructors Constructor Description TableSlice(Table table)
Returns a new view constructed from the given table.TableSlice(Table table, Selection rowSelection)
Returns a new View constructed from the given table, containing only the rows represented by the bitmap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TableSlice
addColumns(Column<?>... column)
Adds the given columns to this Relation and returns the same relation.Table
asTable()
Returns the data in this slice as a new Tablevoid
clear()
Clears all rows from this View, leaving the structure in placeColumn<?>
column(int columnIndex)
Returns the column at columnIndex (0-based)Column<?>
column(String columnName)
Returns the column with the given columnName, ignoring caseint
columnCount()
Returns the number of columns in the relationint
columnIndex(Column<?> column)
Returns the index of the given columnList<String>
columnNames()
Returns a list containing the names of all the columns in this relationList<Column<?>>
columns()
Returns a list of all the columns in the relationTable
first(int nRows)
Returns a new table containing the first n rows in this RelationObject
get(int r, int c)
Returns the value at the given row and column indexesTable
getTable()
Returns the backing table for this sliceIterator<Row>
iterator()
Iterate over the underlying rows in the source table.int
mappedRowNumber(int rowNumber)
Maps the view row number to the row number on the underlying source table.String
name()
Returns the name of this relationdouble
reduce(String numberColumnName, NumericAggregateFunction function)
Returns the result of applying the given function to the specified columnTableSlice
removeColumns(Column<?>... columns)
Removes the given columns from this Relation and returns the same relation.void
removeSelection()
Removes the selection from this view, leaving it with the same number of rows as the underlying source table.void
removeSort()
Removes the sort from this View.int
rowCount()
Returns the number of rows in the relationTableSlice
setName(String name)
Sets the name of this Relation and returns the same relation.void
sortOn(Sort key)
Sort this view in place without modifying or copying the underlying source table.protected PrimitiveIterator.OfInt
sourceRowNumberIterator()
IntIterator of source table row numbers that are present in this view.-
Methods inherited from class tech.tablesaw.table.Relation
as, booleanColumn, booleanColumn, booleanColumns, categoricalColumn, categoricalColumn, categoricalColumns, columnIndex, columns, columns, columnsOfType, colWidths, containsColumn, containsColumn, dateColumn, dateColumn, dateColumns, dateTimeColumn, dateTimeColumn, dateTimeColumns, doubleColumn, doubleColumn, floatColumn, floatColumn, getString, getString, getUnformatted, instantColumn, instantColumn, instantColumns, intColumn, intColumn, isEmpty, longColumn, longColumn, nCol, nCol, numberColumn, numberColumn, numberColumns, numericColumns, numericColumns, numericColumns, print, print, printAll, removeColumns, removeColumns, shape, shortColumn, shortColumn, smile, stringColumn, stringColumn, stringColumns, structure, summary, timeColumn, timeColumn, timeColumns, toString, typeArray, types
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
TableSlice
public TableSlice(Table table, Selection rowSelection)
Returns a new View constructed from the given table, containing only the rows represented by the bitmap
-
TableSlice
public TableSlice(Table table)
Returns a new view constructed from the given table. The view can be sorted independently of the table.
-
-
Method Detail
-
column
public Column<?> column(int columnIndex)
Returns the column at columnIndex (0-based)
-
column
public Column<?> column(String columnName)
Returns the column with the given columnName, ignoring case
-
columnCount
public int columnCount()
Returns the number of columns in the relation- Specified by:
columnCount
in classRelation
-
rowCount
public int rowCount()
Returns the number of rows in the relation
-
columnIndex
public int columnIndex(Column<?> column)
Returns the index of the given column- Specified by:
columnIndex
in classRelation
-
get
public Object get(int r, int c)
Returns the value at the given row and column indexes
-
getTable
public Table getTable()
Returns the backing table for this slice
-
clear
public void clear()
Clears all rows from this View, leaving the structure in place
-
removeSort
public void removeSort()
Removes the sort from this View.
-
removeSelection
public void removeSelection()
Removes the selection from this view, leaving it with the same number of rows as the underlying source table.
-
columnNames
public List<String> columnNames()
Returns a list containing the names of all the columns in this relation- Specified by:
columnNames
in classRelation
-
addColumns
public TableSlice addColumns(Column<?>... column)
Adds the given columns to this Relation and returns the same relation.- Specified by:
addColumns
in classRelation
- Returns:
- This Relation
-
removeColumns
public TableSlice removeColumns(Column<?>... columns)
Removes the given columns from this Relation and returns the same relation.- Specified by:
removeColumns
in classRelation
- Returns:
- This Relation
-
first
public Table first(int nRows)
Returns a new table containing the first n rows in this Relation
-
setName
public TableSlice setName(String name)
Sets the name of this Relation and returns the same relation.
-
asTable
public Table asTable()
Returns the data in this slice as a new Table
-
sourceRowNumberIterator
protected PrimitiveIterator.OfInt sourceRowNumberIterator()
IntIterator of source table row numbers that are present in this view. This can be used to in combination with the source table to iterate over the cells of a column in a sorted order without copying the column.- Returns:
- an int iterator of row numbers in the source table that are present in this view.
-
reduce
public double reduce(String numberColumnName, NumericAggregateFunction function)
Returns the result of applying the given function to the specified column- Parameters:
numberColumnName
- The name of a numeric column in this tablefunction
- A numeric reduce function- Returns:
- the function result
- Throws:
IllegalArgumentException
- if numberColumnName doesn't name a numeric column in this table
-
iterator
public Iterator<Row> iterator()
Iterate over the underlying rows in the source table. If you set one of the rows while iterating it will change the row in the source table.
-
mappedRowNumber
public int mappedRowNumber(int rowNumber)
Maps the view row number to the row number on the underlying source table.- Parameters:
rowNumber
- the row number in the view.- Returns:
- the matching row number in the underlying table.
-
sortOn
public void sortOn(Sort key)
Sort this view in place without modifying or copying the underlying source table. UnlikeTable.sortOn(Sort)
which returns a copy of the table, this method sorts the view in place.- Parameters:
key
- to sort on.
-
-