Package edu.uky.ai.util
Class Table
java.lang.Object
edu.uky.ai.util.Table
- All Implemented Interfaces:
Cloneable
Logic for displaying simple 2-dimensional tables of data.
- Author:
- Stephen G. Ware
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
An individual unit of data in the table.static final class
A vertical sequence of cells.static final class
A horizontal sequence of cells.static class
The abstract parent ofTable.Row
andTable.Column
. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ImmutableArray<Table.Cell>
The table's cellsfinal ImmutableArray<Table.Column>
The table's columnsfinal ImmutableArray<Table.Row>
The table's rows -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new table with an additional column whose cells contain the averages of each row.addAverageColumn
(Function<Object, ?> function) Returns a new table with an additional column whose cells contain the averages of each row.Returns a new table with an additional row whose cells contain the averages of each column.addAverageRow
(Function<Object, ?> function) Returns a new table with an additional row whose cells contain the averages of each column.Returns a new table with an addition column with the given label.Returns a new table with an addition row with the given label.Returns a new table with an additional column whose cells contain the totals of each row.addTotalColumn
(Function<Object, ?> function) Returns a new table with an additional column whose cells contain the totals of each row.Returns a new table with an additional row whose cells contain the totals of each column.addTotalRow
(Function<Object, ?> function) Returns a new table with an additional row whose cells contain the totals of each column.clone()
Returns the cell at the interaction of the row with the given label and and the column with the given labelReturns the column with the given label.Returns the row with the given label.sort
(Comparator<? super Table.Row> rowComparator, Comparator<? super Table.Column> columnComparator) Returns a new table whose rows and columns have been sorted according to the given comparators.sortByColumn
(Comparator<? super Table.Column> comparator) Returns a new table whose columns have been sorted according to the given comparator.sortByRow
(Comparator<? super Table.Row> comparator) Returns a new table whose rows have been sorted according to the given comparator.toHTML()
Returns an HTML representation of this table.toString()
Returns a new table whose cell values are the results of applying the given function to the values in this table.transform
(Predicate<? super Table.Row> rows, Predicate<? super Table.Column> columns) Returns a new table which only keeps the row and columns of this table that are identified by two predicates.transform
(Predicate<? super Table.Row> rows, Predicate<? super Table.Column> columns, Function<Object, ?> transform) Returns a new table which only keeps the row and columns of this table that are identified by two predicates and whose cell values are the results of applying the given function to the values in this table.
-
Field Details
-
rows
The table's rows -
columns
The table's columns -
cells
The table's cells
-
-
Constructor Details
-
Table
Constructs a new, empty table with rows and columns that have the given labels.- Parameters:
rowLabels
- the labels of the rowscolumnLabels
- the labels of the columns- Throws:
IllegalArgumentException
- if any row labels are duplicates or one another or any column labels are duplicates of one another
-
Table
Constructs a new, empty table with rows and columns that have the given labels.- Parameters:
rowLabels
- the labels of the rowscolumnLabels
- the labels of the columns- Throws:
IllegalArgumentException
- if any row labels are duplicates or one another or any column labels are duplicates of one another
-
-
Method Details
-
toString
-
clone
-
getRow
Returns the row with the given label.- Parameters:
label
- the label object- Returns:
- the row with this label
- Throws:
IllegalArgumentException
- if no row has this label
-
getColumn
Returns the column with the given label.- Parameters:
label
- the label object- Returns:
- the column with this label
- Throws:
IllegalArgumentException
- if no column has this label
-
getCell
Returns the cell at the interaction of the row with the given label and and the column with the given label- Parameters:
rowLabel
- the row label objectcolumnLabel
- the column label object- Returns:
- the cell in the given row and column
- Throws:
IllegalArgumentException
- if no such row or column exists
-
addRow
Returns a new table with an addition row with the given label.- Parameters:
label
- the label for the new row- Returns:
- the new table
-
addColumn
Returns a new table with an addition column with the given label.- Parameters:
label
- the label for the new column- Returns:
- the new table
-
addTotalRow
Returns a new table with an additional row whose cells contain the totals of each column. SeeTable.Sequence.sum(Function)
.- Parameters:
function
- a function for converting the values of the cells in each column toNumber
s that will be applied to each cell value before adding it to the sum- Returns:
- the new table
-
addTotalRow
Returns a new table with an additional row whose cells contain the totals of each column. SeeTable.Sequence.sum(Function)
.- Returns:
- the new table
-
addTotalColumn
Returns a new table with an additional column whose cells contain the totals of each row. SeeTable.Sequence.sum(Function)
.- Parameters:
function
- a function for converting the values of the cells in each row toNumber
s that will be applied to each cell value before adding it to the sum- Returns:
- the new table
-
addTotalColumn
Returns a new table with an additional column whose cells contain the totals of each row. SeeTable.Sequence.sum(Function)
.- Returns:
- the new table
-
addAverageRow
Returns a new table with an additional row whose cells contain the averages of each column. SeeTable.Sequence.average(Function)
.- Parameters:
function
- a function for converting the values of the cells in each column toNumber
s that will be applied to each cell value before including it in the average- Returns:
- the new table
-
addAverageRow
Returns a new table with an additional row whose cells contain the averages of each column. SeeTable.Sequence.average(Function)
.- Returns:
- the new table
-
addAverageColumn
Returns a new table with an additional column whose cells contain the averages of each row. SeeTable.Sequence.average(Function)
.- Parameters:
function
- a function for converting the values of the cells in each row toNumber
s that will be applied to each cell value before including it in the average- Returns:
- the new table
-
addAverageColumn
Returns a new table with an additional column whose cells contain the averages of each row. SeeTable.Sequence.average(Function)
.- Returns:
- the new table
-
transform
public Table transform(Predicate<? super Table.Row> rows, Predicate<? super Table.Column> columns, Function<Object, ?> transform) Returns a new table which only keeps the row and columns of this table that are identified by two predicates and whose cell values are the results of applying the given function to the values in this table.- Parameters:
rows
- a predicate describing which rows to copycolumns
- a predicate describing which columns to copytransform
- a function to transform the values of the cells- Returns:
- the new table
-
transform
Returns a new table which only keeps the row and columns of this table that are identified by two predicates.- Parameters:
rows
- a predicate describing which rows to copycolumns
- a predicate describing which columns to copy- Returns:
- the new table
-
transform
Returns a new table whose cell values are the results of applying the given function to the values in this table.- Parameters:
transform
- a function to transform the values of the cells- Returns:
- the new table
-
sort
public Table sort(Comparator<? super Table.Row> rowComparator, Comparator<? super Table.Column> columnComparator) Returns a new table whose rows and columns have been sorted according to the given comparators.- Parameters:
rowComparator
- defines how the rows should be sortedcolumnComparator
- defined how the columns should be sorted- Returns:
- the new table
-
sortByRow
Returns a new table whose rows have been sorted according to the given comparator.- Parameters:
comparator
- defines how the rows should be sorted- Returns:
- the new table
-
sortByColumn
Returns a new table whose columns have been sorted according to the given comparator.- Parameters:
comparator
- defines how the columns should be sorted- Returns:
- the new table
-
toHTML
Returns an HTML representation of this table.- Returns:
- an HTML string
-