diff --git a/archery/src/main/java/com/github/romualdrousseau/archery/intelli/IntelliTable.java b/archery/src/main/java/com/github/romualdrousseau/archery/intelli/IntelliTable.java index b0cf0e8..76d14e9 100644 --- a/archery/src/main/java/com/github/romualdrousseau/archery/intelli/IntelliTable.java +++ b/archery/src/main/java/com/github/romualdrousseau/archery/intelli/IntelliTable.java @@ -109,10 +109,12 @@ private void addTmpHeader(final BaseHeader header, final Set pivotEntryT if (header instanceof PivotKeyHeader) { final var pivotHeader = (PivotKeyHeader) header.clone(); + + if (!pivotEntryTypes.isEmpty()) { + pivotHeader.setEntryTypeValues(pivotEntryTypes); + } + if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) { - if (!pivotEntryTypes.isEmpty()) { - pivotHeader.setEntryTypeValues(pivotEntryTypes); - } this.addHeaderIntoTmpHeaders(pivotHeader, false); pivotHeader.getEntryTypeValues().forEach( x -> this.addHeaderIntoTmpHeaders(pivotHeader.getPivotTypeHeader().clone().setName(x), false)); @@ -191,20 +193,23 @@ private List emitAllRowsForOneRow(final BaseTableGraph graph, final DataTab } if (pivotKeyHeader == null) { this.emitOneRowWithoutPivot(graph, orgTable, orgRow, rowGroup).ifPresent(newRows::add); - } else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) { - pivotKeyHeader.getEntryPivotValues() - .forEach(x -> this - .emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x, - this.findTypeValue(orgTable, orgRow, pivotTypeHeader)) - .ifPresent(newRows::add)); - } else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) { - pivotKeyHeader.getEntries() - .forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x) - .ifPresent(newRows::add)); } else { - pivotKeyHeader.getEntries() - .forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x) - .ifPresent(newRows::add)); + final var typeValue = this.findTypeValue(orgTable, orgRow, pivotTypeHeader); + if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE_AND_VALUE) { + pivotKeyHeader.getEntryPivotValues() + .forEach(x -> this + .emitOneRowWithPivotTypeAndValue(graph, orgTable, orgRow, rowGroup, pivotKeyHeader, x, + typeValue) + .ifPresent(newRows::add)); + } else if (this.getSheet().getPivotOption() == PivotOption.WITH_TYPE) { + pivotKeyHeader.getEntries() + .forEach(x -> this.emitOneRowWithPivotAndType(graph, orgTable, orgRow, rowGroup, x, typeValue) + .ifPresent(newRows::add)); + } else { + pivotKeyHeader.getEntries() + .forEach(x -> this.emitOneRowWithPivot(graph, orgTable, orgRow, rowGroup, x, typeValue) + .ifPresent(newRows::add)); + } } return newRows; } @@ -257,10 +262,13 @@ private Optional emitOneRowWithPivotTypeAndValue(final BaseTableGraph graph } private Optional emitOneRowWithPivotAndType(final BaseTableGraph graph, final DataTable orgTable, - final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) { + final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) { if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) { return Optional.empty(); } + if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) { + return Optional.empty(); + } final var newRow = new Row(this.tmpHeaders.size()); for (final var tmpHeader : this.tmpHeaders) { @@ -283,10 +291,13 @@ private Optional emitOneRowWithPivotAndType(final BaseTableGraph graph, fin } private Optional emitOneRowWithPivot(final BaseTableGraph graph, final DataTable orgTable, - final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry) { + final BaseRow orgRow, final RowGroup rowGroup, final PivotEntry pivotEntry, final String typeValue) { if (!orgRow.getCellAt(pivotEntry.getCell().getColumnIndex()).hasValue()) { return Optional.empty(); } + if (typeValue != null && !typeValue.equals(pivotEntry.getTypeValue())) { + return Optional.empty(); + } final var newRow = new Row(this.tmpHeaders.size()); for (final var tmpHeader : this.tmpHeaders) {