From 16d262d0b439b6681d54d742301d570ee817b4c7 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 18 Sep 2017 10:50:50 +0000 Subject: [PATCH] Change getCachedFormulaResultType to return CellType git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808678 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFCell.java | 27 ++++++----- .../hssf/usermodel/HSSFEvaluationCell.java | 15 +++--- .../poi/ss/formula/BaseFormulaEvaluator.java | 47 +++++++++++-------- .../apache/poi/ss/formula/EvaluationCell.java | 9 ++-- .../eval/forked/ForkedEvaluationCell.java | 12 ++--- .../org/apache/poi/ss/usermodel/Cell.java | 6 +-- .../poi/ss/usermodel/FormulaEvaluator.java | 8 +++- .../org/apache/poi/ss/util/SheetUtil.java | 14 +++--- .../apache/poi/xssf/streaming/SXSSFCell.java | 28 +++++------ .../xssf/streaming/SXSSFEvaluationCell.java | 13 +++-- .../apache/poi/xssf/usermodel/XSSFCell.java | 24 ++++------ .../xssf/usermodel/XSSFEvaluationCell.java | 13 +++-- 12 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 4d711f0415..b18320c61b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -55,6 +55,7 @@ import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.util.Internal; import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.Removal; /** * High level representation of a cell in a row of a spreadsheet. @@ -1145,18 +1146,21 @@ public class HSSFCell implements Cell { /** * Only valid for formula cells - * - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula - * @deprecated 3.15. Will return a {@link CellType} enum in the future. + * + * @since POI 4.0 + * @return CellType depending + * on the cached value of the formula */ @Override - public int getCachedFormulaResultType() { - return getCachedFormulaResultTypeEnum().getCode(); + public CellType getCachedFormulaResultType() { + if (_cellType != CellType.FORMULA) { + throw new IllegalStateException("Only formula cells have cached results"); + } + int code = ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultType(); + return CellType.forInt(code); } /** @@ -1165,15 +1169,14 @@ public class HSSFCell implements Cell { * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula * @since POI 3.15 beta 3 + * @deprecated use getCachedFormulaResultType * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version="4.2") @Override public CellType getCachedFormulaResultTypeEnum() { - if (_cellType != CellType.FORMULA) { - throw new IllegalStateException("Only formula cells have cached results"); - } - int code = ((FormulaRecordAggregate)_record).getFormulaRecord().getCachedResultType(); - return CellType.forInt(code); + return getCachedFormulaResultType(); } void setCellArrayFormula(CellRangeAddress range) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java index 368b8abdc1..0cb4950300 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java @@ -21,6 +21,7 @@ import org.apache.poi.ss.formula.EvaluationCell; import org.apache.poi.ss.formula.EvaluationSheet; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.Removal; /** * HSSF wrapper for a cell under evaluation @@ -107,23 +108,21 @@ final class HSSFEvaluationCell implements EvaluationCell { } /** - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * + * @since POI 4.0 * @return cell type of cached formula result - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override - public int getCachedFormulaResultType() { - return _cell.getCachedFormulaResultType(); - } + public CellType getCachedFormulaResultType() { return _cell.getCachedFormulaResultType(); } + /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Override public CellType getCachedFormulaResultTypeEnum() { - return _cell.getCachedFormulaResultTypeEnum(); + return getCachedFormulaResultType(); } } diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index cc24a8b1fb..4bf033e366 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -27,6 +27,7 @@ import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.util.Removal; /** * Common functionality across file formats for evaluating formula cells.

@@ -143,24 +144,33 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook protected abstract CellValue evaluateFormulaCellValue(Cell cell); /** - * If cell contains formula, it evaluates the formula, and saves the result of the formula. The - * cell remains as a formula cell. If the cell does not contain formula, this method returns -1 - * and leaves the cell unchanged. - * - * Note that the type of the formula result is returned, so you know what kind of - * cached formula result is also stored with the formula. + * If cell contains formula, it evaluates the formula, + * and saves the result of the formula. The cell + * remains as a formula cell. + * Else if cell does not contain formula, this method leaves + * the cell unchanged. + * Note that the type of the formula result is returned, + * so you know what kind of value is also stored with + * the formula. *

-     * int evaluatedCellType = evaluator.evaluateFormulaCell(cell);
+     * CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
      * 
- * Be aware that your cell will hold both the formula, and the result. If you want the cell - * replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)} + * Be aware that your cell will hold both the formula, + * and the result. If you want the cell replaced with + * the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} } * @param cell The cell to evaluate - * @return -1 for non-formula cells, or the type of the formula result - * @deprecated 3.15. Will return a {@link CellType} enum in the future. + * @return The type of the formula result (the cell's type remains as CellType.FORMULA however) + * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception. */ @Override - public int evaluateFormulaCell(Cell cell) { - return evaluateFormulaCellEnum(cell).getCode(); + public CellType evaluateFormulaCell(Cell cell) { + if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { + return CellType._NONE; + } + CellValue cv = evaluateFormulaCellValue(cell); + // cell remains a formula cell, but the cached value is changed + setCellValue(cell, cv); + return cv.getCellTypeEnum(); } /** @@ -182,16 +192,13 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook * @return The type of the formula result (the cell's type remains as CellType.FORMULA however) * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception. * @since POI 3.15 beta 3 + * @deprecated use evaluateFormulaCell(cell) instead */ + @Deprecated + @Removal(version = "4.2") @Override public CellType evaluateFormulaCellEnum(Cell cell) { - if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) { - return CellType._NONE; - } - CellValue cv = evaluateFormulaCellValue(cell); - // cell remains a formula cell, but the cached value is changed - setCellValue(cell, cv); - return cv.getCellTypeEnum(); + return evaluateFormulaCell(cell); } protected static void setCellType(Cell cell, CellValue cv) { diff --git a/src/java/org/apache/poi/ss/formula/EvaluationCell.java b/src/java/org/apache/poi/ss/formula/EvaluationCell.java index 1007cb0c44..3541501496 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationCell.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationCell.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.formula; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.Removal; /** * Abstracts a cell for the purpose of formula evaluation. This interface represents both formula @@ -61,17 +62,15 @@ public interface EvaluationCell { boolean isPartOfArrayFormulaGroup(); /** - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return cell type of cached formula result - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ - int getCachedFormulaResultType(); + CellType getCachedFormulaResultType(); /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") CellType getCachedFormulaResultTypeEnum(); } diff --git a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java index 3418e595b0..2d0c55fce8 100644 --- a/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java +++ b/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java @@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.util.Removal; /** @@ -167,24 +168,23 @@ final class ForkedEvaluationCell implements EvaluationCell { return _masterCell.isPartOfArrayFormulaGroup(); } /** - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return cell type of cached formula result - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override - public int getCachedFormulaResultType() { + public CellType getCachedFormulaResultType() { return _masterCell.getCachedFormulaResultType(); } + /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Override public CellType getCachedFormulaResultTypeEnum() { - return _masterCell.getCachedFormulaResultTypeEnum(); + return getCachedFormulaResultType(); } } diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index 7b1637eeb5..ab8b48cf77 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -198,10 +198,8 @@ public interface Cell { * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ - @Deprecated - int getCachedFormulaResultType(); + CellType getCachedFormulaResultType(); /** * Only valid for formula cells @@ -211,6 +209,8 @@ public interface Cell { * @since POI 3.15 beta 3 * Will be renamed to getCachedFormulaResultType() when we make the CellType enum transition in POI 4.0. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") CellType getCachedFormulaResultTypeEnum(); /** diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java index 81e72c91d5..4d8a440222 100644 --- a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java @@ -17,6 +17,8 @@ package org.apache.poi.ss.usermodel; +import org.apache.poi.util.Removal; + import java.util.Map; /** @@ -99,9 +101,8 @@ public interface FormulaEvaluator { * or one of {@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR} * Note: the cell's type remains as CellType.FORMULA however. - * @deprecated 3.15. Will return a {@link CellType} enum in the future */ - int evaluateFormulaCell(Cell cell); + CellType evaluateFormulaCell(Cell cell); /** * If cell contains formula, it evaluates the formula, @@ -123,7 +124,10 @@ public interface FormulaEvaluator { * or one of {@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR} * Note: the cell's type remains as CellType.FORMULA however. + * @deprecated use evaluateFormulaCell(cell) */ + @Deprecated + @Removal(version = "4.2") CellType evaluateFormulaCellEnum(Cell cell); /** diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java index 28e8b41479..075420478e 100644 --- a/src/java/org/apache/poi/ss/util/SheetUtil.java +++ b/src/java/org/apache/poi/ss/util/SheetUtil.java @@ -38,6 +38,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** @@ -90,19 +91,16 @@ public class SheetUtil { @Override public void evaluateAll() {} @Override - public int evaluateFormulaCell(Cell cell) { - //noinspection deprecation - return cell.getCachedFormulaResultType(); - } - /** + public CellType evaluateFormulaCell(Cell cell) { return cell.getCachedFormulaResultType(); } + /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Internal(since="POI 3.15 beta 3") @Override - public CellType evaluateFormulaCellEnum(Cell cell) { - return cell.getCachedFormulaResultTypeEnum(); - } + public CellType evaluateFormulaCellEnum(Cell cell) { return evaluateFormulaCell(cell); } }; /** diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java index 0d651ad9c5..2c32a145aa 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java @@ -38,10 +38,7 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; -import org.apache.poi.util.LocaleUtil; -import org.apache.poi.util.NotImplemented; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; +import org.apache.poi.util.*; import org.apache.poi.xssf.usermodel.XSSFHyperlink; import org.apache.poi.xssf.usermodel.XSSFRichTextString; @@ -175,12 +172,14 @@ public class SXSSFCell implements Cell { * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override - public int getCachedFormulaResultType() - { - return getCachedFormulaResultTypeEnum().getCode(); + public CellType getCachedFormulaResultType() { + if (_value.getType() != CellType.FORMULA) { + throw new IllegalStateException("Only formula cells have cached results"); + } + + return ((FormulaValue)_value).getFormulaType(); } /** @@ -189,16 +188,13 @@ public class SXSSFCell implements Cell { * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula * @since POI 3.15 beta 3 - * Will be deleted when we make the CellType enum transition. See bug 59791. + * @deprecated use getCachedFormulaResultTypeEnum instead */ + @Deprecated + @Removal(version = "4.2") @Override - public CellType getCachedFormulaResultTypeEnum() - { - if (_value.getType() != CellType.FORMULA) { - throw new IllegalStateException("Only formula cells have cached results"); - } - - return ((FormulaValue)_value).getFormulaType(); + public CellType getCachedFormulaResultTypeEnum() { + return getCachedFormulaResultType(); } /** 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 6fb455554e..21cfb3fe0d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java @@ -22,6 +22,7 @@ import org.apache.poi.ss.formula.EvaluationSheet; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * SXSSF wrapper for a cell under evaluation @@ -110,24 +111,22 @@ final class SXSSFEvaluationCell implements EvaluationCell { } /** - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return cell type of cached formula result - * @deprecated 3.17. Will return a {@link CellType} enum in the future. */ @Override - public int getCachedFormulaResultType() { - return _cell.getCachedFormulaResultType(); + public CellType getCachedFormulaResultType() { + return _cell.getCachedFormulaResultTypeEnum(); } /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { - return _cell.getCachedFormulaResultTypeEnum(); + return getCachedFormulaResultType(); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 067936069a..ffa05313d1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -714,20 +714,17 @@ public final class XSSFCell implements Cell { /** * Only valid for formula cells - * - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING}, * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula - * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ - @Deprecated @Override - @Removal(version="3.17") - public int getCachedFormulaResultType() { - return getCachedFormulaResultTypeEnum().getCode(); + public CellType getCachedFormulaResultType() { + if (! isFormulaCell()) { + throw new IllegalStateException("Only formula cells have cached results"); + } + + return getBaseCellType(false); } /** @@ -736,15 +733,14 @@ public final class XSSFCell implements Cell { * {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending * on the cached value of the formula * @since POI 3.15 beta 3 + * @deprecated use getCachedFormulaResultType instead * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Override public CellType getCachedFormulaResultTypeEnum() { - if (! isFormulaCell()) { - throw new IllegalStateException("Only formula cells have cached results"); - } - - return getBaseCellType(false); + return getCachedFormulaResultType(); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java index 3d75713c8d..c41593d637 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java @@ -22,6 +22,7 @@ import org.apache.poi.ss.formula.EvaluationSheet; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * XSSF wrapper for a cell under evaluation @@ -110,24 +111,22 @@ final class XSSFEvaluationCell implements EvaluationCell { } /** - * Will return {@link CellType} in a future version of POI. - * For forwards compatibility, do not hard-code cell type literals in your code. - * * @return cell type of cached formula result - * @deprecated 3.17. Will return a {@link CellType} enum in the future. */ @Override - public int getCachedFormulaResultType() { - return _cell.getCachedFormulaResultType(); + public CellType getCachedFormulaResultType() { + return _cell.getCachedFormulaResultTypeEnum(); } /** * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ + @Deprecated + @Removal(version = "4.2") @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { - return _cell.getCachedFormulaResultTypeEnum(); + return getCachedFormulaResultType(); } } -- 2.39.5