Class TableSlice

  • All Implemented Interfaces:
    Iterable<Row>

    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 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)
        Specified by:
        column in class Relation
        Parameters:
        columnIndex - an integer at least 0 and less than number of columns in the relation
        Returns:
        the column at the given index
      • column

        public Column<?> column​(String columnName)
        Returns the column with the given columnName, ignoring case
        Overrides:
        column in class Relation
      • columnCount

        public int columnCount()
        Returns the number of columns in the relation
        Specified by:
        columnCount in class Relation
      • rowCount

        public int rowCount()
        Returns the number of rows in the relation
        Specified by:
        rowCount in class Relation
      • columns

        public List<Column<?>> columns()
        Returns a list of all the columns in the relation
        Specified by:
        columns in class Relation
      • columnIndex

        public int columnIndex​(Column<?> column)
        Returns the index of the given column
        Specified by:
        columnIndex in class Relation
      • get

        public Object get​(int r,
                          int c)
        Returns the value at the given row and column indexes
        Overrides:
        get in class Relation
        Parameters:
        r - the row index, 0 based
        c - the column index, 0 based
      • name

        public String name()
        Returns the name of this relation
        Specified by:
        name in class Relation
      • 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
        Specified by:
        clear in class Relation
      • 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 class Relation
      • addColumns

        public TableSlice addColumns​(Column<?>... column)
        Adds the given columns to this Relation and returns the same relation.
        Specified by:
        addColumns in class Relation
        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 class Relation
        Returns:
        This Relation
      • first

        public Table first​(int nRows)
        Returns a new table containing the first n rows in this Relation
        Specified by:
        first in class Relation
      • setName

        public TableSlice setName​(String name)
        Sets the name of this Relation and returns the same relation.
        Specified by:
        setName in class Relation
        Returns:
        This 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 table
        function - 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. Unlike Table.sortOn(Sort) which returns a copy of the table, this method sorts the view in place.
        Parameters:
        key - to sort on.