Skip to content

Commit 894341e

Browse files
flangpaodb
authored andcommitted
refactor: use for loop to improve readability
1 parent 945c490 commit 894341e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelInputStreamFactory.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,22 @@ private int fillData(
235235
Sheet sheet, Cell dataCell, DataProvider<T, ?> dataProvider, CellRangeAddress dataRange, boolean titleExists) {
236236
Stream<T> dataStream = obtainDataStream(dataProvider);
237237

238-
boolean[] notFirstRow = new boolean[1];
239-
Cell[] startingCell = new Cell[1];
240-
startingCell[0] = dataCell;
241-
dataStream.forEach(
242-
t -> {
243-
if (notFirstRow[0]) {
244-
CellStyle cellStyle = startingCell[0].getCellStyle();
245-
Row newRow = sheet.createRow(startingCell[0].getRowIndex() + 1);
246-
startingCell[0] = newRow.createCell(startingCell[0].getColumnIndex());
247-
startingCell[0].setCellStyle(cellStyle);
248-
}
249-
// update the data range by updating last row
250-
dataRange.setLastRow(dataRange.getLastRow() + 1);
251-
buildRow(t, sheet, startingCell[0]);
252-
notFirstRow[0] = true;
253-
});
238+
boolean notFirstRow = false;
239+
Cell startingCell = dataCell;
240+
241+
Iterable<T> items = dataStream::iterator;
242+
for (T item : items) {
243+
if (notFirstRow) {
244+
CellStyle cellStyle = startingCell.getCellStyle();
245+
Row newRow = sheet.createRow(startingCell.getRowIndex() + 1);
246+
startingCell = newRow.createCell(startingCell.getColumnIndex());
247+
startingCell.setCellStyle(cellStyle);
248+
}
249+
// update the data range by updating last row
250+
dataRange.setLastRow(dataRange.getLastRow() + 1);
251+
buildRow(item, sheet, startingCell);
252+
notFirstRow = true;
253+
}
254254
// since we initialized the cell range with the data placeholder cell, we use
255255
// the existing 'getLastColumn' to keep the offset of the data range
256256
dataRange.setLastColumn(dataRange.getLastColumn() + exporter.getColumns().size() - 1);

0 commit comments

Comments
 (0)