From 292d7ec27c9a91c45aeec8387e7fd9f249d1b1e2 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 14 Sep 2016 04:35:45 +0000 Subject: [PATCH] bug 59264: revert getBorder[Top|Bottom|Left|Right|Diagonal]() to return short and add getBorder[Top|Bottom|Left|Right|Diagonal]Enum() returns BorderStyle enum for backwards compatibility with POI 3.14 and earlier git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760627 13f79535-47bb-0310-9956-ffa450edef68 --- .../hssf/usermodel/HSSFBorderFormatting.java | 65 +++++++++++++++++-- .../poi/ss/usermodel/BorderFormatting.java | 58 +++++++++++++++-- .../xssf/usermodel/XSSFBorderFormatting.java | 65 +++++++++++++++++-- .../apache/poi/hssf/usermodel/TestBugs.java | 4 +- .../BaseTestConditionalFormatting.java | 58 ++++++++--------- 5 files changed, 203 insertions(+), 47 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java index d06c9f179..c4113b615 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 BorderStyle getBorderLeft() { + public short getBorderLeft() { + return (short)borderFormatting.getBorderLeft(); + } + /** + * @since POI 3.15 + */ + @Override + 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 BorderStyle getBorderRight() { + public short getBorderRight() { + return (short)borderFormatting.getBorderRight(); + } + /** + * @since POI 3.15 + */ + @Override + 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 BorderStyle getBorderTop() { + public short getBorderTop() { + return (short)borderFormatting.getBorderTop(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { return BorderStyle.valueOf((short)borderFormatting.getBorderTop()); } diff --git a/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java b/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java index 059cdd065..949cc3d00 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/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java index e48fe948e..edea8cda9 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java @@ -35,32 +35,87 @@ public class XSSFBorderFormatting implements BorderFormatting { _border = border; } + /** + * @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 getBorderBottomEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderBottomEnum() { STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @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 getBorderDiagonalEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderDiagonalEnum() { STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderLeft() { + public short getBorderLeft() { + return getBorderLeftEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderLeftEnum() { STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderRight() { + public short getBorderRight() { + return getBorderRightEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderRightEnum() { STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } + /** + * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}. + * This method will return an BorderStyle enum in the future. + */ @Override - public BorderStyle getBorderTop() { + public short getBorderTop() { + return getBorderTopEnum().getCode(); + } + /** + * @since POI 3.15 + */ + @Override + public BorderStyle getBorderTopEnum() { STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null; return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1)); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 466964acf..dca98f620 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -3051,7 +3051,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { HSSFBorderFormatting bord = rule.createBorderFormatting(); bord.setBorderDiagonal(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, bord.getBorderDiagonal()); + assertEquals(BorderStyle.THICK, bord.getBorderDiagonalEnum()); bord.setBackwardDiagonalOn(true); assertTrue(bord.isBackwardDiagonalOn()); @@ -3064,7 +3064,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { // Create the bottom border style so we know what a border is supposed to look like bord.setBorderBottom(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, bord.getBorderBottom()); + assertEquals(BorderStyle.THICK, bord.getBorderBottomEnum()); bord.setBottomBorderColor(BLUE); assertEquals(BLUE, bord.getBottomBorderColor()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index 5509cbf71..28cfb2cf7 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -363,10 +363,10 @@ public abstract class BaseTestConditionalFormatting { BorderFormatting r1bf = rule1.getBorderFormatting(); assertNotNull(r1bf); - assertEquals(BorderStyle.THIN, r1bf.getBorderBottom()); - assertEquals(BorderStyle.THICK,r1bf.getBorderTop()); - assertEquals(BorderStyle.DASHED,r1bf.getBorderLeft()); - assertEquals(BorderStyle.DOTTED,r1bf.getBorderRight()); + assertEquals(BorderStyle.THIN, r1bf.getBorderBottomEnum()); + assertEquals(BorderStyle.THICK,r1bf.getBorderTopEnum()); + assertEquals(BorderStyle.DASHED,r1bf.getBorderLeftEnum()); + assertEquals(BorderStyle.DOTTED,r1bf.getBorderRightEnum()); PatternFormatting r1pf = rule1.getPatternFormatting(); assertNotNull(r1pf); @@ -1021,19 +1021,19 @@ public abstract class BaseTestConditionalFormatting { for (BorderStyle border : BorderStyle.values()) { borderFmt.setBorderTop(border); - assertEquals(border, borderFmt.getBorderTop()); + assertEquals(border, borderFmt.getBorderTopEnum()); borderFmt.setBorderBottom(border); - assertEquals(border, borderFmt.getBorderBottom()); + assertEquals(border, borderFmt.getBorderBottomEnum()); borderFmt.setBorderLeft(border); - assertEquals(border, borderFmt.getBorderLeft()); + assertEquals(border, borderFmt.getBorderLeftEnum()); borderFmt.setBorderRight(border); - assertEquals(border, borderFmt.getBorderRight()); + assertEquals(border, borderFmt.getBorderRightEnum()); borderFmt.setBorderDiagonal(border); - assertEquals(border, borderFmt.getBorderDiagonal()); + assertEquals(border, borderFmt.getBorderDiagonalEnum()); } workbook.close(); @@ -1049,37 +1049,37 @@ public abstract class BaseTestConditionalFormatting { ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7"); BorderFormatting borderFmt = rule1.createBorderFormatting(); - assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum()); borderFmt.setBorderBottom(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, borderFmt.getBorderBottom()); + assertEquals(BorderStyle.THICK, borderFmt.getBorderBottomEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderTop()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTop()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderTop()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum()); borderFmt.setBorderTop(BorderStyle.THICK); - assertEquals(BorderStyle.THICK, borderFmt.getBorderTop()); + assertEquals(BorderStyle.THICK, borderFmt.getBorderTopEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum()); borderFmt.setBorderLeft(BorderStyle.THIN); - assertEquals(BorderStyle.THIN, borderFmt.getBorderLeft()); + assertEquals(BorderStyle.THIN, borderFmt.getBorderLeftEnum()); - assertEquals(BorderStyle.NONE, borderFmt.getBorderRight()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.DOTTED); - assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRight()); + assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.NONE); - assertEquals(BorderStyle.NONE, borderFmt.getBorderRight()); + assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum()); borderFmt.setBorderRight(BorderStyle.HAIR); - assertEquals(BorderStyle.HAIR, borderFmt.getBorderRight()); + assertEquals(BorderStyle.HAIR, borderFmt.getBorderRightEnum()); ConditionalFormattingRule [] cfRules = { rule1 }; @@ -1095,10 +1095,10 @@ public abstract class BaseTestConditionalFormatting { BorderFormatting r1fp = cf.getRule(0).getBorderFormatting(); assertNotNull(r1fp); - assertEquals(BorderStyle.THICK, r1fp.getBorderBottom()); - assertEquals(BorderStyle.THICK, r1fp.getBorderTop()); - assertEquals(BorderStyle.THIN, r1fp.getBorderLeft()); - assertEquals(BorderStyle.HAIR, r1fp.getBorderRight()); + assertEquals(BorderStyle.THICK, r1fp.getBorderBottomEnum()); + assertEquals(BorderStyle.THICK, r1fp.getBorderTopEnum()); + assertEquals(BorderStyle.THIN, r1fp.getBorderLeftEnum()); + assertEquals(BorderStyle.HAIR, r1fp.getBorderRightEnum()); workbook.close(); }