From c0dbef286bb47d10c115c8583df4d1ddb1563122 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sat, 12 Nov 2016 21:54:22 +0000 Subject: [PATCH] #60331 - Remove deprecated classes (POI 3.16) - remove StylesTable.getNumberFormatAt(int) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1769431 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/model/StylesTable.java | 11 ------ .../poi/xssf/usermodel/XSSFDataFormat.java | 20 ++++++----- .../poi/xssf/model/TestStylesTable.java | 36 ++++++++++--------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java index 209dc722a..18b88203f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -255,17 +255,6 @@ public class StylesTable extends POIXMLDocumentPart { // Start of style related getters and setters // =========================================================== - /** - * Get number format string given its id - * - * @param idx number format id - * @return number format code - * @deprecated POI 3.14-beta2. Use {@link #getNumberFormatAt(short)} instead. - */ - public String getNumberFormatAt(int idx) { - return getNumberFormatAt((short) idx); - } - /** * Get number format string given its id * diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java index 4b117742e..d82524515 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java @@ -18,6 +18,7 @@ package org.apache.poi.xssf.usermodel; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.DataFormat; +import org.apache.poi.util.Removal; import org.apache.poi.xssf.model.StylesTable; /** @@ -60,14 +61,6 @@ public class XSSFDataFormat implements DataFormat { */ @Override public String getFormat(short index) { - return getFormat(index&0xffff); - } - /** - * get the format string that matches the given format index - * @param index of a format - * @return string represented at index of format or null if there is not a format at that index - */ - public String getFormat(int index) { // Indices used for built-in formats may be overridden with // custom formats, such as locale-specific currency. // See org.apache.poi.xssf.usermodel.TestXSSFDataFormat#test49928() @@ -78,6 +71,17 @@ public class XSSFDataFormat implements DataFormat { if(fmt == null) fmt = BuiltinFormats.getBuiltinFormat(index); return fmt; } + /** + * get the format string that matches the given format index + * @param index of a format + * @return string represented at index of format or null if there is not a format at that index + * + * @deprecated POI 3.16 beta 1 - use {@link #getFormat(short)} instead + */ + @Removal(version="3.18") + public String getFormat(int index) { + return getFormat((short)index); + } /** * Add a number format with a specific ID into the number format style table. diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java index 03e232ad2..9d29fc453 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java @@ -111,8 +111,8 @@ public final class TestStylesTable { assertEquals(2, st.getFills().size()); assertEquals(1, st.getBorders().size()); - assertEquals("yyyy/mm/dd", st.getNumberFormatAt(165)); - assertEquals("yy/mm/dd", st.getNumberFormatAt(167)); + assertEquals("yyyy/mm/dd", st.getNumberFormatAt((short)165)); + assertEquals("yy/mm/dd", st.getNumberFormatAt((short)167)); assertNotNull(st.getStyleAt(0)); assertNotNull(st.getStyleAt(1)); @@ -150,7 +150,7 @@ public final class TestStylesTable { assertEquals(1, st._getStyleXfsSize()); assertEquals(2, st.getNumDataFormats()); - assertEquals("yyyy-mm-dd", st.getNumberFormatAt(nf1)); + assertEquals("yyyy-mm-dd", st.getNumberFormatAt((short)nf1)); assertEquals(nf1, st.putNumberFormat("yyyy-mm-dd")); assertEquals(nf2, st.putNumberFormat("yyyy-mm-DD")); @@ -177,7 +177,7 @@ public final class TestStylesTable { assertEquals(1, st._getStyleXfsSize()); assertEquals(10, st.getNumDataFormats()); - assertEquals("YYYY-mm-dd", st.getNumberFormatAt(nf1)); + assertEquals("YYYY-mm-dd", st.getNumberFormatAt((short)nf1)); assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd")); assertEquals(nf2, st.putNumberFormat("YYYY-mm-DD")); @@ -216,22 +216,22 @@ public final class TestStylesTable { @Test public void removeNumberFormat() throws IOException { - XSSFWorkbook wb = new XSSFWorkbook(); + XSSFWorkbook wb1 = new XSSFWorkbook(); try { final String fmt = customDataFormat; - final short fmtIdx = (short) wb.getStylesSource().putNumberFormat(fmt); + final short fmtIdx = (short) wb1.getStylesSource().putNumberFormat(fmt); - Cell cell = wb.createSheet("test").createRow(0).createCell(0); + Cell cell = wb1.createSheet("test").createRow(0).createCell(0); cell.setCellValue(5.25); - CellStyle style = wb.createCellStyle(); + CellStyle style = wb1.createCellStyle(); style.setDataFormat(fmtIdx); cell.setCellStyle(style); assertEquals(fmt, cell.getCellStyle().getDataFormatString()); - assertEquals(fmt, wb.getStylesSource().getNumberFormatAt(fmtIdx)); + assertEquals(fmt, wb1.getStylesSource().getNumberFormatAt(fmtIdx)); // remove the number format from the workbook - wb.getStylesSource().removeNumberFormat(fmt); + wb1.getStylesSource().removeNumberFormat(fmt); // number format in CellStyles should be restored to default number format final short defaultFmtIdx = 0; @@ -240,17 +240,17 @@ public final class TestStylesTable { assertEquals(defaultFmt, style.getDataFormatString()); // The custom number format should be entirely removed from the workbook - Map numberFormats = wb.getStylesSource().getNumberFormats(); + Map numberFormats = wb1.getStylesSource().getNumberFormats(); assertNotContainsKey(numberFormats, fmtIdx); assertNotContainsValue(numberFormats, fmt); // The default style shouldn't be added back to the styles source because it's built-in - assertEquals(0, wb.getStylesSource().getNumDataFormats()); + assertEquals(0, wb1.getStylesSource().getNumDataFormats()); cell = null; style = null; numberFormats = null; - wb = XSSFTestDataSamples.writeOutCloseAndReadBack(wb); + XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutCloseAndReadBack(wb1); - cell = wb.getSheet("test").getRow(0).getCell(0); + cell = wb2.getSheet("test").getRow(0).getCell(0); style = cell.getCellStyle(); // number format in CellStyles should be restored to default number format @@ -258,15 +258,17 @@ public final class TestStylesTable { assertEquals(defaultFmt, style.getDataFormatString()); // The custom number format should be entirely removed from the workbook - numberFormats = wb.getStylesSource().getNumberFormats(); + numberFormats = wb2.getStylesSource().getNumberFormats(); assertNotContainsKey(numberFormats, fmtIdx); assertNotContainsValue(numberFormats, fmt); // The default style shouldn't be added back to the styles source because it's built-in - assertEquals(0, wb.getStylesSource().getNumDataFormats()); + assertEquals(0, wb2.getStylesSource().getNumDataFormats()); + + wb2.close(); } finally { - wb.close(); + wb1.close(); } }