diff options
author | Javen O'Neal <onealj@apache.org> | 2015-12-28 14:50:54 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2015-12-28 14:50:54 +0000 |
commit | cac40dd101f2d3b3cf077f73a00bcca927af3a69 (patch) | |
tree | 5a93a1b7d20b3093641b723aff9e6b00525022e8 /src | |
parent | 35c8e0c5edee6ac7438b1c6b9dbfad76ba63e6ae (diff) | |
download | poi-cac40dd101f2d3b3cf077f73a00bcca927af3a69.tar.gz poi-cac40dd101f2d3b3cf077f73a00bcca927af3a69.zip |
bug 58775: use short for data format index, int for cell style index
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1721930 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
9 files changed, 19 insertions, 30 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 2192fa3dcd..2c1d90d1fd 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -1322,11 +1322,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * get the number of styles the workbook contains * @return count of cell styles */ - @Override - public short getNumCellStyles() + public int getNumCellStyles() { - return (short) workbook.getNumExFormats(); + return workbook.getNumExFormats(); } /** @@ -1335,10 +1334,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * @return HSSFCellStyle object at the index */ @Override - public HSSFCellStyle getCellStyleAt(short idx) + public HSSFCellStyle getCellStyleAt(int idx) { ExtendedFormatRecord xfr = workbook.getExFormatAt(idx); - HSSFCellStyle style = new HSSFCellStyle(idx, xfr, this); + HSSFCellStyle style = new HSSFCellStyle((short)idx, xfr, this); return style; } diff --git a/src/java/org/apache/poi/ss/usermodel/Workbook.java b/src/java/org/apache/poi/ss/usermodel/Workbook.java index fad937a646..83fea32e0a 100644 --- a/src/java/org/apache/poi/ss/usermodel/Workbook.java +++ b/src/java/org/apache/poi/ss/usermodel/Workbook.java @@ -344,7 +344,7 @@ public interface Workbook extends Closeable, Iterable<Sheet> { * * @return count of cell styles */ - short getNumCellStyles(); + int getNumCellStyles(); /** * Get the cell style object at the given index @@ -352,7 +352,7 @@ public interface Workbook extends Closeable, Iterable<Sheet> { * @param idx index within the set of styles (0-based) * @return CellStyle object at the index */ - CellStyle getCellStyleAt(short idx); + CellStyle getCellStyleAt(int idx); /** * Write out this workbook to an Outputstream. diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index f3ef6fd59a..cc07b483f6 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -189,9 +189,9 @@ public final class CellUtil { // index seems like what index the cellstyle is in the list of styles for a workbook. // not good to compare on! - short numberCellStyles = workbook.getNumCellStyles(); + int numberCellStyles = workbook.getNumCellStyles(); - for (short i = 0; i < numberCellStyles; i++) { + for (int i = 0; i < numberCellStyles; i++) { CellStyle wbStyle = workbook.getCellStyleAt(i); Map<String, Object> wbStyleMap = getFormatProperties(wbStyle); diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java index 3c16b2cbe8..20ac62e101 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java @@ -877,7 +877,7 @@ public class SXSSFWorkbook implements Workbook { * @return count of cell styles */ @Override - public short getNumCellStyles() + public int getNumCellStyles() { return _wb.getNumCellStyles(); } @@ -889,7 +889,7 @@ public class SXSSFWorkbook implements Workbook { * @return CellStyle object at the index */ @Override - public CellStyle getCellStyleAt(short idx) + public CellStyle getCellStyleAt(int idx) { return _wb.getCellStyleAt(idx); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 864e4a2c60..95bbff9e12 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -859,16 +859,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { * @param idx index within the set of styles * @return XSSFCellStyle object at the index */ - @Override - public XSSFCellStyle getCellStyleAt(short idx) { - return getCellStyleAt(idx&0xffff); - } - /** - * Get the cell style object at the given index - * - * @param idx index within the set of styles - * @return XSSFCellStyle object at the index - */ public XSSFCellStyle getCellStyleAt(int idx) { return stylesSource.getStyleAt(idx); } @@ -931,9 +921,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { * * @return count of cell styles */ - @Override - public short getNumCellStyles() { - return (short) (stylesSource).getNumCellStyles(); + public int getNumCellStyles() { + return stylesSource.getNumCellStyles(); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 6474c7d1ce..e6719ed272 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -2507,6 +2507,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { XSSFCellStyle style = wb.createCellStyle(); assertEquals(i, style.getUIndex()); } + assertEquals(numStyles, wb.getNumCellStyles()); // avoid OOM in gump run File file = XSSFTestDataSamples.writeOutAndClose(wb, "bug57880"); @@ -2522,6 +2523,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { //Assume identical cell styles aren't consolidated //If XSSFWorkbooks ever implicitly optimize/consolidate cell styles (such as when the workbook is written to disk) //then this unit test should be updated + assertEquals(numStyles, wb.getNumCellStyles()); for (int i=1; i<numStyles; i++) { XSSFCellStyle style = wb.getCellStyleAt(i); assertNotNull(style); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java index b02ac2713f..1b33f28a4f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -1019,9 +1019,9 @@ public class TestXSSFCellStyle { } public static void copyStyles(Workbook reference, Workbook target) { - final short numberOfStyles = reference.getNumCellStyles(); + final int numberOfStyles = reference.getNumCellStyles(); // don't copy default style (style index 0) - for (short i = 1; i < numberOfStyles; i++) { + for (int i = 1; i < numberOfStyles; i++) { final CellStyle referenceStyle = reference.getCellStyleAt(i); final CellStyle targetStyle = target.createCellStyle(); targetStyle.cloneStyleFrom(referenceStyle); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 3e80022ca3..cdd20995a5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -225,9 +225,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { public void getNumCellStyles() throws IOException{ XSSFWorkbook workbook = new XSSFWorkbook(); try { - short i = workbook.getNumCellStyles(); //get default cellStyles - assertEquals(1, i); + assertEquals(1, workbook.getNumCellStyles()); } finally { workbook.close(); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index d9027d2ff9..078008a899 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -2006,7 +2006,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { @Test public void bug49751() throws Exception { HSSFWorkbook wb = openSample("49751.xls"); - short numCellStyles = wb.getNumCellStyles(); + int numCellStyles = wb.getNumCellStyles(); List<String> namedStyles = Arrays.asList( "20% - Accent1", "20% - Accent2", "20% - Accent3", "20% - Accent4", "20% - Accent5", "20% - Accent6", "40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", @@ -2017,7 +2017,7 @@ public final class TestBugs extends BaseTestBugzillaIssues { "Neutral", "Note", "Output", "Title", "Total", "Warning Text"); List<String> collecteddStyles = new ArrayList<String>(); - for (short i = 0; i < numCellStyles; i++) { + for (int i = 0; i < numCellStyles; i++) { HSSFCellStyle cellStyle = wb.getCellStyleAt(i); String styleName = cellStyle.getUserStyleName(); if (styleName != null) { |