From 3eea555e419a1f1108b70f6f37d2aab57b42dbb2 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Thu, 14 Oct 2010 08:40:06 +0000 Subject: [PATCH] revert usages of getXYZList() back to getXYZArray() in XSSF, also misc performance optimizations git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1022420 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/model/CalculationChain.java | 6 +- .../apache/poi/xssf/model/CommentsTable.java | 2 +- .../poi/xssf/model/SharedStringsTable.java | 5 +- .../apache/poi/xssf/model/StylesTable.java | 71 +++++++++++-------- .../xssf/usermodel/XSSFRichTextString.java | 10 +-- .../apache/poi/xssf/usermodel/XSSFRow.java | 3 +- .../apache/poi/xssf/usermodel/XSSFSheet.java | 48 ++++++------- .../poi/xssf/usermodel/XSSFWorkbook.java | 22 +++--- .../xssf/usermodel/helpers/ColumnHelper.java | 12 ++-- .../poi/xssf/usermodel/TestXSSFSheet.java | 23 +++--- 10 files changed, 106 insertions(+), 96 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java b/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java index 43fa663439..bcced82bca 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/CalculationChain.java @@ -78,12 +78,12 @@ public class CalculationChain extends POIXMLDocumentPart { * @param sheetId the sheet Id of a sheet the formula belongs to. * @param ref A1 style reference to the cell containing the formula. */ + @SuppressWarnings("deprecation") // getXYZArray() array accessors are deprecated public void removeItem(int sheetId, String ref){ //sheet Id of a sheet the cell belongs to int id = -1; - CTCalcCell[] c = new CTCalcCell[chain.getCList().size()]; - chain.getCList().toArray(c); - + CTCalcCell[] c = chain.getCArray(); + for (int i = 0; i < c.length; i++){ //If sheet Id is omitted, it is assumed to be the same as the value of the previous cell. if(c[i].isSetI()) id = c[i].getI(); diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java index f443be4837..3e35db871e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java @@ -116,7 +116,7 @@ public class CommentsTable extends POIXMLDocumentPart { // Create the cache if needed if(commentRefs == null) { commentRefs = new HashMap(); - for (CTComment comment : comments.getCommentList().getCommentList()) { + for (CTComment comment : comments.getCommentList().getCommentArray()) { commentRefs.put(comment.getRef(), comment); } } diff --git a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java index 7d738e5871..ad5d751845 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java @@ -84,7 +84,7 @@ public class SharedStringsTable extends POIXMLDocumentPart { */ private int uniqueCount; - public SstDocument _sstDoc; + private SstDocument _sstDoc; public SharedStringsTable() { super(); @@ -103,6 +103,7 @@ public class SharedStringsTable extends POIXMLDocumentPart { * @param is The input stream containing the XML document. * @throws IOException if an error occurs while reading. */ + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public void readFrom(InputStream is) throws IOException { try { int cnt = 0; @@ -110,7 +111,7 @@ public class SharedStringsTable extends POIXMLDocumentPart { CTSst sst = _sstDoc.getSst(); count = (int)sst.getCount(); uniqueCount = (int)sst.getUniqueCount(); - for (CTRst st : sst.getSiList()) { + for (CTRst st : sst.getSiArray()) { stmap.put(st.toString(), cnt); strings.add(st); cnt++; 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 6a4a7678cb..6edb91c6ae 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -106,38 +106,52 @@ public class StylesTable extends POIXMLDocumentPart { * @param is The input stream containing the XML document. * @throws IOException if an error occurs while reading. */ + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support protected void readFrom(InputStream is) throws IOException { try { doc = StyleSheetDocument.Factory.parse(is); - // Grab all the different bits we care about - if(doc.getStyleSheet().getNumFmts() != null) - for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtList()) { - numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode()); - } - if(doc.getStyleSheet().getFonts() != null){ + + CTStylesheet styleSheet = doc.getStyleSheet(); + + // Grab all the different bits we care about + CTNumFmts ctfmts = styleSheet.getNumFmts(); + if( ctfmts != null){ + for (CTNumFmt nfmt : ctfmts.getNumFmtArray()) { + numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode()); + } + } + + CTFonts ctfonts = styleSheet.getFonts(); + if(ctfonts != null){ int idx = 0; - for (CTFont font : doc.getStyleSheet().getFonts().getFontList()) { + for (CTFont font : ctfonts.getFontArray()) { XSSFFont f = new XSSFFont(font, idx); fonts.add(f); idx++; } } - if(doc.getStyleSheet().getFills() != null) - for (CTFill fill : doc.getStyleSheet().getFills().getFillList()) { - fills.add(new XSSFCellFill(fill)); - } - if(doc.getStyleSheet().getBorders() != null) - for (CTBorder border : doc.getStyleSheet().getBorders().getBorderList()) { - borders.add(new XSSFCellBorder(border)); - } - CTCellXfs cellXfs = doc.getStyleSheet().getCellXfs(); - if(cellXfs != null) xfs.addAll(cellXfs.getXfList()); + CTFills ctfills = styleSheet.getFills(); + if(ctfills != null){ + for (CTFill fill : ctfills.getFillArray()) { + fills.add(new XSSFCellFill(fill)); + } + } + + CTBorders ctborders = styleSheet.getBorders(); + if(ctborders != null) { + for (CTBorder border : ctborders.getBorderArray()) { + borders.add(new XSSFCellBorder(border)); + } + } + + CTCellXfs cellXfs = styleSheet.getCellXfs(); + if(cellXfs != null) xfs.addAll(Arrays.asList(cellXfs.getXfArray())); - CTCellStyleXfs cellStyleXfs = doc.getStyleSheet().getCellStyleXfs(); - if(cellStyleXfs != null) styleXfs.addAll(cellStyleXfs.getXfList()); + CTCellStyleXfs cellStyleXfs = styleSheet.getCellStyleXfs(); + if(cellStyleXfs != null) styleXfs.addAll(Arrays.asList(cellStyleXfs.getXfArray())); - CTDxfs styleDxfs = doc.getStyleSheet().getDxfs(); - if(styleDxfs != null) dxfs.addAll(styleDxfs.getDxfList()); + CTDxfs styleDxfs = styleSheet.getDxfs(); + if(styleDxfs != null) dxfs.addAll(Arrays.asList(styleDxfs.getDxfArray())); } catch (XmlException e) { throw new IOException(e.getLocalizedMessage()); @@ -328,6 +342,7 @@ public class StylesTable extends POIXMLDocumentPart { // Work on the current one // Need to do this, as we don't handle // all the possible entries yet + CTStylesheet styleSheet = doc.getStyleSheet(); // Formats CTNumFmts formats = CTNumFmts.Factory.newInstance(); @@ -337,7 +352,7 @@ public class StylesTable extends POIXMLDocumentPart { ctFmt.setNumFmtId(fmt.getKey()); ctFmt.setFormatCode(fmt.getValue()); } - doc.getStyleSheet().setNumFmts(formats); + styleSheet.setNumFmts(formats); int idx; // Fonts @@ -347,7 +362,7 @@ public class StylesTable extends POIXMLDocumentPart { idx = 0; for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont(); ctFonts.setFontArray(ctfnt); - doc.getStyleSheet().setFonts(ctFonts); + styleSheet.setFonts(ctFonts); // Fills CTFills ctFills = CTFills.Factory.newInstance(); @@ -356,7 +371,7 @@ public class StylesTable extends POIXMLDocumentPart { idx = 0; for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill(); ctFills.setFillArray(ctf); - doc.getStyleSheet().setFills(ctFills); + styleSheet.setFills(ctFills); // Borders CTBorders ctBorders = CTBorders.Factory.newInstance(); @@ -365,7 +380,7 @@ public class StylesTable extends POIXMLDocumentPart { idx = 0; for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder(); ctBorders.setBorderArray(ctb); - doc.getStyleSheet().setBorders(ctBorders); + styleSheet.setBorders(ctBorders); // Xfs if(xfs.size() > 0) { @@ -374,7 +389,7 @@ public class StylesTable extends POIXMLDocumentPart { ctXfs.setXfArray( xfs.toArray(new CTXf[xfs.size()]) ); - doc.getStyleSheet().setCellXfs(ctXfs); + styleSheet.setCellXfs(ctXfs); } // Style xfs @@ -384,7 +399,7 @@ public class StylesTable extends POIXMLDocumentPart { ctSXfs.setXfArray( styleXfs.toArray(new CTXf[styleXfs.size()]) ); - doc.getStyleSheet().setCellStyleXfs(ctSXfs); + styleSheet.setCellStyleXfs(ctSXfs); } // Style dxfs @@ -393,7 +408,7 @@ public class StylesTable extends POIXMLDocumentPart { ctDxfs.setCount(dxfs.size()); ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()]) ); - doc.getStyleSheet().setDxfs(ctDxfs); + styleSheet.setDxfs(ctDxfs); } // Save diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java index c406a9b9de..c90fb0f9f5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java @@ -132,6 +132,7 @@ public class XSSFRichTextString implements RichTextString { * @param endIndex The end index to apply to font to (exclusive) * @param font The index of the font to use. */ + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public void applyFont(int startIndex, int endIndex, Font font) { if (startIndex > endIndex) throw new IllegalArgumentException("Start index must be less than end index."); @@ -151,9 +152,7 @@ public class XSSFRichTextString implements RichTextString { XSSFFont xssfFont = (XSSFFont)font; ArrayList runs = new ArrayList(); - CTRElt[] r = new CTRElt[st.getRList().size()]; - st.getRList().toArray(r); - + CTRElt[] r = st.getRArray(); int pos = 0; for (int i = 0; i < r.length; i++) { int rStart = pos; @@ -345,7 +344,7 @@ public class XSSFRichTextString implements RichTextString { return utfDecode(st.getT()); } StringBuffer buf = new StringBuffer(); - for(CTRElt r : st.getRList()){ + for(CTRElt r : st.getRArray()){ buf.append(r.getT()); } return utfDecode(buf.toString()); @@ -429,10 +428,11 @@ public class XSSFRichTextString implements RichTextString { return st; } + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support protected void setStylesTableReference(StylesTable tbl){ styles = tbl; if(st.sizeOfRArray() > 0) { - for (CTRElt r : st.getRList()) { + for (CTRElt r : st.getRArray()) { CTRPrElt pr = r.getRPr(); if(pr != null){ String fontName = pr.getRFontArray(0).getVal(); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index f61717f475..2fbcd19f17 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -59,11 +59,12 @@ public class XSSFRow implements Row, Comparable { * @param row the xml bean containing all cell definitions for this row. * @param sheet the parent sheet. */ + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support protected XSSFRow(CTRow row, XSSFSheet sheet) { _row = row; _sheet = sheet; _cells = new TreeMap(); - for (CTCell c : row.getCList()) { + for (CTCell c : row.getCArray()) { XSSFCell cell = new XSSFCell(this, c); _cells.put(cell.getColumnIndex(), cell); sheet.onReadCell(cell); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index d69456361f..131df845f3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -170,11 +170,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { hyperlinks = new ArrayList(); } + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support private void initRows(CTWorksheet worksheet) { _rows = new TreeMap(); sharedFormulas = new HashMap(); arrayFormulas = new ArrayList(); - for (CTRow row : worksheet.getSheetData().getRowList()) { + for (CTRow row : worksheet.getSheetData().getRowArray()) { XSSFRow r = new XSSFRow(row, this); _rows.put(r.getRowNum(), r); } @@ -194,7 +195,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation()); // Turn each one into a XSSFHyperlink - for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkList()) { + for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) { PackageRelationship hyperRel = null; if(hyperlink.getId() != null) { hyperRel = hyperRels.getRelationshipByID(hyperlink.getId()); @@ -547,9 +548,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { return new int[0]; } - CTBreak[] brkArray = new CTBreak[worksheet.getColBreaks().getBrkList().size()]; - worksheet.getColBreaks().getBrkList().toArray(brkArray); - + CTBreak[] brkArray = worksheet.getColBreaks().getBrkArray(); + int[] breaks = new int[brkArray.length]; for (int i = 0 ; i < brkArray.length ; i++) { CTBreak brk = brkArray[i]; @@ -1003,9 +1003,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { return new int[0]; } - CTBreak[] brkArray = new CTBreak[worksheet.getRowBreaks().getBrkList().size()]; - worksheet.getRowBreaks().getBrkList().toArray(brkArray); - + CTBreak[] brkArray = worksheet.getRowBreaks().getBrkArray(); int[] breaks = new int[brkArray.length]; for (int i = 0 ; i < brkArray.length ; i++) { CTBreak brk = brkArray[i]; @@ -1179,11 +1177,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } - private short getMaxOutlineLevelCols(){ - CTCols ctCols=worksheet.getColsArray(0); - short outlineLevel=0; - for(CTCol col: ctCols.getColList()){ - outlineLevel=col.getOutlineLevel()>outlineLevel? col.getOutlineLevel(): outlineLevel; + private short getMaxOutlineLevelCols() { + CTCols ctCols = worksheet.getColsArray(0); + short outlineLevel = 0; + for (CTCol col : ctCols.getColArray()) { + outlineLevel = col.getOutlineLevel() > outlineLevel ? col.getOutlineLevel() : outlineLevel; } return outlineLevel; } @@ -1327,9 +1325,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * Removes a page break at the indicated column */ public void removeColumnBreak(int column) { - CTBreak[] brkArray = new CTBreak[getSheetTypeColumnBreaks().getBrkList().size()]; - getSheetTypeColumnBreaks().getBrkList().toArray(brkArray); - + CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray(); for (int i = 0 ; i < brkArray.length ; i++) { if (brkArray[i].getId() == column) { getSheetTypeColumnBreaks().removeBrk(i); @@ -1385,8 +1381,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ public void removeRowBreak(int row) { CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks(); - CTBreak[] brkArray = new CTBreak[pgBreak.getBrkList().size()]; - pgBreak.getBrkList().toArray(brkArray); + CTBreak[] brkArray = pgBreak.getBrkArray(); for (int i = 0 ; i < brkArray.length ; i++) { if (brkArray[i].getId() == row) { pgBreak.removeBrk(i); @@ -2159,7 +2154,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { if(sheetComments != null){ //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml CTCommentList lst = sheetComments.getCTComments().getCommentList(); - for (CTComment comment : lst.getCommentList()) { + for (CTComment comment : lst.getCommentArray()) { CellReference ref = new CellReference(comment.getRef()); if(ref.getRow() == rownum){ ref = new CellReference(rownum + n, ref.getCol()); @@ -2285,7 +2280,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ public void setSelected(boolean value) { CTSheetViews views = getSheetTypeSheetViews(); - for (CTSheetView view : views.getSheetViewList()) { + for (CTSheetView view : views.getSheetViewArray()) { view.setTabSelected(value); } } @@ -2361,10 +2356,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ private CTSheetView getDefaultSheetView() { CTSheetViews views = getSheetTypeSheetViews(); - if (views == null || views.getSheetViewList() == null || views.getSheetViewList().size() <= 0) { + int sz = views == null ? 0 : views.sizeOfSheetViewArray(); + if (sz == 0) { return null; } - return views.getSheetViewArray(views.getSheetViewList().size() - 1); + return views.getSheetViewArray(sz - 1); } /** @@ -2438,9 +2434,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { protected void write(OutputStream out) throws IOException { - if(worksheet.getColsList().size() == 1) { + if(worksheet.sizeOfColsArray() == 1) { CTCols col = worksheet.getColsArray(0); - if(col.getColList().size() == 0) { + if(col.sizeOfColArray() == 0) { worksheet.setColsArray(null); } } @@ -2895,7 +2891,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { List xssfValidations = new ArrayList(); CTDataValidations dataValidations = this.worksheet.getDataValidations(); if( dataValidations!=null && dataValidations.getCount() > 0 ) { - for (CTDataValidation ctDataValidation : dataValidations.getDataValidationList()) { + for (CTDataValidation ctDataValidation : dataValidations.getDataValidationArray()) { CellRangeAddressList addressList = new CellRangeAddressList(); @SuppressWarnings("unchecked") @@ -2923,7 +2919,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { if( dataValidations==null ) { dataValidations = worksheet.addNewDataValidations(); } - int currentCount = dataValidations.getDataValidationList().size(); + int currentCount = dataValidations.sizeOfDataValidationArray(); CTDataValidation newval = dataValidations.addNewDataValidation(); newval.set(xssfDataValidation.getCtDdataValidation()); dataValidations.setCount(currentCount + 1); 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 00d2ffee7e..6756c1c259 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -199,6 +199,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable(shIdMap.size()); - for (CTSheet ctSheet : this.workbook.getSheets().getSheetList()) { + for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) { XSSFSheet sh = shIdMap.get(ctSheet.getId()); if(sh == null) { logger.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping"); @@ -238,7 +239,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable(); if(workbook.isSetDefinedNames()) { - for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameList()) { + for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) { namedRanges.add(new XSSFName(ctName, this)); } } @@ -881,12 +882,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable MAX_SENSITIVE_SHEET_NAME_LEN) { name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java index b4158d8b85..f465078acb 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java @@ -53,16 +53,14 @@ public class ColumnHelper { cleanColumns(); } + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public void cleanColumns() { this.newCols = CTCols.Factory.newInstance(); - CTCols[] colsArray = new CTCols[worksheet.getColsList().size()]; - worksheet.getColsList().toArray(colsArray); - + CTCols[] colsArray = worksheet.getColsArray(); int i = 0; for (i = 0; i < colsArray.length; i++) { CTCols cols = colsArray[i]; - CTCol[] colArray = new CTCol[cols.getColList().size()]; - cols.getColList().toArray(colArray); + CTCol[] colArray = cols.getColArray(); for (int y = 0; y < colArray.length; y++) { CTCol col = colArray[y]; newCols = addCleanColIntoCols(newCols, col); @@ -75,9 +73,9 @@ public class ColumnHelper { worksheet.setColsArray(0, newCols); } + @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public static void sortColumns(CTCols newCols) { - CTCol[] colArray = new CTCol[newCols.getColList().size()]; - newCols.getColList().toArray(colArray); + CTCol[] colArray = newCols.getColArray(); Arrays.sort(colArray, new CTColComparator()); newCols.setColArray(colArray); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index f38d773e6a..11267d5853 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -29,6 +29,7 @@ import org.apache.poi.hssf.record.PasswordRecord; import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; +@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support public final class TestXSSFSheet extends BaseTestSheet { public TestXSSFSheet() { @@ -291,7 +292,7 @@ public final class TestXSSFSheet extends BaseTestSheet { sheet.groupColumn(10, 11); CTCols cols = sheet.getCTWorksheet().getColsArray(0); assertEquals(2, cols.sizeOfColArray()); - CTCol[] colArray = cols.getColList().toArray(new CTCol[2]); + CTCol[] colArray = cols.getColArray(); assertNotNull(colArray); assertEquals(2 + 1, colArray[0].getMin()); // 1 based assertEquals(7 + 1, colArray[0].getMax()); // 1 based @@ -301,7 +302,7 @@ public final class TestXSSFSheet extends BaseTestSheet { sheet.groupColumn(1, 2); cols = sheet.getCTWorksheet().getColsArray(0); assertEquals(4, cols.sizeOfColArray()); - colArray = cols.getColList().toArray(new CTCol[0]); + colArray = cols.getColArray(); assertEquals(2, colArray[1].getOutlineLevel()); //three level @@ -309,17 +310,17 @@ public final class TestXSSFSheet extends BaseTestSheet { sheet.groupColumn(2, 3); cols = sheet.getCTWorksheet().getColsArray(0); assertEquals(7, cols.sizeOfColArray()); - colArray = cols.getColList().toArray(new CTCol[0]); + colArray = cols.getColArray(); assertEquals(3, colArray[1].getOutlineLevel()); assertEquals(3, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); sheet.ungroupColumn(8, 10); - colArray = cols.getColList().toArray(new CTCol[0]); + colArray = cols.getColArray(); //assertEquals(3, colArray[1].getOutlineLevel()); sheet.ungroupColumn(4, 6); sheet.ungroupColumn(2, 2); - colArray = cols.getColList().toArray(new CTCol[0]); + colArray = cols.getColArray(); assertEquals(4, colArray.length); assertEquals(2, sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelCol()); } @@ -701,7 +702,7 @@ public final class TestXSSFSheet extends BaseTestSheet { XSSFSheet xs = sheet; CTWorksheet cts = xs.getCTWorksheet(); - CTCols[] cols_s = cts.getColsList().toArray(new CTCols[1]); + CTCols[] cols_s = cts.getColsArray(); assertEquals(1, cols_s.length); CTCols cols = cols_s[0]; assertEquals(1, cols.sizeOfColArray()); @@ -716,7 +717,7 @@ public final class TestXSSFSheet extends BaseTestSheet { // Now set another sheet.setColumnWidth(3, 33 * 256); - cols_s = cts.getColsList().toArray(new CTCols[1]); + cols_s = cts.getColsArray(); assertEquals(1, cols_s.length); cols = cols_s[0]; assertEquals(2, cols.sizeOfColArray()); @@ -922,7 +923,7 @@ public final class TestXSSFSheet extends BaseTestSheet { row3.createCell(5); - CTRow[] xrow = sheetData.getRowList().toArray(new CTRow[3]); + CTRow[] xrow = sheetData.getRowArray(); assertEquals(3, xrow.length); //rows are unsorted: {2, 1, 0} @@ -938,7 +939,7 @@ public final class TestXSSFSheet extends BaseTestSheet { assertEquals(1, xrow[2].getR()); assertTrue(xrow[2].equals(row3.getCTRow())); - CTCell[] xcell = xrow[2].getCList().toArray(new CTCell[4]); + CTCell[] xcell = xrow[2].getCArray(); assertEquals("D1", xcell[0].getR()); assertEquals("A1", xcell[1].getR()); assertEquals("C1", xcell[2].getR()); @@ -954,14 +955,14 @@ public final class TestXSSFSheet extends BaseTestSheet { workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); sheet = workbook.getSheetAt(0); wsh = sheet.getCTWorksheet(); - xrow = sheetData.getRowList().toArray(new CTRow[3]); + xrow = sheetData.getRowArray(); assertEquals(3, xrow.length); //rows are sorted: {0, 1, 2} assertEquals(4, xrow[0].sizeOfCArray()); assertEquals(1, xrow[0].getR()); //cells are now sorted - xcell = xrow[0].getCList().toArray(new CTCell[4]); + xcell = xrow[0].getCArray(); assertEquals("A1", xcell[0].getR()); assertEquals("C1", xcell[1].getR()); assertEquals("D1", xcell[2].getR()); -- 2.39.5