This is an automated email from the ASF dual-hosted git repository. centic pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/poi.git
commit dc2cfe0bfce4d87dcf8ae72737bde4d2e96d7590 Author: Dominik Stadler <[email protected]> AuthorDate: Mon Apr 21 20:20:35 2025 +0200 Apply IDE suggestions --- .../poi/xssf/streaming/DeferredSXSSFWorkbook.java | 10 ++-- .../apache/poi/ss/formula/TestEvaluationCache.java | 58 +++++++++++----------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java index 5844eb9800..36c367e3c9 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFWorkbook.java @@ -30,7 +30,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; /** - * An variant of SXSSFWorkbook that avoids generating a temporary file and writes data directly to + * A variant of SXSSFWorkbook that avoids generating a temporary file and writes data directly to * the provided OutputStream. * * This variant is experimental and APIs may change at short notice. @@ -57,7 +57,7 @@ public class DeferredSXSSFWorkbook extends SXSSFWorkbook { @NotImplemented @Override - protected SheetDataWriter createSheetDataWriter() throws IOException { + protected SheetDataWriter createSheetDataWriter() { throw new IllegalStateException("Not supported by DeferredSXSSFWorkbook"); } @@ -66,11 +66,9 @@ public class DeferredSXSSFWorkbook extends SXSSFWorkbook { } @Override - protected ISheetInjector createSheetInjector(SXSSFSheet sxSheet) throws IOException { + protected ISheetInjector createSheetInjector(SXSSFSheet sxSheet) { DeferredSXSSFSheet ssxSheet = (DeferredSXSSFSheet) sxSheet; - return (output) -> { - ssxSheet.writeRows(output); - }; + return ssxSheet::writeRows; } @Override diff --git a/poi/src/test/java/org/apache/poi/ss/formula/TestEvaluationCache.java b/poi/src/test/java/org/apache/poi/ss/formula/TestEvaluationCache.java index 6af211e7cf..21a318f8b1 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/TestEvaluationCache.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/TestEvaluationCache.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -669,44 +670,41 @@ class TestEvaluationCache { } @Test - void testPlainValueCache() { + void testPlainValueCache() throws IOException { + try (Workbook wb = new HSSFWorkbook()) { + int numberOfSheets = 4098; // Bug 51448 reported that Evaluation Cache got messed up after 256 sheets - Workbook wb = new HSSFWorkbook(); - int numberOfSheets = 4098; // Bug 51448 reported that Evaluation Cache got messed up after 256 sheets + Row row; + Cell cell; - Row row; - Cell cell; + //create summary sheet + Sheet summary = wb.createSheet("summary"); + wb.setActiveSheet(wb.getSheetIndex(summary)); - //create summary sheet - Sheet summary = wb.createSheet("summary"); - wb.setActiveSheet(wb.getSheetIndex(summary)); + //formula referring all sheets created below + row = summary.createRow(0); + Cell summaryCell = row.createCell(0); + summaryCell.setCellFormula("SUM(A2:A" + (numberOfSheets + 2) + ")"); - //formula referring all sheets created below - row = summary.createRow(0); - Cell summaryCell = row.createCell(0); - summaryCell.setCellFormula("SUM(A2:A" + (numberOfSheets + 2) + ")"); + //create sheets with cells having (different) numbers + // and add a row to summary + for (int i = 1; i < numberOfSheets; i++) { + Sheet sheet = wb.createSheet("new" + i); + row = sheet.createRow(0); + cell = row.createCell(0); + cell.setCellValue(i); - //create sheets with cells having (different) numbers - // and add a row to summary - for (int i = 1; i < numberOfSheets; i++) { - Sheet sheet = wb.createSheet("new" + i); + row = summary.createRow(i); + cell = row.createCell(0); + cell.setCellFormula("new" + i + "!A1"); - row = sheet.createRow(0); - cell = row.createCell(0); - cell.setCellValue(i); - - row = summary.createRow(i); - cell = row.createCell(0); - cell.setCellFormula("new" + i + "!A1"); + } + //calculate + FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); + evaluator.evaluateFormulaCell(summaryCell); + assertEquals(8394753.0, summaryCell.getNumericCellValue(), 0); } - - - //calculate - FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); - evaluator.evaluateFormulaCell(summaryCell); - assertEquals(8394753.0, summaryCell.getNumericCellValue(), 0); } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
