TSK-1344: Added public method Report#createRow to allow manual addition of report rows

This commit is contained in:
Mustapha Zorgati 2020-07-29 14:17:03 +02:00
parent 4fea8b5402
commit d62184df2c
1 changed files with 7 additions and 5 deletions

View File

@ -34,8 +34,8 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
protected Report(List<H> columnHeaders, String[] rowDesc) {
this.rowDesc = rowDesc;
sumRow = createRow("Total", columnHeaders.size());
this.columnHeaders = new ArrayList<>(columnHeaders);
sumRow = createRow("Total");
}
public final Map<String, Row<I>> getRows() {
@ -69,16 +69,14 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
public final void addItem(I item) {
Row<I> row = null;
if (columnHeaders.isEmpty()) {
row = reportRows.computeIfAbsent(item.getKey(), key -> createRow(key, columnHeaders.size()));
row = reportRows.computeIfAbsent(item.getKey(), this::createRow);
row.updateTotalValue(item);
sumRow.updateTotalValue(item);
} else {
for (int i = 0; i < columnHeaders.size(); i++) {
if (columnHeaders.get(i).fits(item)) {
if (row == null) {
row =
reportRows.computeIfAbsent(
item.getKey(), key -> createRow(key, columnHeaders.size()));
row = reportRows.computeIfAbsent(item.getKey(), this::createRow);
}
row.addItem(item, i);
sumRow.addItem(item, i);
@ -104,6 +102,10 @@ public abstract class Report<I extends QueryItem, H extends ColumnHeader<? super
sumRow.setDisplayName(displayMap);
}
public final Row<I> createRow(String key) {
return createRow(key, columnHeaders.size());
}
protected Row<I> createRow(String key, int columnSize) {
return new SingleRow<>(key, columnSize);
}