Browse Source

Change getCachedFormulaResultType to return CellType

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808678 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_4_0_0_FINAL
PJ Fanning 6 years ago
parent
commit
f3643e95f9

+ 15
- 12
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java View File

@@ -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 <code>CellType</code> 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 <code>getCachedFormulaResultType</code>
* 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) {

+ 7
- 8
src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java View File

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

+ 27
- 20
src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java View File

@@ -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.<p>
@@ -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 <em>formula result</em> 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.
* <pre>
* int evaluatedCellType = evaluator.evaluateFormulaCell(cell);
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
* </pre>
* 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 <em>formula result</em>
* @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 <code>evaluateFormulaCell(cell)</code> 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) {

+ 4
- 5
src/java/org/apache/poi/ss/formula/EvaluationCell.java View File

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

+ 6
- 6
src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationCell.java View File

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

}

+ 3
- 3
src/java/org/apache/poi/ss/usermodel/Cell.java View File

@@ -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 <code>getCachedFormulaResultType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Deprecated
@Removal(version = "4.2")
CellType getCachedFormulaResultTypeEnum();

/**

+ 6
- 2
src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java View File

@@ -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 <code>evaluateFormulaCell(cell)</code>
*/
@Deprecated
@Removal(version = "4.2")
CellType evaluateFormulaCellEnum(Cell cell);

/**

+ 6
- 8
src/java/org/apache/poi/ss/util/SheetUtil.java View File

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

/**

+ 12
- 16
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java View File

@@ -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 <code>getCachedFormulaResultTypeEnum</code> 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();
}

/**

+ 6
- 7
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationCell.java View File

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

+ 10
- 14
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java View File

@@ -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 <code>getCachedFormulaResultType</code> 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();
}

/**

+ 6
- 7
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java View File

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

Loading…
Cancel
Save