Class TotalsTableBuilder
The builder is intended to be used with the applyToTable(Table)
method after the operations are applied.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumeration representing valid aggregation types forTotalsTableBuilder
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddOperation
(String column, TotalsTableBuilder.AggType operation) Adds an operation for a column.addOperation
(String column, TotalsTableBuilder.AggType operation, String format) Adds an operation for a column.addOperation
(String column, String operation) Adds an operation for a column.addOperation
(String column, String operation, String format) Adds an operation for a column.applyToTable
(@NotNull Table table) Creates the string directive used to set the Table attribute.static TotalsTableBuilder
fromDirective
(String directive) Produce a TotalsTableBuilder from a directive string.static TotalsTableBuilder
Produce a totals table builder from the source table.Gets the operation to use for columns without an operation specified.@NotNull Map<TotalsTableBuilder.AggType,
String> getFormats
(String column) Gets the format for an aggregated column.@NotNull Set<TotalsTableBuilder.AggType>
getOperations
(String column) Gets the operations for a given column.boolean
Should grand totals be shown by default?boolean
Should totals be shown by default?static boolean
hasDefinedTotals
(Table source) Does a table have a totals table defined?static Collection<? extends Aggregation>
makeAggregations
(Table source, TotalsTableBuilder builder) Produceaggregations
from a source table and builder.static Table
makeTotalsTable
(Table source) Create a totals table from a source table.static Table
makeTotalsTable
(Table source, TotalsTableBuilder builder, String... groupByColumns) Given a source table, builder and aggregation columns build a totals table with multiple rows.static boolean
operationApplies
(Class type, TotalsTableBuilder.AggType operation) Does the operation apply to type?setDefaultOperation
(TotalsTableBuilder.AggType defaultOperation) Sets the operation for columns which are not otherwise specified.setDefaultOperation
(String defaultOperation) Sets the operation for columns which are not otherwise specified.setFormat
(String column, TotalsTableBuilder.AggType agg, String format) Sets the format of a column.Sets the format of a column.setOperation
(String column, TotalsTableBuilder.AggType operation) Sets the operation for a column.setOperation
(String column, TotalsTableBuilder.AggType operation, String format) Sets the operation for a column.setOperation
(String column, String operation) Sets the operation for a column.setOperation
(String column, String operation, String format) Sets the operation for a column.setShowGrandTotalsByDefault
(boolean showGrandTotalsByDefault) Set whether grand totals are shown by default.setShowTotalsByDefault
(boolean showTotalsByDefault) Set whether totals are shown by default.toString()
-
Constructor Details
-
TotalsTableBuilder
public TotalsTableBuilder()
-
-
Method Details
-
getShowTotalsByDefault
public boolean getShowTotalsByDefault()Should totals be shown by default?- Returns:
- true if totals should be shown by default
-
getShowGrandTotalsByDefault
public boolean getShowGrandTotalsByDefault()Should grand totals be shown by default?- Returns:
- true if grand totals should be shown by default
-
setShowTotalsByDefault
Set whether totals are shown by default.- Parameters:
showTotalsByDefault
- whether totals are shown by default- Returns:
- this TotalsTableBuilder
-
setShowGrandTotalsByDefault
Set whether grand totals are shown by default.- Parameters:
showGrandTotalsByDefault
- whether grand totals are shown by default- Returns:
- this TotalsTableBuilder
-
setDefaultOperation
@ScriptApi public TotalsTableBuilder setDefaultOperation(TotalsTableBuilder.AggType defaultOperation) Sets the operation for columns which are not otherwise specified.- Parameters:
defaultOperation
- the default operation- Returns:
- this TotalsTableBuilder
-
setDefaultOperation
Sets the operation for columns which are not otherwise specified.- Parameters:
defaultOperation
- the default operation- Returns:
- this TotalsTableBuilder
-
setOperation
@ScriptApi public TotalsTableBuilder setOperation(String column, TotalsTableBuilder.AggType operation, String format) Sets the operation for a column.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this columnformat
- the format string for this column- Returns:
- this TotalsTableBuilder
-
setOperation
@ScriptApi public TotalsTableBuilder setOperation(String column, TotalsTableBuilder.AggType operation) Sets the operation for a column.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this column- Returns:
- this TotalsTableBuilder
-
setOperation
Sets the operation for a column.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this column- Returns:
- this TotalsTableBuilder
-
setOperation
Sets the operation for a column.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this columnformat
- the format string for this column- Returns:
- this TotalsTableBuilder
-
addOperation
@ScriptApi public TotalsTableBuilder addOperation(String column, TotalsTableBuilder.AggType operation) Adds an operation for a column.The add method is used instead of the
setOperation(String, String)
method when more than one aggregation per input column is desired.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this column- Returns:
- this TotalsTableBuilder
-
addOperation
@ScriptApi public TotalsTableBuilder addOperation(String column, TotalsTableBuilder.AggType operation, String format) Adds an operation for a column.The add method is used instead of the
setOperation(String, AggType, String)
method when more than one aggregation per input column is desired.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this columnformat
- the format string for this column- Returns:
- this TotalsTableBuilder
-
addOperation
Adds an operation for a column.The add method is used instead of the
setOperation(String, String, String)
method when more than one aggregation per input column is desired.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this columnformat
- the format string for this column- Returns:
- this TotalsTableBuilder
-
addOperation
Adds an operation for a column.The add method is used instead of the
setOperation(String, String)
method when more than one aggregation per input column is desired.- Parameters:
column
- the name of the column to operate onoperation
- the aggregation operation for this column- Returns:
- this TotalsTableBuilder
-
getOperations
Gets the operations for a given column.- Parameters:
column
- the column to get the operations for- Returns:
- a set of aggregations for the column
-
getDefaultOperation
Gets the operation to use for columns without an operation specified.- Returns:
- the default operation
-
setFormat
@ScriptApi public TotalsTableBuilder setFormat(String column, TotalsTableBuilder.AggType agg, String format) Sets the format of a column.- Parameters:
column
- the column to set the format foragg
- the aggregation type the format is relevant forformat
- the format string- Returns:
- this TotalsTableBuilder
-
setFormat
Sets the format of a column.- Parameters:
column
- the column to set the format foragg
- the aggregation type the format is relevant for, "*" for all aggregationsformat
- the format string- Returns:
- this TotalsTableBuilder
-
getFormats
Gets the format for an aggregated column.- Parameters:
column
- the column to get the format for- Returns:
- a map from AggType to the corresponding format string
-
buildDirective
Creates the string directive used to set the Table attribute.- Returns:
- the attribute string representing this TotalsTableBuilder.
-
applyToTable
- Parameters:
table
- The sourceTable
- Returns:
table.setTotalsTable(buildDirective())
-
toString
-
makeTotalsTable
Create a totals table from a source table.Given a source table that has had a TotalsTableBuilder applied, create a new totals table from the table. If no TotalsTableBuilder has been applied, then the columns are summed.
- Parameters:
source
- the source table- Returns:
- an aggregated totals table
-
get
Produce a totals table builder from the source table.- Parameters:
source
- the source table- Returns:
- a TotalsTableBuilder derived from the source table's totals table attribute
-
fromDirective
Produce a TotalsTableBuilder from a directive string.The
buildDirective()
method produces a String representation of a TotalsTableBuilder, this function is its inverse.- Parameters:
directive
- the directive.- Returns:
- a TotalsTableBuilder
-
hasDefinedTotals
Does a table have a totals table defined?- Parameters:
source
- the source table- Returns:
- true if source has a totals table defined
-
makeTotalsTable
public static Table makeTotalsTable(Table source, TotalsTableBuilder builder, String... groupByColumns) Given a source table, builder and aggregation columns build a totals table with multiple rows.- Parameters:
source
- the source tablebuilder
- the TotalsTableBuildergroupByColumns
- the columns to group by- Returns:
- an aggregated totals table
-
makeAggregations
public static Collection<? extends Aggregation> makeAggregations(Table source, TotalsTableBuilder builder) Produceaggregations
from a source table and builder.- Parameters:
source
- the source tablebuilder
- the TotalsTableBuilder- Returns:
- the
aggregations
described by source and builder.
-
operationApplies
Does the operation apply to type?- Parameters:
type
- the column typeoperation
- the aggregation operation- Returns:
- true if the operation is applicable to columns of this type
-