From 52320e3213c882049a2b20f259f0c430dd0f94b8 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 24 Apr 2020 20:58:32 +0000 Subject: [PATCH] Fix some IDE warnings, remove usage of deprecated methods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876947 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFCell.java | 6 ++-- .../org/apache/poi/ss/usermodel/Cell.java | 3 +- .../xssf/streaming/SXSSFEvaluationCell.java | 8 ++--- .../poi/xssf/streaming/TestSXSSFCell.java | 3 +- .../poi/hssf/model/TestFormulaParser.java | 30 ++++++++++--------- .../apache/poi/ss/usermodel/BaseTestCell.java | 13 ++++---- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 80e066fd91..bac2af5553 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -839,7 +839,7 @@ public class HSSFCell extends CellBase { case STRING: int sstIndex = ((LabelSSTRecord)_record).getSSTIndex(); String text = _book.getWorkbook().getSSTString(sstIndex).getString(); - return Boolean.valueOf(text).booleanValue(); + return Boolean.parseBoolean(text); case NUMERIC: return ((NumberRecord)_record).getValue() != 0; @@ -1028,7 +1028,7 @@ public class HSSFCell extends CellBase { * Errors are displayed as #ERR<errIdx> */ public String toString() { - switch (getCellTypeEnum()) { + switch (getCellType()) { case BLANK: return ""; case BOOLEAN: @@ -1125,7 +1125,7 @@ public class HSSFCell extends CellBase { link.setFirstColumn(_record.getColumn()); link.setLastColumn(_record.getColumn()); - switch(link.getTypeEnum()){ + switch(link.getType()){ case EMAIL: case URL: link.setLabel("url"); diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index ad26ed0882..78c6ae242d 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -123,7 +123,8 @@ public interface Cell { * @return the cell type * @since POI 3.15 beta 3 * @deprecated will be removed in 4.2 - * Will be renamed to getCellType() when we make the CellType enum transition in POI 4.0. See bug 59791. + * Use getCellType() + * Was renamed to getCellType() when we made the CellType enum transition in POI 4.0. See bug 59791. */ @Deprecated @Removal(version="4.2") diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java index 31d1b59288..4faf8c2507 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java @@ -71,7 +71,7 @@ final class SXSSFEvaluationCell implements EvaluationCell { @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { - return _cell.getCellTypeEnum(); + return _cell.getCellType(); } @Override public int getColumnIndex() { @@ -97,17 +97,17 @@ final class SXSSFEvaluationCell implements EvaluationCell { public String getStringCellValue() { return _cell.getRichStringCellValue().getString(); } - + @Override public CellRangeAddress getArrayFormulaRange() { return _cell.getArrayFormulaRange(); } - + @Override public boolean isPartOfArrayFormulaGroup() { return _cell.isPartOfArrayFormulaGroup(); } - + /** * @return cell type of cached formula result */ diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java index 31c0c61316..da6c796108 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java @@ -98,7 +98,7 @@ public class TestSXSSFCell extends BaseTestXCell { @Test public void getCellTypeEnumDelegatesToGetCellType() { SXSSFCell instance = spy(new SXSSFCell(null, CellType.BLANK)); - CellType result = instance.getCellTypeEnum(); + CellType result = instance.getCellType(); verify(instance).getCellType(); assertEquals(CellType.BLANK, result); } @@ -107,6 +107,7 @@ public class TestSXSSFCell extends BaseTestXCell { public void getCachedFormulaResultTypeEnum_delegatesTo_getCachedFormulaResultType() { SXSSFCell instance = spy(new SXSSFCell(null, CellType.BLANK)); instance.setCellFormula(""); + //noinspection deprecation instance.getCachedFormulaResultTypeEnum(); verify(instance).getCachedFormulaResultType(); } diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index 8c0cf9b82f..5a88f460b8 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -162,10 +162,12 @@ public final class TestFormulaParser { // Verify that myFunc and yourFunc were successfully added to Workbook names try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb)) { // HSSFWorkbook/EXCEL97-specific side-effects user-defined function names must be added to Workbook's defined names in order to be saved. - assertNotNull(wb2.getName("myFunc")); - assertEqualsIgnoreCase("myFunc", wb2.getName("myFunc").getNameName()); - assertNotNull(wb2.getName("yourFunc")); - assertEqualsIgnoreCase("yourFunc", wb2.getName("yourFunc").getNameName()); + HSSFName myFunc = wb2.getName("myFunc"); + assertNotNull(myFunc); + assertEqualsIgnoreCase("myFunc", myFunc.getNameName()); + HSSFName yourFunc = wb2.getName("yourFunc"); + assertNotNull(yourFunc); + assertEqualsIgnoreCase("yourFunc", yourFunc.getNameName()); // Manually check to make sure file isn't corrupted // TODO: develop a process for occasionally manually reviewing workbooks @@ -542,14 +544,14 @@ public final class TestFormulaParser { assertEquals("Cash_Flow!A1", formula); // Then the other - cell.setCellFormula("\'Test Sheet\'!A1"); + cell.setCellFormula("'Test Sheet'!A1"); formula = cell.getCellFormula(); - assertEquals("\'Test Sheet\'!A1", formula); + assertEquals("'Test Sheet'!A1", formula); // Now both - cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1"); + cell.setCellFormula("Cash_Flow:'Test Sheet'!A1"); formula = cell.getCellFormula(); - assertEquals("Cash_Flow:\'Test Sheet\'!A1", formula); + assertEquals("Cash_Flow:'Test Sheet'!A1", formula); // References to a range (area) of cells: @@ -560,14 +562,14 @@ public final class TestFormulaParser { assertEquals("Cash_Flow!A1:B2", formula); // Then the other - cell.setCellFormula("\'Test Sheet\'!A1:B2"); + cell.setCellFormula("'Test Sheet'!A1:B2"); formula = cell.getCellFormula(); - assertEquals("\'Test Sheet\'!A1:B2", formula); + assertEquals("'Test Sheet'!A1:B2", formula); // Now both - cell.setCellFormula("Cash_Flow:\'Test Sheet\'!A1:B2"); + cell.setCellFormula("Cash_Flow:'Test Sheet'!A1:B2"); formula = cell.getCellFormula(); - assertEquals("Cash_Flow:\'Test Sheet\'!A1:B2", formula); + assertEquals("Cash_Flow:'Test Sheet'!A1:B2", formula); wb.close(); } @@ -1085,13 +1087,13 @@ public final class TestFormulaParser { confirmTokenClasses(ptgs, ArrayPtg.class); Object element = ((ArrayPtg)ptgs[0]).getTokenArrayValues()[0][0]; - assertEquals(-42.0, ((Double)element).doubleValue(), 0.0); + assertEquals(-42.0, (Double) element, 0.0); // Should be able to handle whitespace between unary minus and digits (Excel // accepts this formula after presenting the user with a confirmation dialog). ptgs = parseFormula("{- 5}"); element = ((ArrayPtg)ptgs[0]).getTokenArrayValues()[0][0]; - assertEquals(-5.0, ((Double)element).doubleValue(), 0.0); + assertEquals(-5.0, (Double) element, 0.0); } @Test diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 2ab0f48b5e..e2032de2df 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -133,18 +133,15 @@ public abstract class BaseTestCell { assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, CellType.FORMULA, CellType.ERROR); - String strNull = null; - cell.setCellValue(strNull); + cell.setCellValue((String)null); assertEquals("", cell.getStringCellValue()); assertEquals(CellType.BLANK, cell.getCellType()); - LocalDate ldNull = null; - cell.setCellValue(ldNull); + cell.setCellValue((LocalDate)null); assertNull(cell.getLocalDateTimeCellValue()); assertEquals(CellType.BLANK, cell.getCellType()); - LocalDateTime ldtNull = null; - cell.setCellValue(ldtNull); + cell.setCellValue((LocalDateTime)null); assertNull(cell.getLocalDateTimeCellValue()); assertEquals(CellType.BLANK, cell.getCellType()); @@ -769,12 +766,12 @@ public abstract class BaseTestCell { Sheet sh = wb1.createSheet(); Row row = sh.createRow(0); Cell cell = row.createCell(0); - cell.setCellValue(Integer.valueOf(23)); + cell.setCellValue(23); cell.setCellValue("some"); cell = row.createCell(1); - cell.setCellValue(Integer.valueOf(23)); + cell.setCellValue(23); cell.setCellValue("24"); -- 2.39.5