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) {
CellType type = c.getCellTypeEnum();
CellType type = c.getCellType();
if (type == CellType.FORMULA) {
type = c.getCachedFormulaResultTypeEnum();
type = c.getCachedFormulaResultType();
}
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
*/
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
);
}

View File

@ -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());

View File

@ -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());

View File

@ -269,13 +269,13 @@ public class XSSFExportToXml implements Comparator<String>{
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)) {

View File

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

View File

@ -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 <c><v/></c>
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);

View File

@ -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();

View File

@ -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