Class TotalsTableBuilder

java.lang.Object
io.deephaven.engine.util.TotalsTableBuilder

@ScriptApi public class TotalsTableBuilder extends Object
Defines the default aggregations and display for a totals table.

The builder is intended to be used with the applyToTable(Table) method after the operations are applied.

  • 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

      @ScriptApi public TotalsTableBuilder setShowTotalsByDefault(boolean showTotalsByDefault)
      Set whether totals are shown by default.
      Parameters:
      showTotalsByDefault - whether totals are shown by default
      Returns:
      this TotalsTableBuilder
    • setShowGrandTotalsByDefault

      @ScriptApi public TotalsTableBuilder setShowGrandTotalsByDefault(boolean showGrandTotalsByDefault)
      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

      @ScriptApi public TotalsTableBuilder setDefaultOperation(String defaultOperation)
      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 on
      operation - the aggregation operation for this column
      format - 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 on
      operation - the aggregation operation for this column
      Returns:
      this TotalsTableBuilder
    • setOperation

      @ScriptApi public TotalsTableBuilder setOperation(String column, String operation)
      Sets the operation for a column.
      Parameters:
      column - the name of the column to operate on
      operation - the aggregation operation for this column
      Returns:
      this TotalsTableBuilder
    • setOperation

      @ScriptApi public TotalsTableBuilder setOperation(String column, String operation, String format)
      Sets the operation for a column.
      Parameters:
      column - the name of the column to operate on
      operation - the aggregation operation for this column
      format - 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 on
      operation - 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 on
      operation - the aggregation operation for this column
      format - the format string for this column
      Returns:
      this TotalsTableBuilder
    • addOperation

      @ScriptApi public TotalsTableBuilder addOperation(String column, String operation, String format)
      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 on
      operation - the aggregation operation for this column
      format - the format string for this column
      Returns:
      this TotalsTableBuilder
    • addOperation

      @ScriptApi public TotalsTableBuilder addOperation(String column, String 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 on
      operation - the aggregation operation for this column
      Returns:
      this TotalsTableBuilder
    • getOperations

      @NotNull public @NotNull Set<TotalsTableBuilder.AggType> getOperations(String column)
      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

      public TotalsTableBuilder.AggType 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 for
      agg - the aggregation type the format is relevant for
      format - the format string
      Returns:
      this TotalsTableBuilder
    • setFormat

      @ScriptApi public TotalsTableBuilder setFormat(String column, String agg, String format)
      Sets the format of a column.
      Parameters:
      column - the column to set the format for
      agg - the aggregation type the format is relevant for, "*" for all aggregations
      format - the format string
      Returns:
      this TotalsTableBuilder
    • getFormats

      @NotNull public @NotNull Map<TotalsTableBuilder.AggType,String> getFormats(String column)
      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

      public String buildDirective()
      Creates the string directive used to set the Table attribute.
      Returns:
      the attribute string representing this TotalsTableBuilder.
    • applyToTable

      @ScriptApi public Table applyToTable(@NotNull @NotNull Table table)
      Helper method for building and applying a totals table to a Table.
      Parameters:
      table - The source Table
      Returns:
      table.setTotalsTable(buildDirective())
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • makeTotalsTable

      public static Table makeTotalsTable(Table source)
      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

      public static TotalsTableBuilder get(Table source)
      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

      public static TotalsTableBuilder fromDirective(String directive)
      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

      public static boolean hasDefinedTotals(Table source)
      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 table
      builder - the TotalsTableBuilder
      groupByColumns - the columns to group by
      Returns:
      an aggregated totals table
    • makeAggregations

      public static Collection<? extends Aggregation> makeAggregations(Table source, TotalsTableBuilder builder)
      Produce aggregationsfrom a source table and builder.
      Parameters:
      source - the source table
      builder - the TotalsTableBuilder
      Returns:
      the aggregations described by source and builder.
    • operationApplies

      public static boolean operationApplies(Class type, TotalsTableBuilder.AggType operation)
      Does the operation apply to type?
      Parameters:
      type - the column type
      operation - the aggregation operation
      Returns:
      true if the operation is applicable to columns of this type