Class TableBuilder

java.lang.Object
com.nsdev.lettergenerator.builder.TableBuilder

public final class TableBuilder extends Object
Mutable table builder with a fixed column count and ordered, appended rows. Obtain one from Table.builder(String...) or its constructor. Columns start with equal relative weights; string header cells default to bold white text on #10384A. Configuration calls replace their option, and build() takes an independent immutable snapshot for a letter's body.
  • Constructor Details

    • TableBuilder

      public TableBuilder(String... headers)
      Creates a table whose header array fixes the number of columns. Header strings are snapshotted; empty strings are accepted. At least one data row is needed before building.
      Parameters:
      headers - non-null array containing at least one non-null header string
      Throws:
      IllegalArgumentException - if headers are null or empty, or contain null
  • Method Details

    • row

      public TableBuilder row(String... values)
      Appends one data row, copying its cell strings into plain text runs. Later header style changes affect header cells only.
      Parameters:
      values - non-null array with one non-null string per column, in column order
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the array or a cell is null, or its length differs from the header count
    • row

      public TableBuilder row(List<TableCell> cells)
      Appends a typed row, allowing spans and block content. An empty row is useful when earlier row spans cover every column. Complete grid validation occurs during generation.
      Parameters:
      cells - nonnull ordered row cells
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the list or a cell is null
    • rowCells

      public TableBuilder rowCells(TableCell... cells)
      Appends typed cells through an explicit varargs entry point, including a fully spanned empty row. Grid shape and content values are checked during generation.
      Parameters:
      cells - nonnull array of nonnull cells
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the array or any cell is null
    • headerCells

      public TableBuilder headerCells(TableCell... cells)
      Replaces the repeating header with typed cells; an empty array removes the header. Typed headers use their own typography and appearance instead of the string-header defaults.
      Parameters:
      cells - nonnull array of nonnull header cells
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the array or any cell is null
    • cellAppearance

      public TableBuilder cellAppearance(CellAppearance value)
      Replaces cell appearance defaults while retaining configured row policies.
      Parameters:
      value - nonnull defaults independently inherited by each cell
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • rowKeepTogether

      public TableBuilder rowKeepTogether(Keep value)
      Sets the default row split control; AUTO permits normal splits, PREFER is the legacy soft keep, and ALWAYS strongly requests intact rows.
      Parameters:
      value - nonnull default row keep
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • rowPolicy

      public TableBuilder rowPolicy(TableRowPolicy value)
      Appends an explicit body-row override. Duplicate or out-of-range indices fail during generation, after all rows have been appended.
      Parameters:
      value - nonnull indexed row policy
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • rowGroup

      public TableBuilder rowGroup(TableRowGroup value)
      Appends a consecutive body-row group. Groups must be disjoint and within the completed table; their keep strength also applies between member rows.
      Parameters:
      value - nonnull row group
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • options

      public TableBuilder options(TableOptions value)
      Replaces all cell defaults and row metadata with one immutable options value.
      Parameters:
      value - nonnull complete table options
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • columnWeights

      public TableBuilder columnWeights(double... values)
      Replaces column widths with relative, unitless weights. For example, 1, 2 gives the second column twice the first column's width. The values are copied; equal weights are the default.
      Parameters:
      values - one finite positive weight per column, with a finite sum
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the array is null, its length differs from the column count, any value is nonpositive or nonfinite, or their sum is nonfinite
    • style

      public TableBuilder style(Style value)
      Replaces the table's inherited text and spacing style. Detailed style validation is deferred to PDF generation.
      Parameters:
      value - non-null table style
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • headerStyle

      public TableBuilder headerStyle(Style value)
      Replaces the header style overrides, overlaid on the default bold white text. This does not change the separately configured header background.
      Parameters:
      value - non-null style whose specified fields override the header defaults
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if value is null
    • headerBackground

      public TableBuilder headerBackground(String color)
      Replaces the header-cell background color, initially #10384A. Color syntax is validated during PDF generation.
      Parameters:
      color - non-null color string in the model's supported hex notation
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if color is null
    • build

      public TableBlock build()
      Snapshots headers, appended rows, relative widths and current styles into a table block. The builder can be changed and built again without changing earlier blocks.
      Returns:
      an immutable table block for a letter body
      Throws:
      IllegalStateException - if no data row has been added