From 894341e53cfbc77aa4c8d524a3f8bf8863643364 Mon Sep 17 00:00:00 2001 From: Felipe Lang Date: Mon, 11 Dec 2023 14:22:52 -0300 Subject: [PATCH] refactor: use for loop to improve readability --- .../gridexporter/ExcelInputStreamFactory.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelInputStreamFactory.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelInputStreamFactory.java index 2347eeb..8a39829 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelInputStreamFactory.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelInputStreamFactory.java @@ -235,22 +235,22 @@ private int fillData( Sheet sheet, Cell dataCell, DataProvider dataProvider, CellRangeAddress dataRange, boolean titleExists) { Stream dataStream = obtainDataStream(dataProvider); - boolean[] notFirstRow = new boolean[1]; - Cell[] startingCell = new Cell[1]; - startingCell[0] = dataCell; - dataStream.forEach( - t -> { - if (notFirstRow[0]) { - CellStyle cellStyle = startingCell[0].getCellStyle(); - Row newRow = sheet.createRow(startingCell[0].getRowIndex() + 1); - startingCell[0] = newRow.createCell(startingCell[0].getColumnIndex()); - startingCell[0].setCellStyle(cellStyle); - } - // update the data range by updating last row - dataRange.setLastRow(dataRange.getLastRow() + 1); - buildRow(t, sheet, startingCell[0]); - notFirstRow[0] = true; - }); + boolean notFirstRow = false; + Cell startingCell = dataCell; + + Iterable items = dataStream::iterator; + for (T item : items) { + if (notFirstRow) { + CellStyle cellStyle = startingCell.getCellStyle(); + Row newRow = sheet.createRow(startingCell.getRowIndex() + 1); + startingCell = newRow.createCell(startingCell.getColumnIndex()); + startingCell.setCellStyle(cellStyle); + } + // update the data range by updating last row + dataRange.setLastRow(dataRange.getLastRow() + 1); + buildRow(item, sheet, startingCell); + notFirstRow = true; + } // since we initialized the cell range with the data placeholder cell, we use // the existing 'getLastColumn' to keep the offset of the data range dataRange.setLastColumn(dataRange.getLastColumn() + exporter.getColumns().size() - 1);