From e3ddb77bc18cd01735d3ce98afecf6ec5ab984dd Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 18 Sep 2017 13:38:07 +0000 Subject: [PATCH] update getCellType to return CellType enum instead of int git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808703 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/examples/html/ToHtml.java | 4 +-- .../ss/formula/DataValidationEvaluator.java | 4 +-- .../poi/ss/formula/WorkbookEvaluator.java | 8 ++--- .../org/apache/poi/ss/util/SheetUtil.java | 4 +-- .../poi/xssf/extractor/XSSFExportToXml.java | 4 +-- .../poi/xssf/streaming/SheetDataWriter.java | 2 +- .../poi/xssf/usermodel/TestXSSFBugs.java | 34 +++++++++---------- .../usermodel/TestXSSFFormulaEvaluation.java | 10 +++--- .../poi/hssf/usermodel/TestHSSFCell.java | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java index 23a161830b..5f77d02ead 100644 --- a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java +++ b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java @@ -340,9 +340,9 @@ public class ToHtml { } private static CellType ultimateCellType(Cell c) { - CellType type = c.getCellTypeEnum(); + CellType type = c.getCellType(); if (type == CellType.FORMULA) { - type = c.getCachedFormulaResultTypeEnum(); + type = c.getCachedFormulaResultType(); } return type; } diff --git a/src/java/org/apache/poi/ss/formula/DataValidationEvaluator.java b/src/java/org/apache/poi/ss/formula/DataValidationEvaluator.java index 866669016f..c6dadfff7f 100644 --- a/src/java/org/apache/poi/ss/formula/DataValidationEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/DataValidationEvaluator.java @@ -255,10 +255,10 @@ public class DataValidationEvaluator { * @return true if the cell or cached cell formula result type match the given type */ public static boolean isType(Cell cell, CellType type) { - final CellType cellType = cell.getCellTypeEnum(); + final CellType cellType = cell.getCellType(); return cellType == type || (cellType == CellType.FORMULA - && cell.getCachedFormulaResultTypeEnum() == type + && cell.getCachedFormulaResultType() == type ); } diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index b1fe124d56..127978eedb 100644 --- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -250,7 +250,7 @@ public final class WorkbookEvaluator { // avoid tracking dependencies to cells that have constant definition boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true : !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex); - if (srcCell == null || srcCell.getCellTypeEnum() != CellType.FORMULA) { + if (srcCell == null || srcCell.getCellType() != CellType.FORMULA) { ValueEval result = getValueFromNonFormulaCell(srcCell); if (shouldCellDependencyBeRecorded) { tracker.acceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result); @@ -288,7 +288,7 @@ public final class WorkbookEvaluator { } catch (RuntimeException re) { if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) { logInfo(re.getCause().getMessage() + " - Continuing with cached value!"); - switch(srcCell.getCachedFormulaResultTypeEnum()) { + switch(srcCell.getCachedFormulaResultType()) { case NUMERIC: result = new NumberEval(srcCell.getNumericCellValue()); break; @@ -306,7 +306,7 @@ public final class WorkbookEvaluator { break; case FORMULA: default: - throw new RuntimeException("Unexpected cell type '" + srcCell.getCellTypeEnum()+"' found!"); + throw new RuntimeException("Unexpected cell type '" + srcCell.getCellType()+"' found!"); } } else { throw re; @@ -359,7 +359,7 @@ public final class WorkbookEvaluator { if (cell == null) { return BlankEval.instance; } - CellType cellType = cell.getCellTypeEnum(); + CellType cellType = cell.getCellType(); switch (cellType) { case NUMERIC: return new NumberEval(cell.getNumericCellValue()); diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java index 075420478e..e01b8a3b37 100644 --- a/src/java/org/apache/poi/ss/util/SheetUtil.java +++ b/src/java/org/apache/poi/ss/util/SheetUtil.java @@ -138,11 +138,11 @@ public class SheetUtil { } CellStyle style = cell.getCellStyle(); - CellType cellType = cell.getCellTypeEnum(); + CellType cellType = cell.getCellType(); // for formula cells we compute the cell width for the cached formula result if (cellType == CellType.FORMULA) - cellType = cell.getCachedFormulaResultTypeEnum(); + cellType = cell.getCachedFormulaResultType(); Font font = wb.getFontAt(style.getFontIndex()); diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index 0da032c592..4633df0434 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -269,13 +269,13 @@ public class XSSFExportToXml implements Comparator{ private void mapCellOnNode(XSSFCell cell, Node node) { String value =""; - switch (cell.getCellTypeEnum()) { + switch (cell.getCellType()) { case STRING: value = cell.getStringCellValue(); break; case BOOLEAN: value += cell.getBooleanCellValue(); break; case ERROR: value = cell.getErrorCellString(); break; case FORMULA: - if (cell.getCachedFormulaResultTypeEnum() == CellType.STRING) { + if (cell.getCachedFormulaResultType() == CellType.STRING) { value = cell.getStringCellValue(); } else { if (DateUtil.isCellDateFormatted(cell)) { diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index a32b8f3de2..19f6047d4f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -262,7 +262,7 @@ public class SheetDataWriter implements Closeable { _out.write(">"); outputQuotedString(cell.getCellFormula()); _out.write(""); - switch (cell.getCachedFormulaResultTypeEnum()) { + switch (cell.getCachedFormulaResultType()) { case NUMERIC: double nval = cell.getNumericCellValue(); if (!Double.isNaN(nval)) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 2fef668932..2b82e0fe4e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -303,10 +303,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Sheet s = wb.getSheetAt(i); for (Row r : s) { for (Cell c : r) { - if (c.getCellTypeEnum() == CellType.FORMULA) { + if (c.getCellType() == CellType.FORMULA) { CellValue cv = eval.evaluate(c); - if (cv.getCellTypeEnum() == CellType.NUMERIC) { + if (cv.getCellType() == CellType.NUMERIC) { // assert that the calculated value agrees with // the cached formula result calculated by Excel String formula = c.getCellFormula(); @@ -427,7 +427,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { cell = sheet.getRow(0).getCell(0); assertEquals("#REF!*#REF!", cell.getCellFormula()); - assertEquals(CellType.ERROR, evaluator.evaluateInCell(cell).getCellTypeEnum()); + assertEquals(CellType.ERROR, evaluator.evaluateInCell(cell).getCellType()); assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString()); Name nm1 = wb.getName("sale_1"); @@ -439,7 +439,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { cell = sheet.getRow(1).getCell(0); assertEquals("sale_1*sale_2", cell.getCellFormula()); - assertEquals(CellType.ERROR, evaluator.evaluateInCell(cell).getCellTypeEnum()); + assertEquals(CellType.ERROR, evaluator.evaluateInCell(cell).getCellType()); assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString()); wb.close(); @@ -645,7 +645,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Sheet sheet = wb.getSheetAt(0); for (Row row : sheet) { for (Cell cell : row) { - if (cell.getCellTypeEnum() == CellType.FORMULA) { + if (cell.getCellType() == CellType.FORMULA) { formulaEvaluator.evaluateInCell(cell); // caused NPE on some cells } } @@ -1696,7 +1696,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { // Get wrong cell by row 8 & column 7 Cell cell = sheet.getRow(8).getCell(7); - assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); + assertEquals(CellType.NUMERIC, cell.getCellType()); // Check the value - will be zero as it is assertEquals(0.0, cell.getNumericCellValue(), 0.001); @@ -2181,11 +2181,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Sheet sheet = wb.getSheet("Sheet1"); Cell cell = sheet.getRow(5).getCell(4); - assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("E4+E5", cell.getCellFormula()); CellValue value = evaluator.evaluate(cell); - assertEquals(CellType.ERROR, value.getCellTypeEnum()); + assertEquals(CellType.ERROR, value.getCellType()); assertEquals(-60, value.getErrorValue()); assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString()); assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString()); @@ -2535,7 +2535,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { if (cell == null) { cell = row.createCell(cellnum); } else { - if (cell.getCellTypeEnum() == CellType.FORMULA) { + if (cell.getCellType() == CellType.FORMULA) { cell.setCellFormula(null); cell.getCellStyle().setDataFormat((short) 0); } @@ -2601,12 +2601,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { } private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) { - assertEquals(CellType.FORMULA, intF.getCellTypeEnum()); + assertEquals(CellType.FORMULA, intF.getCellType()); if (null == expectedResultOrNull) { - assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, intF.getCachedFormulaResultType()); expectedResultOrNull = "#VALUE!"; } else { - assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum()); + assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultType()); } assertEquals(expectedFormula, intF.getCellFormula()); @@ -2647,7 +2647,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Sheet sheet = wb.getSheet("Sheet1"); for (Row aRow : sheet) { Cell cell = aRow.getCell(1); - if (cell.getCellTypeEnum() == CellType.FORMULA) { + if (cell.getCellType() == CellType.FORMULA) { String formula = cell.getCellFormula(); //System.out.println("formula: " + formula); assertNotNull(formula); @@ -2934,14 +2934,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { row = worksheet.getRow(2); cell = row.getCell(1); - assertEquals(CellType.BLANK, cell.getCellTypeEnum()); + assertEquals(CellType.BLANK, cell.getCellType()); assertEquals(CellType._NONE, evaluator.evaluateFormulaCellEnum(cell)); // A3 row = worksheet.getRow(2); cell = row.getCell(0); - assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("IF(ISBLANK(B3),\"\",B3)", cell.getCellFormula()); assertEquals(CellType.STRING, evaluator.evaluateFormulaCellEnum(cell)); CellValue value = evaluator.evaluate(cell); @@ -2951,7 +2951,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { row = worksheet.getRow(4); cell = row.getCell(0); - assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); + assertEquals(CellType.FORMULA, cell.getCellType()); assertEquals("COUNTBLANK(A1:A4)", cell.getCellFormula()); assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(cell)); value = evaluator.evaluate(cell); @@ -3177,7 +3177,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Row r = s.getRow(3); Cell c = r.getCell(0); - assertEquals(CellType.FORMULA, c.getCellTypeEnum()); + assertEquals(CellType.FORMULA, c.getCellType()); System.out.println(c.getCellFormula()); eval.setDebugEvaluationOutputForNextEval(true); CellValue cv = eval.evaluate(c); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java index e92143ca8b..c31b236380 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java @@ -592,9 +592,9 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator { wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); - assertEquals(CellType.ERROR, getCell(sheet, 0,0).getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, getCell(sheet, 0,0).getCachedFormulaResultType()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,0).getErrorCellValue()); - assertEquals(CellType.ERROR, getCell(sheet, 0,1).getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, getCell(sheet, 0,1).getCachedFormulaResultType()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,1).getErrorCellValue()); wb.close(); @@ -613,11 +613,11 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator { wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); - assertEquals(CellType.ERROR, getCell(sheet, 0, 0).getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, getCell(sheet, 0, 0).getCachedFormulaResultType()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 0).getErrorCellValue()); - assertEquals(CellType.ERROR, getCell(sheet, 1, 0).getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, getCell(sheet, 1, 0).getCachedFormulaResultType()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 1, 0).getErrorCellValue()); - assertEquals(CellType.ERROR, getCell(sheet, 0, 3).getCachedFormulaResultTypeEnum()); + assertEquals(CellType.ERROR, getCell(sheet, 0, 3).getCachedFormulaResultType()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 3).getErrorCellValue()); wb.close(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java index f6f8892587..a9cc347bef 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java @@ -417,7 +417,7 @@ public final class TestHSSFCell extends BaseTestCell { assertEquals(wb.getWorkbook(), cell.getBoundWorkbook()); try { - cell.getCachedFormulaResultTypeEnum(); + cell.getCachedFormulaResultType(); fail("Should catch exception"); } catch (IllegalStateException e) { // expected here -- 2.39.5