diff options
Diffstat (limited to 'src/java')
33 files changed, 570 insertions, 251 deletions
diff --git a/src/java/org/apache/poi/common/usermodel/Hyperlink.java b/src/java/org/apache/poi/common/usermodel/Hyperlink.java index 132a3eb4c3..abcdd112a6 100644 --- a/src/java/org/apache/poi/common/usermodel/Hyperlink.java +++ b/src/java/org/apache/poi/common/usermodel/Hyperlink.java @@ -16,6 +16,8 @@ ==================================================================== */ package org.apache.poi.common.usermodel; +import org.apache.poi.util.Removal; + /** * Represents a hyperlink. */ @@ -25,6 +27,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#URL} instead. */ + @Removal(version="3.17") public static final int LINK_URL = 1; // HyperlinkType.URL.getCode() /** @@ -32,6 +35,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#DOCUMENT} instead. */ + @Removal(version="3.17") public static final int LINK_DOCUMENT = 2; // HyperlinkType.DOCUMENT.getCode() /** @@ -39,6 +43,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#EMAIL} instead. */ + @Removal(version="3.17") public static final int LINK_EMAIL = 3; // HyperlinkType.EMAIL.getCode() /** @@ -46,6 +51,7 @@ public interface Hyperlink { * * @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#FILE} instead. */ + @Removal(version="3.17") public static final int LINK_FILE = 4; // HyperlinkType.FILE.getCode() @@ -83,6 +89,7 @@ public interface Hyperlink { * @return the type of this hyperlink * @see HyperlinkType#forInt(int) * @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()} + * getType will return a HyperlinkType enum in the future. */ public int getType(); diff --git a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java index b54b27ad49..774eb788f3 100644 --- a/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java +++ b/src/java/org/apache/poi/hssf/model/HSSFFormulaParser.java @@ -17,8 +17,6 @@ package org.apache.poi.hssf.model; -import org.apache.poi.ss.formula.ptg.Ptg; -import org.apache.poi.util.Internal; import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.FormulaParseException; @@ -26,6 +24,9 @@ import org.apache.poi.ss.formula.FormulaParser; import org.apache.poi.ss.formula.FormulaParsingWorkbook; import org.apache.poi.ss.formula.FormulaRenderer; import org.apache.poi.ss.formula.FormulaType; +import org.apache.poi.ss.formula.ptg.Ptg; +import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer} @@ -61,6 +62,7 @@ public final class HSSFFormulaParser { * * @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType)} instead. */ + @Removal(version="3.17") public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) throws FormulaParseException { return parse(formula, workbook, FormulaType.forInt(formulaType)); } @@ -87,6 +89,7 @@ public final class HSSFFormulaParser { * @throws FormulaParseException if the formula has incorrect syntax or is otherwise invalid * @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType, int)} instead. */ + @Removal(version="3.17") public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) throws FormulaParseException { return parse(formula, workbook, FormulaType.forInt(formulaType), sheetIndex); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java index d06c9f179b..c4113b6159 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java @@ -42,28 +42,83 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B return borderFormatting; } + /** + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderBottom() { + public short getBorderBottom() { + return (short)borderFormatting.getBorderBottom(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderBottomEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderBottom()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderDiagonal() { + public short getBorderDiagonal() { + return (short)borderFormatting.getBorderDiagonal(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderDiagonalEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}. + * This method will return an BorderStyle enum in the future. + */ + @Override + public short getBorderLeft() { + return (short)borderFormatting.getBorderLeft(); + } + /** + * @since POI 3.15 + */ @Override - public BorderStyle getBorderLeft() { + public BorderStyle getBorderLeftEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderLeft()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}. + * This method will return an BorderStyle enum in the future. + */ + @Override + public short getBorderRight() { + return (short)borderFormatting.getBorderRight(); + } + /** + * @since POI 3.15 + */ @Override - public BorderStyle getBorderRight() { + public BorderStyle getBorderRightEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderRight()); } + /** + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}. + * This method will return an BorderStyle enum in the future. + */ + @Override + public short getBorderTop() { + return (short)borderFormatting.getBorderTop(); + } + /** + * @since POI 3.15 + */ @Override - public BorderStyle getBorderTop() { + public BorderStyle getBorderTopEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderTop()); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 44427fce73..cfe998e059 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -446,6 +446,7 @@ public class HSSFCell implements Cell { * * Will return {@link CellType} in a future version of POI. * For forwards compatibility, do not hard-code cell type literals in your code. + * @deprecated 3.15. Will be return a {@link CellType} enum in the future. */ @Override public int getCellType() @@ -459,7 +460,6 @@ public class HSSFCell implements Cell { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { @@ -1154,6 +1154,7 @@ public class HSSFCell 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() { @@ -1169,7 +1170,6 @@ public class HSSFCell implements Cell { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { if (_cellType != CellType.FORMULA) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 6e6c05504b..0fd7cf2ade 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -32,6 +32,7 @@ import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; +import org.apache.poi.util.Removal; /** * High level representation of the style of a cell in a sheet of a workbook. @@ -254,6 +255,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #ALIGN_CENTER_SELECTION * @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setAlignment(short align) { @@ -329,6 +331,7 @@ public final class HSSFCellStyle implements CellStyle { * @see VerticalAlignment * @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead. */ + @Removal(version="3.17") @Override public void setVerticalAlignment(short align) { @@ -459,6 +462,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderLeft(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderLeft(short border) { @@ -469,6 +473,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the left border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderLeft(BorderStyle border) @@ -479,9 +484,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the left border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderLeftEnum()}. */ @Override - public BorderStyle getBorderLeft() + public short getBorderLeft() + { + return _format.getBorderLeft(); + } + /** + * get the type of border to use for the left border of the cell + * @return border type + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderLeftEnum() { return BorderStyle.valueOf(_format.getBorderLeft()); } @@ -505,6 +521,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderRight(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderRight(short border) { @@ -515,6 +532,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the right border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderRight(BorderStyle border) @@ -525,9 +543,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the right border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderRightEnum()}. + */ + @Override + public short getBorderRight() + { + return _format.getBorderRight(); + } + /** + * get the type of border to use for the right border of the cell + * @return border type + * @since POI 3.15 */ @Override - public BorderStyle getBorderRight() + public BorderStyle getBorderRightEnum() { return BorderStyle.valueOf(_format.getBorderRight()); } @@ -551,6 +580,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderTop(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderTop(short border) { @@ -561,6 +591,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the top border of the cell * @param border type + * @since POI 3.15 */ @Override public void setBorderTop(BorderStyle border) @@ -571,9 +602,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the top border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderTopEnum()}. */ @Override - public BorderStyle getBorderTop() + public short getBorderTop() + { + return _format.getBorderTop(); + } + /** + * get the type of border to use for the top border of the cell + * @return border type + * @since 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { return BorderStyle.valueOf(_format.getBorderTop()); } @@ -597,6 +639,7 @@ public final class HSSFCellStyle implements CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderBottom(BorderStyle)} instead. */ + @Removal(version="3.17") @Override public void setBorderBottom(short border) { @@ -607,6 +650,7 @@ public final class HSSFCellStyle implements CellStyle { /** * set the type of border to use for the bottom border of the cell * @param border type + * @since 3.15 beta 2 */ @Override public void setBorderBottom(BorderStyle border) @@ -617,9 +661,20 @@ public final class HSSFCellStyle implements CellStyle { /** * get the type of border to use for the bottom border of the cell * @return border type + * @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderBottomEnum()}. + */ + @Override + public short getBorderBottom() + { + return _format.getBorderBottom(); + } + /** + * get the type of border to use for the bottom border of the cell + * @return border type + * @since 3.15 */ @Override - public BorderStyle getBorderBottom() + public BorderStyle getBorderBottomEnum() { return BorderStyle.valueOf(_format.getBorderBottom()); } @@ -733,6 +788,7 @@ public final class HSSFCellStyle implements CellStyle { * @param fp fill pattern (set to 1 to fill w/foreground color) * @deprecated POI 3.15 beta 3. Use {@link #setFillPattern(FillPatternType)} instead. */ + @Removal(version="3.17") @Override public void setFillPattern(short fp) { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java index 4b8a25e302..d4c8c6d689 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java @@ -21,6 +21,7 @@ import org.apache.poi.ddf.EscherClientAnchorRecord; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.ClientAnchor; +import org.apache.poi.util.Removal; /** * A client anchor is attached to an excel worksheet. It anchors against a @@ -250,6 +251,7 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { /** * Gets the anchor type + * Changed from returning an int to an enum in POI 3.14 beta 1. * @return the anchor type */ @Override @@ -260,11 +262,22 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor { /** * Sets the anchor type * @param anchorType the anchor type to set + * @since POI 3.14 */ @Override public void setAnchorType(AnchorType anchorType) { _escherClientAnchor.setFlag(anchorType.value); } + /** + * Sets the anchor type + * @param anchorType the anchor type to set + * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. + */ + @Removal(version="3.17") + @Override + public void setAnchorType(int anchorType) { + _escherClientAnchor.setFlag((short) anchorType); + } private void checkRange(int value, int minRange, int maxRange, String varName) { if (value < minRange || value > maxRange) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java index 7ce7ef1be8..863d1a004a 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCreationHelper.java @@ -21,6 +21,7 @@ import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.record.common.ExtendedColor; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; public class HSSFCreationHelper implements CreationHelper { private final HSSFWorkbook workbook; @@ -50,6 +51,7 @@ public class HSSFCreationHelper implements CreationHelper { * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ @Deprecated + @Removal(version="3.17") @Override public HSSFHyperlink createHyperlink(int type) { return new HSSFHyperlink(type); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java index b524cc149a..1771b2e35f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationCell.java @@ -55,6 +55,7 @@ final class HSSFEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -65,7 +66,6 @@ final class HSSFEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { return _cell.getCellTypeEnum(); @@ -99,6 +99,7 @@ final class HSSFEvaluationCell implements EvaluationCell { * 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() { @@ -109,7 +110,6 @@ final class HSSFEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { return _cell.getCachedFormulaResultTypeEnum(); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 8d7d781f9a..20c7ffa1e4 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -30,11 +30,10 @@ import org.apache.poi.ss.formula.eval.StringValueEval; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; +import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.util.Internal; /** * Evaluates formula cells.<p/> @@ -81,6 +80,11 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { public static HSSFFormulaEvaluator create(HSSFWorkbook workbook, IStabilityClassifier stabilityClassifier, UDFFinder udfFinder) { return new HSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder); } + + @Override + protected RichTextString createRichTextString(String str) { + return new HSSFRichTextString(str); + } /** @@ -136,87 +140,10 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator { public void notifySetFormula(Cell cell) { _bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)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, rather than throwing an - * exception, this method returns {@link CellType#_NONE} 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. - * <pre> - * CellType evaluatedCellType = evaluator.evaluateFormulaCell(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)} - * @param cell The cell to evaluate - * @return {@link CellType#_NONE} for non-formula cells, or the type of the <em>formula result</em> - * @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. - */ - @Internal - @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.getCellType(); - } - - /** - * If cell contains formula, it evaluates the formula, and - * puts the formula result back into the cell, in place - * of the old formula. - * Else if cell does not contain formula, this method leaves - * the cell unchanged. - * Note that the same instance of HSSFCell is returned to - * allow chained calls like: - * <pre> - * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); - * </pre> - * Be aware that your cell value will be changed to hold the - * result of the formula. If you simply want the formula - * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}} - */ + @Override public HSSFCell evaluateInCell(Cell cell) { - if (cell == null) { - return null; - } - HSSFCell result = (HSSFCell) cell; - if (cell.getCellTypeEnum() == CellType.FORMULA) { - CellValue cv = evaluateFormulaCellValue(cell); - setCellValue(cell, cv); - setCellType(cell, cv); // cell will no longer be a formula cell - } - return result; - } - - private static void setCellValue(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); - switch (cellType) { - case BOOLEAN: - cell.setCellValue(cv.getBooleanValue()); - break; - case ERROR: - cell.setCellErrorValue(cv.getErrorValue()); - break; - case NUMERIC: - cell.setCellValue(cv.getNumberValue()); - break; - case STRING: - cell.setCellValue(new HSSFRichTextString(cv.getStringValue())); - break; - case BLANK: - // never happens - blanks eventually get translated to zero - case FORMULA: - // this will never happen, we have already evaluated the formula - default: - throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); - } + return (HSSFCell) super.evaluateInCell(cell); } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java index 1847bfc0fb..084a6bfe04 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java @@ -273,6 +273,8 @@ public class HSSFHyperlink implements Hyperlink { * * @return the type of this hyperlink * @see HyperlinkType#forInt + * @deprecated POI 3.15. Use {@link #getTypeEnum()} instead. + * getType will return a HyperlinkType enum in the future. */ @Override public int getType() { diff --git a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java index 1b86606448..47637daa3a 100644 --- a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java +++ b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java @@ -94,6 +94,8 @@ public class FileBackedDataSource extends DataSource { if (writable) { dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length); worked = 0; + // remember the buffer for cleanup if necessary + buffersToClean.add(dst); } else { // Read channel.position(position); @@ -109,9 +111,6 @@ public class FileBackedDataSource extends DataSource { // Ready it for reading dst.position(0); - // remember the buffer for cleanup if necessary - buffersToClean.add(dst); - // All done return dst; } diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShow.java b/src/java/org/apache/poi/sl/usermodel/SlideShow.java index e46ce243f8..228925d1c4 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShow.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShow.java @@ -83,6 +83,7 @@ public interface SlideShow< * @param format The format of the picture. * * @return the picture data reference. + * @since 3.15 beta 1 */ PictureData addPicture(InputStream is, PictureType format) throws IOException; @@ -93,6 +94,7 @@ public interface SlideShow< * @param format The format of the picture. * * @return the picture data reference + * @since 3.15 beta 1 */ PictureData addPicture(File pict, PictureType format) throws IOException; @@ -101,6 +103,7 @@ public interface SlideShow< * * @param pictureData The picture data to find in the SlideShow * @return {@code null} if picture data is not found in this slideshow + * @since 3.15 beta 3 */ PictureData findPictureData(byte[] pictureData); diff --git a/src/java/org/apache/poi/ss/format/CellFormat.java b/src/java/org/apache/poi/ss/format/CellFormat.java index e47d40c4f1..bad8497126 100644 --- a/src/java/org/apache/poi/ss/format/CellFormat.java +++ b/src/java/org/apache/poi/ss/format/CellFormat.java @@ -35,7 +35,6 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingRule; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.util.DateFormatConverter; -import org.apache.poi.util.Internal; /** * Format a value according to the standard Excel behavior. This "standard" is @@ -44,28 +43,35 @@ import org.apache.poi.util.Internal; * <p/> * An Excel format has up to four parts, separated by semicolons. Each part * specifies what to do with particular kinds of values, depending on the number - * of parts given: <dl> <dt>One part (example: <tt>[Green]#.##</tt>) <dd>If the - * value is a number, display according to this one part (example: green text, - * with up to two decimal points). If the value is text, display it as is. - * <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>) <dd>If the value is a - * positive number or zero, display according to the first part (example: green + * of parts given: + * <dl> + * <dt>One part (example: <tt>[Green]#.##</tt>)</dt> + * <dd>If the value is a number, display according to this one part (example: green text, + * with up to two decimal points). If the value is text, display it as is.</dd> + * + * <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>)</dt> + * <dd>If the value is a positive number or zero, display according to the first part (example: green * text, with up to two decimal points); if it is a negative number, display * according to the second part (example: red text, with up to two decimal - * points). If the value is text, display it as is. <dt>Three parts (example: - * <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>) <dd>If the value is a positive + * points). If the value is text, display it as is.</dd> + * + * <dt>Three parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>)</dt> + * <dd>If the value is a positive * number, display according to the first part (example: green text, with up to * two decimal points); if it is zero, display according to the second part * (example: black text, with up to two decimal points); if it is a negative * number, display according to the third part (example: red text, with up to - * two decimal points). If the value is text, display it as is. <dt>Four parts - * (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>) <dd>If the value is - * a positive number, display according to the first part (example: green text, + * two decimal points). If the value is text, display it as is.</dd> + * + * <dt>Four parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>)</dt> + * <dd>If the value is a positive number, display according to the first part (example: green text, * with up to two decimal points); if it is zero, display according to the * second part (example: black text, with up to two decimal points); if it is a * negative number, display according to the third part (example: red text, with * up to two decimal points). If the value is text, display according to the * fourth part (example: text in the cell's usual color, with the text value - * surround by brackets). </dl> + * surround by brackets).</dd> + * </dl> * <p/> * A given format part may specify a given Locale, by including something * like <tt>[$$-409]</tt> or <tt>[$£-809]</tt> or <tt>[$-40C]</tt>. These @@ -421,6 +427,7 @@ public class CellFormat { * @param cell The cell. * * @return The ultimate type of this cell. + * @deprecated POI 3.15. This will return a CellType enum in the future */ public static int ultimateType(Cell cell) { return ultimateTypeEnum(cell).getCode(); @@ -439,7 +446,6 @@ public class CellFormat { * @deprecated POI 3.15 beta 3 * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") public static CellType ultimateTypeEnum(Cell cell) { CellType type = cell.getCellTypeEnum(); if (type == CellType.FORMULA) diff --git a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java index 8746ba7fa0..6cd19f5bf1 100644 --- a/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/BaseFormulaEvaluator.java @@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.ss.usermodel.FormulaEvaluator; +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; @@ -108,6 +109,37 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook throw new IllegalStateException("Bad cell type (" + cell.getCellTypeEnum() + ")"); } } + + /** + * If cell contains formula, it evaluates the formula, and + * puts the formula result back into the cell, in place + * of the old formula. + * Else if cell does not contain formula, this method leaves + * the cell unchanged. + * Note that the same instance of HSSFCell is returned to + * allow chained calls like: + * <pre> + * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType(); + * </pre> + * Be aware that your cell value will be changed to hold the + * result of the formula. If you simply want the formula + * value computed for you, use {@link #evaluateFormulaCellEnum(Cell)}} + * @param cell + * @return the {@code cell} that was passed in, allowing for chained calls + */ + @Override + public Cell evaluateInCell(Cell cell) { + if (cell == null) { + return null; + } + Cell result = cell; + if (cell.getCellTypeEnum() == CellType.FORMULA) { + CellValue cv = evaluateFormulaCellValue(cell); + setCellValue(cell, cv); + setCellType(cell, cv); // cell will no longer be a formula cell + } + return result; + } protected abstract CellValue evaluateFormulaCellValue(Cell cell); @@ -125,14 +157,47 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook * replaced with the result of the formula, use {@link #evaluateInCell(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. */ @Override public int evaluateFormulaCell(Cell cell) { return evaluateFormulaCellEnum(cell).getCode(); } + + /** + * 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> + * 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 #evaluate(org.apache.poi.ss.usermodel.Cell)} } + * @param cell The cell to evaluate + * @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 POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791. + */ + @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(); + } protected static void setCellType(Cell cell, CellValue cv) { - CellType cellType = cv.getCellType(); + CellType cellType = cv.getCellTypeEnum(); switch (cellType) { case BOOLEAN: case ERROR: @@ -150,6 +215,33 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); } } + + protected abstract RichTextString createRichTextString(String str); + + protected void setCellValue(Cell cell, CellValue cv) { + CellType cellType = cv.getCellTypeEnum(); + switch (cellType) { + case BOOLEAN: + cell.setCellValue(cv.getBooleanValue()); + break; + case ERROR: + cell.setCellErrorValue(cv.getErrorValue()); + break; + case NUMERIC: + cell.setCellValue(cv.getNumberValue()); + break; + case STRING: + cell.setCellValue(createRichTextString(cv.getStringValue())); + break; + case BLANK: + // never happens - blanks eventually get translated to zero + case FORMULA: + // this will never happen, we have already evaluated the formula + default: + throw new IllegalStateException("Unexpected cell value type (" + cellType + ")"); + } + } + /** * Loops over all cells in all sheets of the supplied diff --git a/src/java/org/apache/poi/ss/formula/EvaluationCell.java b/src/java/org/apache/poi/ss/formula/EvaluationCell.java index 3695fe2802..a7e855c443 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationCell.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationCell.java @@ -42,6 +42,7 @@ public interface EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ int getCellType(); /** @@ -61,6 +62,7 @@ public interface EvaluationCell { * 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(); /** diff --git a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java index a45d5a2d14..8e438c9669 100644 --- a/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java +++ b/src/java/org/apache/poi/ss/formula/OperandClassTransformer.java @@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RangePtg; import org.apache.poi.ss.formula.ptg.UnionPtg; import org.apache.poi.ss.formula.ptg.ValueOperatorPtg; +import org.apache.poi.util.Removal; /** * This class performs 'operand class' transformation. Non-base tokens are classified into three @@ -59,7 +60,10 @@ final class OperandClassTransformer { private final FormulaType _formulaType; - /** @deprecated POI 3.15 beta 3. */ + /** + * @deprecated POI 3.15 beta 3. Use {@code OperandClassTransformer(FormulaType)} instead. + */ + @Removal(version="3.17") public OperandClassTransformer(int formulaType) { this(FormulaType.forInt(formulaType)); } 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 0521e0889e..db01b06403 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 @@ -108,6 +108,7 @@ final class ForkedEvaluationCell implements EvaluationCell { * For forwards compatibility, do not hard-code cell type literals in your code. * * @return cell type + * @deprecated 3.15. Will return a {@link CellType} enum in the future. */ @Override public int getCellType() { @@ -118,7 +119,6 @@ final class ForkedEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCellTypeEnum() { return _cellType; @@ -160,6 +160,7 @@ final class ForkedEvaluationCell implements EvaluationCell { * 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() { @@ -170,7 +171,6 @@ final class ForkedEvaluationCell implements EvaluationCell { * @deprecated POI 3.15 beta 3. * Will be deleted when we make the CellType enum transition. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") @Override public CellType getCachedFormulaResultTypeEnum() { return _masterCell.getCachedFormulaResultTypeEnum(); diff --git a/src/java/org/apache/poi/ss/formula/functions/DGet.java b/src/java/org/apache/poi/ss/formula/functions/DGet.java index 91a9934b50..0bf9cc2623 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DGet.java +++ b/src/java/org/apache/poi/ss/formula/functions/DGet.java @@ -17,7 +17,10 @@ package org.apache.poi.ss.formula.functions; +import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.eval.EvaluationException; +import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.ValueEval; /** @@ -46,8 +49,18 @@ public final class DGet implements IDStarAlgorithm { public ValueEval getResult() { if(result == null) { return ErrorEval.VALUE_INVALID; - } else { - return result; - } + } else if(result instanceof BlankEval) { + return ErrorEval.VALUE_INVALID; + } else + try { + if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) { + return ErrorEval.VALUE_INVALID; + } + else { + return result; + } + } catch (EvaluationException e) { + return e.getErrorEval(); + } } } diff --git a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java index 6a87a67a64..8418c4f740 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java +++ b/src/java/org/apache/poi/ss/formula/functions/DStarRunner.java @@ -17,13 +17,13 @@ package org.apache.poi.ss.formula.functions; -import org.apache.poi.ss.formula.TwoDEval; +import org.apache.poi.ss.formula.eval.AreaEval; import org.apache.poi.ss.formula.eval.BlankEval; import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NumericValueEval; -import org.apache.poi.ss.formula.eval.RefEval; +import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.StringEval; import org.apache.poi.ss.formula.eval.StringValueEval; import org.apache.poi.ss.formula.eval.ValueEval; @@ -62,11 +62,17 @@ public final class DStarRunner implements Function3Arg { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval database, ValueEval filterColumn, ValueEval conditionDatabase) { // Input processing and error checks. - if(!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) { + if(!(database instanceof AreaEval) || !(conditionDatabase instanceof AreaEval)) { return ErrorEval.VALUE_INVALID; } - TwoDEval db = (TwoDEval)database; - TwoDEval cdb = (TwoDEval)conditionDatabase; + AreaEval db = (AreaEval)database; + AreaEval cdb = (AreaEval)conditionDatabase; + + try { + filterColumn = OperandResolver.getSingleValue(filterColumn, srcRowIndex, srcColumnIndex); + } catch (EvaluationException e) { + return e.getErrorEval(); + } int fc; try { @@ -100,15 +106,11 @@ public final class DStarRunner implements Function3Arg { } // Filter each entry. if(matches) { - try { - ValueEval currentValueEval = solveReference(db.getValue(row, fc)); - // Pass the match to the algorithm and conditionally abort the search. - boolean shouldContinue = algorithm.processMatch(currentValueEval); - if(! shouldContinue) { - break; - } - } catch (EvaluationException e) { - return e.getErrorEval(); + ValueEval currentValueEval = resolveReference(db, row, fc); + // Pass the match to the algorithm and conditionally abort the search. + boolean shouldContinue = algorithm.processMatch(currentValueEval); + if(! shouldContinue) { + break; } } } @@ -126,56 +128,16 @@ public final class DStarRunner implements Function3Arg { } /** - * Resolve reference(-chains) until we have a normal value. + * * - * @param field a ValueEval which can be a RefEval. - * @return a ValueEval which is guaranteed not to be a RefEval - * @throws EvaluationException If a multi-sheet reference was found along the way. - */ - private static ValueEval solveReference(ValueEval field) throws EvaluationException { - if (field instanceof RefEval) { - RefEval refEval = (RefEval)field; - if (refEval.getNumberOfSheets() > 1) { - throw new EvaluationException(ErrorEval.VALUE_INVALID); - } - return solveReference(refEval.getInnerValueEval(refEval.getFirstSheetIndex())); - } - else { - return field; - } - } - - /** - * Returns the first column index that matches the given name. The name can either be - * a string or an integer, when it's an integer, then the respective column - * (1 based index) is returned. - * @param nameValueEval - * @param db - * @return the first column index that matches the given name (or int) + * @param nameValueEval Must not be a RefEval or AreaEval. Thus make sure resolveReference() is called on the value first! + * @param db Database + * @return Corresponding column number. * @throws EvaluationException */ - @SuppressWarnings("unused") - private static int getColumnForTag(ValueEval nameValueEval, TwoDEval db) + private static int getColumnForName(ValueEval nameValueEval, AreaEval db) throws EvaluationException { - int resultColumn = -1; - - // Numbers as column indicator are allowed, check that. - if(nameValueEval instanceof NumericValueEval) { - double doubleResultColumn = ((NumericValueEval)nameValueEval).getNumberValue(); - resultColumn = (int)doubleResultColumn; - // Floating comparisions are usually not possible, but should work for 0.0. - if(doubleResultColumn - resultColumn != 0.0) - throw new EvaluationException(ErrorEval.VALUE_INVALID); - resultColumn -= 1; // Numbers are 1-based not 0-based. - } else { - resultColumn = getColumnForName(nameValueEval, db); - } - return resultColumn; - } - - private static int getColumnForName(ValueEval nameValueEval, TwoDEval db) - throws EvaluationException { - String name = getStringFromValueEval(nameValueEval); + String name = OperandResolver.coerceValueToString(nameValueEval); return getColumnForString(db, name); } @@ -187,16 +149,19 @@ public final class DStarRunner implements Function3Arg { * @return Corresponding column number. * @throws EvaluationException If it's not possible to turn all headings into strings. */ - private static int getColumnForString(TwoDEval db,String name) + private static int getColumnForString(AreaEval db,String name) throws EvaluationException { int resultColumn = -1; final int width = db.getWidth(); for(int column = 0; column < width; ++column) { - ValueEval columnNameValueEval = db.getValue(0, column); - if(solveReference(columnNameValueEval) instanceof BlankEval) { + ValueEval columnNameValueEval = resolveReference(db, 0, column); + if(columnNameValueEval instanceof BlankEval) { continue; } - String columnName = getStringFromValueEval(columnNameValueEval); + if(columnNameValueEval instanceof ErrorEval) { + continue; + } + String columnName = OperandResolver.coerceValueToString(columnNameValueEval); if(name.equals(columnName)) { resultColumn = column; break; @@ -215,7 +180,7 @@ public final class DStarRunner implements Function3Arg { * @throws EvaluationException If references could not be resolved or comparison * operators and operands didn't match. */ - private static boolean fullfillsConditions(TwoDEval db, int row, TwoDEval cdb) + private static boolean fullfillsConditions(AreaEval db, int row, AreaEval cdb) throws EvaluationException { // Only one row must match to accept the input, so rows are ORed. // Each row is made up of cells where each cell is a condition, @@ -229,20 +194,15 @@ public final class DStarRunner implements Function3Arg { // special column that accepts formulas. boolean columnCondition = true; ValueEval condition = null; - try { - // The condition to apply. - condition = solveReference(cdb.getValue(conditionRow, column)); - } catch (java.lang.RuntimeException e) { - // It might be a special formula, then it is ok if it fails. - columnCondition = false; - } + + // The condition to apply. + condition = resolveReference(cdb, conditionRow, column); + // If the condition is empty it matches. if(condition instanceof BlankEval) continue; // The column in the DB to apply the condition to. - ValueEval targetHeader = solveReference(cdb.getValue(0, column)); - targetHeader = solveReference(targetHeader); - + ValueEval targetHeader = resolveReference(cdb, 0, column); if(!(targetHeader instanceof StringValueEval)) { throw new EvaluationException(ErrorEval.VALUE_INVALID); @@ -254,14 +214,14 @@ public final class DStarRunner implements Function3Arg { if(columnCondition == true) { // normal column condition // Should not throw, checked above. - ValueEval value = db.getValue( - row, getColumnForName(targetHeader, db)); + ValueEval value = resolveReference(db, row, getColumnForName(targetHeader, db)); if(!testNormalCondition(value, condition)) { matches = false; break; } } else { // It's a special formula condition. - if(getStringFromValueEval(condition).isEmpty()) { + // TODO: Check whether the condition cell contains a formula and return #VALUE! if it doesn't. + if(OperandResolver.coerceValueToString(condition).isEmpty()) { throw new EvaluationException(ErrorEval.VALUE_INVALID); } throw new NotImplementedException( @@ -328,7 +288,7 @@ public final class DStarRunner implements Function3Arg { if(itsANumber) { return testNumericCondition(value, operator.equal, stringOrNumber); } else { // It's a string. - String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value); + String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value); return stringOrNumber.equals(valueString); } } else { // It's a text starts-with condition. @@ -336,7 +296,7 @@ public final class DStarRunner implements Function3Arg { return value instanceof StringEval; } else { - String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value); + String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value); return valueString.startsWith(conditionString); } } @@ -424,20 +384,20 @@ public final class DStarRunner implements Function3Arg { return null; } } - + /** - * Takes a ValueEval and tries to retrieve a String value from it. - * It tries to resolve references if there are any. + * Resolve a ValueEval that's in an AreaEval. * - * @param value ValueEval to retrieve the string from. - * @return String corresponding to the given ValueEval. - * @throws EvaluationException If it's not possible to retrieve a String value. + * @param db AreaEval from which the cell to resolve is retrieved. + * @param dbRow Relative row in the AreaEval. + * @param dbCol Relative column in the AreaEval. + * @return A ValueEval that is a NumberEval, StringEval, BoolEval, BlankEval or ErrorEval. */ - private static String getStringFromValueEval(ValueEval value) - throws EvaluationException { - value = solveReference(value); - if(!(value instanceof StringValueEval)) - throw new EvaluationException(ErrorEval.VALUE_INVALID); - return ((StringValueEval)value).getStringValue(); + private static ValueEval resolveReference(AreaEval db, int dbRow, int dbCol) { + try { + return OperandResolver.getSingleValue(db.getValue(dbRow, dbCol), db.getFirstRow()+dbRow, db.getFirstColumn()+dbCol); + } catch (EvaluationException e) { + return e.getErrorEval(); + } } } diff --git a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java index 059cdd065c..949cc3d00e 100644 --- a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java +++ b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
+import org.apache.poi.util.Removal;
+
/**
* High level representation for Border Formatting component
* of Conditional Formatting settings
@@ -27,84 +29,128 @@ public interface BorderFormatting { /** No border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE}
*/
+ @Removal(version="3.17")
short BORDER_NONE = 0x0;
/** Thin border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN}
*/
+ @Removal(version="3.17")
short BORDER_THIN = 0x1;
/** Medium border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM}
*/
+ @Removal(version="3.17")
short BORDER_MEDIUM = 0x2;
/** dash border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED}
*/
+ @Removal(version="3.17")
short BORDER_DASHED = 0x3;
/** dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED}
*/
+ @Removal(version="3.17")
short BORDER_DOTTED = 0x4;
/** Thick border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK}
*/
+ @Removal(version="3.17")
short BORDER_THICK = 0x5;
/** double-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE}
*/
+ @Removal(version="3.17")
short BORDER_DOUBLE = 0x6;
/** hair-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR}
*/
+ @Removal(version="3.17")
short BORDER_HAIR = 0x7;
/** Medium dashed border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED}
*/
+ @Removal(version="3.17")
short BORDER_MEDIUM_DASHED = 0x8;
-
/** dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT}
*/
+ @Removal(version="3.17")
short BORDER_DASH_DOT = 0x9;
/** medium dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT}
*/
+ @Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT = 0xA;
/** dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT}
*/
+ @Removal(version="3.17")
short BORDER_DASH_DOT_DOT = 0xB;
/** medium dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT}
*/
+ @Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/** slanted dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT}
*/
+ @Removal(version="3.17")
short BORDER_SLANTED_DASH_DOT = 0xD;
- BorderStyle getBorderBottom();
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
+ short getBorderBottom();
+ /** @since POI 3.15 */
+ BorderStyle getBorderBottomEnum();
- BorderStyle getBorderDiagonal();
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
+ short getBorderDiagonal();
+ /** @since POI 3.15 */
+ BorderStyle getBorderDiagonalEnum();
- BorderStyle getBorderLeft();
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
+ short getBorderLeft();
+ /** @since POI 3.15 */
+ BorderStyle getBorderLeftEnum();
- BorderStyle getBorderRight();
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
+ short getBorderRight();
+ /** @since POI 3.15 */
+ BorderStyle getBorderRightEnum();
- BorderStyle getBorderTop();
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
+ short getBorderTop();
+ /** @since POI 3.15 */
+ BorderStyle getBorderTopEnum();
+
short getBottomBorderColor();
Color getBottomBorderColorColor();
diff --git a/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java b/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java index 708f2f66a4..8d11881785 100644 --- a/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java +++ b/src/java/org/apache/poi/ss/usermodel/BuiltinFormats.java @@ -75,7 +75,7 @@ public final class BuiltinFormats { "#,##0.00", "\"$\"#,##0_);(\"$\"#,##0)", "\"$\"#,##0_);[Red](\"$\"#,##0)", - "\"$\"#,##,00_);(\"$\"#,##0.00)", + "\"$\"#,##0.00_);(\"$\"#,##0.00)", "\"$\"#,##0.00_);[Red](\"$\"#,##0.00)", "0%", "0.00%", diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java index 95840a6c01..13d8608230 100644 --- a/src/java/org/apache/poi/ss/usermodel/Cell.java +++ b/src/java/org/apache/poi/ss/usermodel/Cell.java @@ -24,6 +24,7 @@ import org.apache.poi.ss.formula.FormulaParseException; import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * High level representation of a cell in a row of a spreadsheet. @@ -46,7 +47,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#NUMERIC} instead. */ - CellType CELL_TYPE_NUMERIC = CellType.NUMERIC; + @Removal(version="4.0") + int CELL_TYPE_NUMERIC = 0; //CellType.NUMERIC.getCode(); /** * String Cell type (1) @@ -54,7 +56,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#STRING} instead. */ - CellType CELL_TYPE_STRING = CellType.STRING; + @Removal(version="4.0") + int CELL_TYPE_STRING = 1; //CellType.STRING.getCode(); /** * Formula Cell type (2) @@ -62,7 +65,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#FORMULA} instead. */ - CellType CELL_TYPE_FORMULA = CellType.FORMULA; + @Removal(version="4.0") + int CELL_TYPE_FORMULA = 2; //CellType.FORMULA.getCode(); /** * Blank Cell type (3) @@ -70,7 +74,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#BLANK} instead. */ - CellType CELL_TYPE_BLANK = CellType.BLANK; + @Removal(version="4.0") + int CELL_TYPE_BLANK = 3; //CellType.BLANK.getCode(); /** * Boolean Cell type (4) @@ -78,7 +83,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#BOOLEAN} instead. */ - CellType CELL_TYPE_BOOLEAN = CellType.BOOLEAN; + @Removal(version="4.0") + int CELL_TYPE_BOOLEAN = 4; //CellType.BOOLEAN.getCode(); /** * Error Cell type (5) @@ -86,7 +92,8 @@ public interface Cell { * @see #getCellType() * @deprecated POI 3.15 beta 3. Use {@link CellType#ERROR} instead. */ - CellType CELL_TYPE_ERROR = CellType.ERROR; + @Removal(version="4.0") + int CELL_TYPE_ERROR = 5; //CellType.ERROR.getCode(); /** * Returns column index of this cell @@ -136,6 +143,7 @@ public interface Cell { * @see CellType#ERROR * @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead. */ + @Removal(version="4.0") void setCellType(int cellType); /** * Set the cells type (numeric, formula or string). @@ -155,10 +163,11 @@ public interface Cell { /** * Return the cell type. * - * Will return {@link CellType} in a future version of POI. + * Will return {@link CellType} in version 4.0 of POI. * For forwards compatibility, do not hard-code cell type literals in your code. * * @return the cell type + * @deprecated POI 3.15. Will return a {@link CellType} enum in the future. */ int getCellType(); @@ -168,9 +177,9 @@ public interface Cell { * @return the cell type * @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. + * Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") + @Removal(version="4.2") CellType getCellTypeEnum(); /** @@ -182,6 +191,7 @@ 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. */ int getCachedFormulaResultType(); @@ -192,9 +202,8 @@ public interface Cell { * on the cached value of the formula * @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. + * Will be renamed to <code>getCachedFormulaResultType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791. */ - @Internal(since="POI 3.15 beta 3") CellType getCachedFormulaResultTypeEnum(); /** diff --git a/src/java/org/apache/poi/ss/usermodel/CellStyle.java b/src/java/org/apache/poi/ss/usermodel/CellStyle.java index b6c9719790..df3d572598 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellStyle.java +++ b/src/java/org/apache/poi/ss/usermodel/CellStyle.java @@ -17,270 +17,316 @@ package org.apache.poi.ss.usermodel; +import org.apache.poi.util.Removal; + public interface CellStyle { /** * general (normal) horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#GENERAL} instead. */ + @Removal(version="3.17") static final short ALIGN_GENERAL = 0x0; //HorizontalAlignment.GENERAL.getCode(); /** * left-justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#LEFT} instead. */ + @Removal(version="3.17") static final short ALIGN_LEFT = 0x1; //HorizontalAlignment.LEFT.getCode(); /** * center horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER} instead. */ + @Removal(version="3.17") static final short ALIGN_CENTER = 0x2; //HorizontalAlignment.CENTER.getCode(); /** * right-justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#RIGHT} instead. */ + @Removal(version="3.17") static final short ALIGN_RIGHT = 0x3; //HorizontalAlignment.RIGHT.getCode(); /** * fill? horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#FILL} instead. */ + @Removal(version="3.17") static final short ALIGN_FILL = 0x4; //HorizontalAlignment.FILL.getCode(); /** * justified horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#JUSTIFY} instead. */ + @Removal(version="3.17") static final short ALIGN_JUSTIFY = 0x5; //HorizontalAlignment.JUSTIFY.getCode(); /** * center-selection? horizontal alignment * @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER_SELECTION} instead. */ + @Removal(version="3.17") static final short ALIGN_CENTER_SELECTION = 0x6; //HorizontalAlignment.CENTER_SELECTION.getCode(); /** * top-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#TOP} instead. */ + @Removal(version="3.17") static final short VERTICAL_TOP = 0x0; //VerticalAlignment.TOP.getCode(); /** * center-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#CENTER} instead. */ + @Removal(version="3.17") static final short VERTICAL_CENTER = 0x1; //VerticalAlignment.CENTER.getCode(); /** * bottom-aligned vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#BOTTOM} instead. */ + @Removal(version="3.17") static final short VERTICAL_BOTTOM = 0x2; //VerticalAlignment.BOTTOM.getCode(); /** * vertically justified vertical alignment * @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#JUSTIFY} instead. */ + @Removal(version="3.17") static final short VERTICAL_JUSTIFY = 0x3; //VerticalAlignment.JUSTIFY.getCode(); /** * No border * @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE} instead. */ + @Removal(version="3.17") static final short BORDER_NONE = 0x0; //BorderStyle.NONE.getCode(); /** * Thin border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN} instead. */ + @Removal(version="3.17") static final short BORDER_THIN = 0x1; //BorderStyle.THIN.getCode(); /** * Medium border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM = 0x2; //BorderStyle.MEDIUM.getCode(); /** * dash border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED} instead. */ + @Removal(version="3.17") static final short BORDER_DASHED = 0x3; //BorderStyle.DASHED.getCode(); /** * dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED} instead. */ + @Removal(version="3.17") static final short BORDER_DOTTED = 0x4; //BorderStyle.DOTTED.getCode(); /** * Thick border * @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK} instead. */ + @Removal(version="3.17") static final short BORDER_THICK = 0x5; //BorderStyle.THICK.getCode(); /** * double-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE} instead. */ + @Removal(version="3.17") static final short BORDER_DOUBLE = 0x6; //BorderStyle.DOUBLE.getCode(); /** * hair-line border * @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR} instead. */ + @Removal(version="3.17") static final short BORDER_HAIR = 0x7; //BorderStyle.HAIR.getCode(); /** * Medium dashed border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASHED = 0x8; //BorderStyle.MEDIUM_DASHED.getCode(); /** * dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_DASH_DOT = 0x9; //BorderStyle.DASH_DOT.getCode(); /** * medium dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASH_DOT = 0xA; //BorderStyle.MEDIUM_DASH_DOT.getCode(); /** * dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_DASH_DOT_DOT = 0xB; //BorderStyle.DASH_DOT_DOT.getCode(); /** * medium dash-dot-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; //BorderStyle.MEDIUM_DASH_DOT_DOT.getCode(); /** * slanted dash-dot border * @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT} instead. */ + @Removal(version="3.17") static final short BORDER_SLANTED_DASH_DOT = 0xD; //BorderStyle.SLANTED_DASH_DOT.getCode(); /** * Fill Pattern: No background * @deprecated 3.15 beta 3. Use {@link FillPatternType#NO_FILL} instead. */ + @Removal(version="3.17") static final short NO_FILL = 0; //FillPatternType.NO_FILL.getCode(); /** * Fill Pattern: Solidly filled * @deprecated 3.15 beta 3. Use {@link FillPatternType#SOLID_FOREGROUND} instead. */ + @Removal(version="3.17") static final short SOLID_FOREGROUND = 1; //FillPatternType.SOLID_FOREGROUND.getCode(); /** * Fill Pattern: Small fine dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#FINE_DOTS} instead. */ + @Removal(version="3.17") static final short FINE_DOTS = 2; //FillPatternType.FINE_DOTS.getCode(); /** * Fill Pattern: Wide dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#ALT_BARS} instead. */ + @Removal(version="3.17") static final short ALT_BARS = 3; //FillPatternType.ALT_BARS.getCode(); /** * Fill Pattern: Sparse dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#SPARSE_DOTS} instead. */ + @Removal(version="3.17") static final short SPARSE_DOTS = 4; //FillPatternType.SPARSE_DOTS.getCode(); /** * Fill Pattern: Thick horizontal bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_HORZ_BANDS} instead. */ + @Removal(version="3.17") static final short THICK_HORZ_BANDS = 5; //FillPatternType.THICK_HORZ_BANDS.getCode(); /** * Fill Pattern: Thick vertical bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_VERT_BANDS} instead. */ + @Removal(version="3.17") static final short THICK_VERT_BANDS = 6; //FillPatternType.THICK_VERT_BANDS.getCode(); /** * Fill Pattern: Thick backward facing diagonals * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_BACKWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THICK_BACKWARD_DIAG = 7; //FillPatternType.THICK_BACKWARD_DIAG.getCode(); /** * Fill Pattern: Thick forward facing diagonals * @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_FORWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THICK_FORWARD_DIAG = 8; //FillPatternType.THICK_FORWARD_DIAG.getCode(); /** * Fill Pattern: Large spots * @deprecated 3.15 beta 3. Use {@link FillPatternType#BIG_SPOTS} instead. */ + @Removal(version="3.17") static final short BIG_SPOTS = 9; //FillPatternType.BIG_SPOTS.getCode(); /** * Fill Pattern: Brick-like layout * @deprecated 3.15 beta 3. Use {@link FillPatternType#BRICKS} instead. */ + @Removal(version="3.17") static final short BRICKS = 10; //FillPatternType.BRICKS.getCode(); /** * Fill Pattern: Thin horizontal bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_HORZ_BANDS} instead. */ + @Removal(version="3.17") static final short THIN_HORZ_BANDS = 11; //FillPatternType.THIN_HORZ_BANDS.getCode(); /** * Fill Pattern: Thin vertical bands * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_VERT_BANDS} instead. */ + @Removal(version="3.17") static final short THIN_VERT_BANDS = 12; //FillPatternType.THIN_VERT_BANDS.getCode(); /** * Fill Pattern: Thin backward diagonal * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_BACKWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THIN_BACKWARD_DIAG = 13; //FillPatternType.THIN_BACKWARD_DIAG.getCode(); /** * Fill Pattern: Thin forward diagonal * @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_FORWARD_DIAG} instead. */ + @Removal(version="3.17") static final short THIN_FORWARD_DIAG = 14; //FillPatternType.THIN_FORWARD_DIAG.getCode(); /** * Fill Pattern: Squares * @deprecated 3.15 beta 3. Use {@link FillPatternType#SQUARES} instead. */ + @Removal(version="3.17") static final short SQUARES = 15; //FillPatternType.SQUARES.getCode(); /** * Fill Pattern: Diamonds * @deprecated 3.15 beta 3. Use {@link FillPatternType#DIAMONDS} instead. */ + @Removal(version="3.17") static final short DIAMONDS = 16; //FillPatternType.DIAMONDS.getCode(); /** * Fill Pattern: Less Dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#LESS_DOTS} instead. */ + @Removal(version="3.17") static final short LESS_DOTS = 17; //FillPatternType.LESS_DOTS.getCode(); /** * Fill Pattern: Least Dots * @deprecated 3.15 beta 3. Use {@link FillPatternType#LEAST_DOTS} instead. */ + @Removal(version="3.17") static final short LEAST_DOTS = 18; //FillPatternType.LEAST_DOTS.getCode(); /** @@ -495,19 +541,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderLeft(short border); /** * set the type of border to use for the left border of the cell * @param border type + * @since POI 3.15 */ void setBorderLeft(BorderStyle border); /** * get the type of border to use for the left border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()} instead. + * This will return a BorderStyle enum in the future. + */ + short getBorderLeft(); + /** + * get the type of border to use for the left border of the cell + * @return border type + * @since POI 3.15 */ - BorderStyle getBorderLeft(); + BorderStyle getBorderLeftEnum(); /** * set the type of border to use for the right border of the cell @@ -528,19 +584,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderRight(short border); /** * set the type of border to use for the right border of the cell * @param border type + * @since POI 3.15 */ void setBorderRight(BorderStyle border); /** * get the type of border to use for the right border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()} instead. + * This will return a BorderStyle enum in the future. + */ + short getBorderRight(); + /** + * get the type of border to use for the right border of the cell + * @return border type + * @since POI 3.15 */ - BorderStyle getBorderRight(); + BorderStyle getBorderRightEnum(); /** * set the type of border to use for the top border of the cell @@ -561,19 +627,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)} instead */ + @Removal(version="3.17") void setBorderTop(short border); /** * set the type of border to use for the top border of the cell * @param border type + * @since POI 3.15 */ void setBorderTop(BorderStyle border); /** * get the type of border to use for the top border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()} instead. + * This will return a BorderStyle enum in the future. */ - BorderStyle getBorderTop(); + short getBorderTop(); + /** + * get the type of border to use for the top border of the cell + * @return border type + * @since POI 3.15 + */ + BorderStyle getBorderTopEnum(); /** * set the type of border to use for the bottom border of the cell @@ -594,19 +670,29 @@ public interface CellStyle { * @see #BORDER_SLANTED_DASH_DOT * @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)} instead. */ + @Removal(version="3.17") void setBorderBottom(short border); /** * set the type of border to use for the bottom border of the cell * @param border type + * @since POI 3.15 */ void setBorderBottom(BorderStyle border); /** * get the type of border to use for the bottom border of the cell * @return border type + * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()} instead. + * This will return a BorderStyle enum in the future. + */ + short getBorderBottom(); + /** + * get the type of border to use for the bottom border of the cell + * @return border type + * @since POI 3.15 */ - BorderStyle getBorderBottom(); + BorderStyle getBorderBottomEnum(); /** * set the color to use for the left border diff --git a/src/java/org/apache/poi/ss/usermodel/CellValue.java b/src/java/org/apache/poi/ss/usermodel/CellValue.java index 52fea225ab..301accfca8 100644 --- a/src/java/org/apache/poi/ss/usermodel/CellValue.java +++ b/src/java/org/apache/poi/ss/usermodel/CellValue.java @@ -78,11 +78,23 @@ public final class CellValue { } /** * @return Returns the cellType. + * @since POI 3.15 */ - public CellType getCellType() { + public CellType getCellTypeEnum() { return _cellType; } /** + * @return Returns the cellType. + * @deprecated POI 3.15. Use {@link #getCellTypeEnum()} instead. + * In the future, the signature of this method will be changed to return a + * {@link CellType}. + */ + @Deprecated + public int getCellType() { + return _cellType.getCode(); + } + + /** * @return Returns the errorValue. */ public byte getErrorValue() { diff --git a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java index 672c1e2302..702970c69e 100644 --- a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -17,6 +17,7 @@ package org.apache.poi.ss.usermodel; import org.apache.poi.util.Internal; +import org.apache.poi.util.Removal; /** * A client anchor is attached to an excel worksheet. It anchors against a @@ -35,6 +36,7 @@ public interface ClientAnchor { * </p> * @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_AND_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType MOVE_AND_RESIZE = AnchorType.MOVE_AND_RESIZE; /** @@ -50,6 +52,7 @@ public interface ClientAnchor { * </p> * @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_DONT_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType MOVE_DONT_RESIZE = AnchorType.MOVE_DONT_RESIZE; /** @@ -66,6 +69,7 @@ public interface ClientAnchor { * </p> * @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#DONT_MOVE_AND_RESIZE} instead. */ + @Removal(version="3.17") public static final AnchorType DONT_MOVE_AND_RESIZE = AnchorType.DONT_MOVE_AND_RESIZE; /** @@ -288,11 +292,20 @@ public interface ClientAnchor { /** * Sets the anchor type * @param anchorType the anchor type to set + * @since POI 3.14 */ public void setAnchorType( AnchorType anchorType ); + /** + * Sets the anchor type + * @param anchorType the anchor type to set + * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead. + */ + @Removal(version="3.17") + public void setAnchorType( int anchorType ); /** * Gets the anchor type + * Changed from returning an int to an enum in POI 3.14 beta 1. * @return the anchor type */ public AnchorType getAnchorType(); diff --git a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java index 25e1cdaae8..53462c1d4e 100644 --- a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java +++ b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java @@ -17,18 +17,18 @@ package org.apache.poi.ss.usermodel; import org.apache.poi.common.usermodel.HyperlinkType; +import org.apache.poi.util.Removal; /** * An object that handles instantiating concrete * classes of the various instances one needs for * HSSF and XSSF. - * Works around a major shortcoming in Java, where we - * can't have static methods on interfaces or abstract + * Works around a limitation in Java where we + * cannot have static methods on interfaces or abstract * classes. * This allows you to get the appropriate class for * a given interface, without you having to worry - * about if you're dealing with HSSF or XSSF, despite - * Java being quite rubbish. + * about if you're dealing with HSSF or XSSF. */ public interface CreationHelper { /** @@ -46,6 +46,7 @@ public interface CreationHelper { * Creates a new Hyperlink, of the given type * @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead. */ + @Removal(version="3.17") @Deprecated Hyperlink createHyperlink(int type); diff --git a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java index f54fb4f7b4..d40a8d11c5 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java +++ b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java @@ -38,8 +38,8 @@ public enum DataConsolidateFunction { VAR(10, "Var"), VARP(11, "Varp"); - private int value; - private String name; + private final int value; + private final String name; DataConsolidateFunction(int value, String name) { this.value = value; diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java index ee6583937b..61a5092f22 100644 --- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java +++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java @@ -895,7 +895,7 @@ public class DataFormatter implements Observer { return cell.getRichStringCellValue().getString(); case BOOLEAN : - return String.valueOf(cell.getBooleanCellValue()); + return cell.getBooleanCellValue() ? "TRUE" : "FALSE"; case BLANK : return ""; case ERROR: diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaError.java b/src/java/org/apache/poi/ss/usermodel/FormulaError.java index 583ca06d9c..fa102299e8 100644 --- a/src/java/org/apache/poi/ss/usermodel/FormulaError.java +++ b/src/java/org/apache/poi/ss/usermodel/FormulaError.java @@ -166,19 +166,19 @@ public enum FormulaError { return false; } - public static FormulaError forInt(byte type){ + public static FormulaError forInt(byte type) throws IllegalArgumentException { FormulaError err = bmap.get(type); if(err == null) throw new IllegalArgumentException("Unknown error type: " + type); return err; } - public static FormulaError forInt(int type){ + public static FormulaError forInt(int type) throws IllegalArgumentException { FormulaError err = imap.get(type); if(err == null) err = bmap.get((byte)type); if(err == null) throw new IllegalArgumentException("Unknown error type: " + type); return err; } - public static FormulaError forString(String code){ + public static FormulaError forString(String code) throws IllegalArgumentException { FormulaError err = smap.get(code); if(err == null) throw new IllegalArgumentException("Unknown error code: " + code); return err; diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java index be75ff9d55..357bd073a6 100644 --- a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java +++ b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java @@ -101,6 +101,7 @@ 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); diff --git a/src/java/org/apache/poi/ss/usermodel/Row.java b/src/java/org/apache/poi/ss/usermodel/Row.java index b17edcd303..f58775704c 100644 --- a/src/java/org/apache/poi/ss/usermodel/Row.java +++ b/src/java/org/apache/poi/ss/usermodel/Row.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel; import java.util.Iterator; +import org.apache.poi.util.Removal; + /** * High level representation of a row of a spreadsheet. */ @@ -240,8 +242,10 @@ public interface Row extends Iterable<Cell> { CREATE_NULL_AS_BLANK(3); /** - * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed + * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed. + * The {@code id} is only kept only for backwards compatibility with applications that hard-coded the number */ + @Removal(version="3.17") @Deprecated public final int id; private MissingCellPolicy(int id) { @@ -254,6 +258,7 @@ public interface Row extends Iterable<Cell> { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy RETURN_NULL_AND_BLANK = MissingCellPolicy.RETURN_NULL_AND_BLANK; /** @@ -261,6 +266,7 @@ public interface Row extends Iterable<Cell> { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy RETURN_BLANK_AS_NULL = MissingCellPolicy.RETURN_BLANK_AS_NULL; /** @@ -268,6 +274,7 @@ public interface Row extends Iterable<Cell> { * * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum **/ + @Removal(version="3.17") @Deprecated public static final MissingCellPolicy CREATE_NULL_AS_BLANK = MissingCellPolicy.CREATE_NULL_AS_BLANK; diff --git a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java index 3bf891e0a9..75e7fd9a81 100644 --- a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java +++ b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java @@ -42,7 +42,7 @@ public class DataSources { return new AbstractCellRangeDataSource<Number>(sheet, cellRangeAddress) { public Number getPointAt(int index) { CellValue cellValue = getCellValueAt(index); - if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) { + if (cellValue != null && cellValue.getCellTypeEnum() == CellType.NUMERIC) { return Double.valueOf(cellValue.getNumberValue()); } else { return null; @@ -59,7 +59,7 @@ public class DataSources { return new AbstractCellRangeDataSource<String>(sheet, cellRangeAddress) { public String getPointAt(int index) { CellValue cellValue = getCellValueAt(index); - if (cellValue != null && cellValue.getCellType() == CellType.STRING) { + if (cellValue != null && cellValue.getCellTypeEnum() == CellType.STRING) { return cellValue.getStringValue(); } else { return null; diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index 4f446c10dc..3dad83aab6 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -405,10 +405,10 @@ public final class CellUtil { Map<String, Object> properties = new HashMap<String, Object>(); put(properties, ALIGNMENT, style.getAlignmentEnum()); put(properties, VERTICAL_ALIGNMENT, style.getVerticalAlignmentEnum()); - put(properties, BORDER_BOTTOM, style.getBorderBottom()); - put(properties, BORDER_LEFT, style.getBorderLeft()); - put(properties, BORDER_RIGHT, style.getBorderRight()); - put(properties, BORDER_TOP, style.getBorderTop()); + put(properties, BORDER_BOTTOM, style.getBorderBottomEnum()); + put(properties, BORDER_LEFT, style.getBorderLeftEnum()); + put(properties, BORDER_RIGHT, style.getBorderRightEnum()); + put(properties, BORDER_TOP, style.getBorderTopEnum()); put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor()); put(properties, DATA_FORMAT, style.getDataFormat()); put(properties, FILL_PATTERN, style.getFillPatternEnum()); |