From cac40dd101f2d3b3cf077f73a00bcca927af3a69 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 28 Dec 2015 14:50:54 +0000 Subject: [PATCH] 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 --- .../apache/poi/hssf/usermodel/HSSFWorkbook.java | 9 ++++----- .../org/apache/poi/ss/usermodel/Workbook.java | 4 ++-- src/java/org/apache/poi/ss/util/CellUtil.java | 4 ++-- .../apache/poi/xssf/streaming/SXSSFWorkbook.java | 4 ++-- .../apache/poi/xssf/usermodel/XSSFWorkbook.java | 15 ++------------- .../apache/poi/xssf/usermodel/TestXSSFBugs.java | 2 ++ .../poi/xssf/usermodel/TestXSSFCellStyle.java | 4 ++-- .../poi/xssf/usermodel/TestXSSFWorkbook.java | 3 +-- .../org/apache/poi/hssf/usermodel/TestBugs.java | 4 ++-- 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 { * * @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 { * @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 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 @@ -853,16 +853,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { return pictures; //YK: should return Collections.unmodifiableList(pictures); } - /** - * Get the cell style object at the given index - * - * @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 * @@ -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 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 collecteddStyles = new ArrayList(); - 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) { -- 2.39.5