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
This commit is contained in:
PJ Fanning 2017-09-18 13:38:07 +00:00
parent d4486af6de
commit 4a4c428b6b
9 changed files with 36 additions and 36 deletions

View File

@ -340,9 +340,9 @@ public class ToHtml {
} }
private static CellType ultimateCellType(Cell c) { private static CellType ultimateCellType(Cell c) {
CellType type = c.getCellTypeEnum(); CellType type = c.getCellType();
if (type == CellType.FORMULA) { if (type == CellType.FORMULA) {
type = c.getCachedFormulaResultTypeEnum(); type = c.getCachedFormulaResultType();
} }
return type; return type;
} }

View File

@ -255,10 +255,10 @@ public class DataValidationEvaluator {
* @return true if the cell or cached cell formula result type match the given type * @return true if the cell or cached cell formula result type match the given type
*/ */
public static boolean isType(Cell cell, CellType type) { public static boolean isType(Cell cell, CellType type) {
final CellType cellType = cell.getCellTypeEnum(); final CellType cellType = cell.getCellType();
return cellType == type return cellType == type
|| (cellType == CellType.FORMULA || (cellType == CellType.FORMULA
&& cell.getCachedFormulaResultTypeEnum() == type && cell.getCachedFormulaResultType() == type
); );
} }

View File

@ -250,7 +250,7 @@ public final class WorkbookEvaluator {
// avoid tracking dependencies to cells that have constant definition // avoid tracking dependencies to cells that have constant definition
boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true boolean shouldCellDependencyBeRecorded = _stabilityClassifier == null ? true
: !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex); : !_stabilityClassifier.isCellFinal(sheetIndex, rowIndex, columnIndex);
if (srcCell == null || srcCell.getCellTypeEnum() != CellType.FORMULA) { if (srcCell == null || srcCell.getCellType() != CellType.FORMULA) {
ValueEval result = getValueFromNonFormulaCell(srcCell); ValueEval result = getValueFromNonFormulaCell(srcCell);
if (shouldCellDependencyBeRecorded) { if (shouldCellDependencyBeRecorded) {
tracker.acceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result); tracker.acceptPlainValueDependency(_workbookIx, sheetIndex, rowIndex, columnIndex, result);
@ -288,7 +288,7 @@ public final class WorkbookEvaluator {
} catch (RuntimeException re) { } catch (RuntimeException re) {
if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) { if (re.getCause() instanceof WorkbookNotFoundException && _ignoreMissingWorkbooks) {
logInfo(re.getCause().getMessage() + " - Continuing with cached value!"); logInfo(re.getCause().getMessage() + " - Continuing with cached value!");
switch(srcCell.getCachedFormulaResultTypeEnum()) { switch(srcCell.getCachedFormulaResultType()) {
case NUMERIC: case NUMERIC:
result = new NumberEval(srcCell.getNumericCellValue()); result = new NumberEval(srcCell.getNumericCellValue());
break; break;
@ -306,7 +306,7 @@ public final class WorkbookEvaluator {
break; break;
case FORMULA: case FORMULA:
default: default:
throw new RuntimeException("Unexpected cell type '" + srcCell.getCellTypeEnum()+"' found!"); throw new RuntimeException("Unexpected cell type '" + srcCell.getCellType()+"' found!");
} }
} else { } else {
throw re; throw re;
@ -359,7 +359,7 @@ public final class WorkbookEvaluator {
if (cell == null) { if (cell == null) {
return BlankEval.instance; return BlankEval.instance;
} }
CellType cellType = cell.getCellTypeEnum(); CellType cellType = cell.getCellType();
switch (cellType) { switch (cellType) {
case NUMERIC: case NUMERIC:
return new NumberEval(cell.getNumericCellValue()); return new NumberEval(cell.getNumericCellValue());

View File

@ -138,11 +138,11 @@ public class SheetUtil {
} }
CellStyle style = cell.getCellStyle(); 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 // for formula cells we compute the cell width for the cached formula result
if (cellType == CellType.FORMULA) if (cellType == CellType.FORMULA)
cellType = cell.getCachedFormulaResultTypeEnum(); cellType = cell.getCachedFormulaResultType();
Font font = wb.getFontAt(style.getFontIndex()); Font font = wb.getFontAt(style.getFontIndex());

View File

@ -269,13 +269,13 @@ public class XSSFExportToXml implements Comparator<String>{
private void mapCellOnNode(XSSFCell cell, Node node) { private void mapCellOnNode(XSSFCell cell, Node node) {
String value =""; String value ="";
switch (cell.getCellTypeEnum()) { switch (cell.getCellType()) {
case STRING: value = cell.getStringCellValue(); break; case STRING: value = cell.getStringCellValue(); break;
case BOOLEAN: value += cell.getBooleanCellValue(); break; case BOOLEAN: value += cell.getBooleanCellValue(); break;
case ERROR: value = cell.getErrorCellString(); break; case ERROR: value = cell.getErrorCellString(); break;
case FORMULA: case FORMULA:
if (cell.getCachedFormulaResultTypeEnum() == CellType.STRING) { if (cell.getCachedFormulaResultType() == CellType.STRING) {
value = cell.getStringCellValue(); value = cell.getStringCellValue();
} else { } else {
if (DateUtil.isCellDateFormatted(cell)) { if (DateUtil.isCellDateFormatted(cell)) {

View File

@ -262,7 +262,7 @@ public class SheetDataWriter implements Closeable {
_out.write("><f>"); _out.write("><f>");
outputQuotedString(cell.getCellFormula()); outputQuotedString(cell.getCellFormula());
_out.write("</f>"); _out.write("</f>");
switch (cell.getCachedFormulaResultTypeEnum()) { switch (cell.getCachedFormulaResultType()) {
case NUMERIC: case NUMERIC:
double nval = cell.getNumericCellValue(); double nval = cell.getNumericCellValue();
if (!Double.isNaN(nval)) { if (!Double.isNaN(nval)) {

View File

@ -303,10 +303,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Sheet s = wb.getSheetAt(i); Sheet s = wb.getSheetAt(i);
for (Row r : s) { for (Row r : s) {
for (Cell c : r) { for (Cell c : r) {
if (c.getCellTypeEnum() == CellType.FORMULA) { if (c.getCellType() == CellType.FORMULA) {
CellValue cv = eval.evaluate(c); CellValue cv = eval.evaluate(c);
if (cv.getCellTypeEnum() == CellType.NUMERIC) { if (cv.getCellType() == CellType.NUMERIC) {
// assert that the calculated value agrees with // assert that the calculated value agrees with
// the cached formula result calculated by Excel // the cached formula result calculated by Excel
String formula = c.getCellFormula(); String formula = c.getCellFormula();
@ -427,7 +427,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
cell = sheet.getRow(0).getCell(0); cell = sheet.getRow(0).getCell(0);
assertEquals("#REF!*#REF!", cell.getCellFormula()); 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()); assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());
Name nm1 = wb.getName("sale_1"); Name nm1 = wb.getName("sale_1");
@ -439,7 +439,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
cell = sheet.getRow(1).getCell(0); cell = sheet.getRow(1).getCell(0);
assertEquals("sale_1*sale_2", cell.getCellFormula()); 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()); assertEquals("#REF!", FormulaError.forInt(cell.getErrorCellValue()).getString());
wb.close(); wb.close();
@ -645,7 +645,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
for (Row row : sheet) { for (Row row : sheet) {
for (Cell cell : row) { for (Cell cell : row) {
if (cell.getCellTypeEnum() == CellType.FORMULA) { if (cell.getCellType() == CellType.FORMULA) {
formulaEvaluator.evaluateInCell(cell); // caused NPE on some cells 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 // Get wrong cell by row 8 & column 7
Cell cell = sheet.getRow(8).getCell(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 <c><v/></c> // Check the value - will be zero as it is <c><v/></c>
assertEquals(0.0, cell.getNumericCellValue(), 0.001); assertEquals(0.0, cell.getNumericCellValue(), 0.001);
@ -2181,11 +2181,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Sheet sheet = wb.getSheet("Sheet1"); Sheet sheet = wb.getSheet("Sheet1");
Cell cell = sheet.getRow(5).getCell(4); Cell cell = sheet.getRow(5).getCell(4);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("E4+E5", cell.getCellFormula()); assertEquals("E4+E5", cell.getCellFormula());
CellValue value = evaluator.evaluate(cell); CellValue value = evaluator.evaluate(cell);
assertEquals(CellType.ERROR, value.getCellTypeEnum()); assertEquals(CellType.ERROR, value.getCellType());
assertEquals(-60, value.getErrorValue()); assertEquals(-60, value.getErrorValue());
assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString()); assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString());
assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString()); assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString());
@ -2535,7 +2535,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
if (cell == null) { if (cell == null) {
cell = row.createCell(cellnum); cell = row.createCell(cellnum);
} else { } else {
if (cell.getCellTypeEnum() == CellType.FORMULA) { if (cell.getCellType() == CellType.FORMULA) {
cell.setCellFormula(null); cell.setCellFormula(null);
cell.getCellStyle().setDataFormat((short) 0); 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) { private void assertFormula(Workbook wb, Cell intF, String expectedFormula, String expectedResultOrNull) {
assertEquals(CellType.FORMULA, intF.getCellTypeEnum()); assertEquals(CellType.FORMULA, intF.getCellType());
if (null == expectedResultOrNull) { if (null == expectedResultOrNull) {
assertEquals(CellType.ERROR, intF.getCachedFormulaResultTypeEnum()); assertEquals(CellType.ERROR, intF.getCachedFormulaResultType());
expectedResultOrNull = "#VALUE!"; expectedResultOrNull = "#VALUE!";
} else { } else {
assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultTypeEnum()); assertEquals(CellType.NUMERIC, intF.getCachedFormulaResultType());
} }
assertEquals(expectedFormula, intF.getCellFormula()); assertEquals(expectedFormula, intF.getCellFormula());
@ -2647,7 +2647,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Sheet sheet = wb.getSheet("Sheet1"); Sheet sheet = wb.getSheet("Sheet1");
for (Row aRow : sheet) { for (Row aRow : sheet) {
Cell cell = aRow.getCell(1); Cell cell = aRow.getCell(1);
if (cell.getCellTypeEnum() == CellType.FORMULA) { if (cell.getCellType() == CellType.FORMULA) {
String formula = cell.getCellFormula(); String formula = cell.getCellFormula();
//System.out.println("formula: " + formula); //System.out.println("formula: " + formula);
assertNotNull(formula); assertNotNull(formula);
@ -2934,14 +2934,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
row = worksheet.getRow(2); row = worksheet.getRow(2);
cell = row.getCell(1); cell = row.getCell(1);
assertEquals(CellType.BLANK, cell.getCellTypeEnum()); assertEquals(CellType.BLANK, cell.getCellType());
assertEquals(CellType._NONE, evaluator.evaluateFormulaCellEnum(cell)); assertEquals(CellType._NONE, evaluator.evaluateFormulaCellEnum(cell));
// A3 // A3
row = worksheet.getRow(2); row = worksheet.getRow(2);
cell = row.getCell(0); cell = row.getCell(0);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("IF(ISBLANK(B3),\"\",B3)", cell.getCellFormula()); assertEquals("IF(ISBLANK(B3),\"\",B3)", cell.getCellFormula());
assertEquals(CellType.STRING, evaluator.evaluateFormulaCellEnum(cell)); assertEquals(CellType.STRING, evaluator.evaluateFormulaCellEnum(cell));
CellValue value = evaluator.evaluate(cell); CellValue value = evaluator.evaluate(cell);
@ -2951,7 +2951,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
row = worksheet.getRow(4); row = worksheet.getRow(4);
cell = row.getCell(0); cell = row.getCell(0);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum()); assertEquals(CellType.FORMULA, cell.getCellType());
assertEquals("COUNTBLANK(A1:A4)", cell.getCellFormula()); assertEquals("COUNTBLANK(A1:A4)", cell.getCellFormula());
assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(cell)); assertEquals(CellType.NUMERIC, evaluator.evaluateFormulaCellEnum(cell));
value = evaluator.evaluate(cell); value = evaluator.evaluate(cell);
@ -3177,7 +3177,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
Row r = s.getRow(3); Row r = s.getRow(3);
Cell c = r.getCell(0); Cell c = r.getCell(0);
assertEquals(CellType.FORMULA, c.getCellTypeEnum()); assertEquals(CellType.FORMULA, c.getCellType());
System.out.println(c.getCellFormula()); System.out.println(c.getCellFormula());
eval.setDebugEvaluationOutputForNextEval(true); eval.setDebugEvaluationOutputForNextEval(true);
CellValue cv = eval.evaluate(c); CellValue cv = eval.evaluate(c);

View File

@ -592,9 +592,9 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); 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(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()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,1).getErrorCellValue());
wb.close(); wb.close();
@ -613,11 +613,11 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); 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(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(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()); assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 3).getErrorCellValue());
wb.close(); wb.close();

View File

@ -417,7 +417,7 @@ public final class TestHSSFCell extends BaseTestCell {
assertEquals(wb.getWorkbook(), cell.getBoundWorkbook()); assertEquals(wb.getWorkbook(), cell.getBoundWorkbook());
try { try {
cell.getCachedFormulaResultTypeEnum(); cell.getCachedFormulaResultType();
fail("Should catch exception"); fail("Should catch exception");
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// expected here // expected here