Class TableBuilder
java.lang.Object
com.nsdev.lettergenerator.builder.TableBuilder
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 Summary
ConstructorsConstructorDescriptionTableBuilder(String... headers) Creates a table whose header array fixes the number of columns. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Snapshots headers, appended rows, relative widths and current styles into a table block.cellAppearance(CellAppearance value) Replaces cell appearance defaults while retaining configured row policies.columnWeights(double... values) Replaces column widths with relative, unitless weights.headerBackground(String color) Replaces the header-cell background color, initially#10384A.headerCells(TableCell... cells) Replaces the repeating header with typed cells; an empty array removes the header.headerStyle(Style value) Replaces the header style overrides, overlaid on the default bold white text.options(TableOptions value) Replaces all cell defaults and row metadata with one immutable options value.Appends one data row, copying its cell strings into plain text runs.Appends a typed row, allowing spans and block content.Appends typed cells through an explicit varargs entry point, including a fully spanned empty row.rowGroup(TableRowGroup value) Appends a consecutive body-row group.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.rowPolicy(TableRowPolicy value) Appends an explicit body-row override.Replaces the table's inherited text and spacing style.
-
Constructor Details
-
TableBuilder
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
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
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
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
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
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
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
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
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
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
Replaces column widths with relative, unitless weights. For example,1, 2gives 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
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- ifvalueis null
-
headerStyle
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- ifvalueis null
-
headerBackground
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- ifcoloris null
-
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
-