diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/QueryItem.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/QueryItem.java new file mode 100644 index 000000000..739282a3d --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/QueryItem.java @@ -0,0 +1,9 @@ +package pro.taskana.impl.report; + +public interface QueryItem { + + String getKey(); + + int getValue(); + +} \ No newline at end of file diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/Report.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/Report.java new file mode 100644 index 000000000..8928123d8 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/Report.java @@ -0,0 +1,48 @@ +package pro.taskana.impl.report; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public abstract class Report> { + + protected List columns = new ArrayList<>(); //this can be done as an array + private Map> reportLines = new LinkedHashMap<>(); + private ReportRow sumLine; + + public Report(List columns) { + sumLine = new ReportRow<>(columns.size()); + this.columns.addAll(columns); + } + + protected final void addItem(Item item) { + ReportRow row = reportLines.computeIfAbsent(item.getKey(), (s) -> createReportRow(columns.size())); + for (int i = 0; i < columns.size(); i++) { + if (columns.get(i).fits(item)) { + row.addItem(item, i); + sumLine.addItem(item, i); + } + } + } + + public ReportRow getRow(String key) { + return reportLines.get(key); + } + + public void addItems(List items) { + items.forEach(this::addItem); + } + + public final ReportRow getSumLine() { + return sumLine; + } + + public Map> getReportLines() { + return reportLines; + } + + protected ReportRow createReportRow(int columnSize) { + return new ReportRow<>(columnSize); + } +} \ No newline at end of file diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportColumnHeader.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportColumnHeader.java new file mode 100644 index 000000000..0d0739364 --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportColumnHeader.java @@ -0,0 +1,9 @@ +package pro.taskana.impl.report; + +public interface ReportColumnHeader { + + String displayName(); + + boolean fits(Item item); + +} \ No newline at end of file diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportRow.java b/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportRow.java new file mode 100644 index 000000000..3853847bd --- /dev/null +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/report/ReportRow.java @@ -0,0 +1,25 @@ +package pro.taskana.impl.report; + +public class ReportRow { + + private final int[] lineItems; + private int totalValue = 0; + + public ReportRow(int columnCount) { + //TODO: do you use an assert / throw an exception? + lineItems = new int[columnCount]; + } + + public int[] getLineItems() { + return lineItems; + } + + public int getTotalValue() { + return totalValue; + } + + public void addItem(Item item, int index) throws IndexOutOfBoundsException { + totalValue += item.getValue(); + lineItems[index] += item.getValue(); + } +} \ No newline at end of file