From 736cd9cf49b1cfb116327d052b5ef0f33a0c7850 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 24 Jul 2014 16:41:43 +0000 Subject: [PATCH] For places where an ordered collection is created and used within the context of a single thread, and there are no thread safety concerns, use ArrayList not Vector. See bug #54838 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613186 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFMap.java | 10 ++--- .../apache/poi/xssf/usermodel/XSSFTable.java | 8 ++-- .../QuickButCruddyTextExtractor.java | 28 +++++++------- .../org/apache/poi/hslf/record/PPDrawing.java | 37 ++++++++++++------- .../poi/hslf/record/SlideListWithText.java | 7 ++-- .../hslf/extractor/TestCruddyExtractor.java | 5 ++- 6 files changed, 52 insertions(+), 43 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFMap.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFMap.java index 6ddda437d1..b1f70dbca2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFMap.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFMap.java @@ -17,8 +17,8 @@ package org.apache.poi.xssf.usermodel; +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.util.Internal; @@ -41,12 +41,9 @@ import org.w3c.dom.Node; public class XSSFMap { - private CTMap ctMap; - private MapInfo mapInfo; - public XSSFMap(CTMap ctMap, MapInfo mapInfo) { this.ctMap = ctMap; this.mapInfo = mapInfo; @@ -58,7 +55,6 @@ public class XSSFMap { return ctMap; } - @Internal public CTSchema getCTSchema() { String schemaId = ctMap.getSchemaID(); @@ -78,7 +74,7 @@ public class XSSFMap { * @return the list of Single Xml Cells that provide a map rule to this mapping. */ public List getRelatedSingleXMLCell() { - List relatedSimpleXmlCells = new Vector(); + List relatedSimpleXmlCells = new ArrayList(); int sheetNumber = mapInfo.getWorkbook().getNumberOfSheets(); for (int i = 0; i < sheetNumber; i++) { @@ -102,7 +98,7 @@ public class XSSFMap { */ public List getRelatedTables() { - List tables = new Vector(); + List tables = new ArrayList(); int sheetNumber = mapInfo.getWorkbook().getNumberOfSheets(); for (int i = 0; i < sheetNumber; i++) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java index 9d7e4e77b8..ed1d9a27c5 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -20,9 +20,9 @@ package org.apache.poi.xssf.usermodel; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Vector; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; @@ -176,9 +176,9 @@ public class XSSFTable extends POIXMLDocumentPart { public List getXmlColumnPrs() { if(xmlColumnPr==null){ - xmlColumnPr = new Vector(); - for(CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){ - if(column.getXmlColumnPr()!=null){ + xmlColumnPr = new ArrayList(); + for (CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){ + if (column.getXmlColumnPr()!=null){ XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr()); xmlColumnPr.add(columnPr); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java b/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java index 6983c4927f..e449a555e8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java @@ -17,21 +17,23 @@ package org.apache.poi.hslf.extractor; -import java.io.*; -import java.util.Vector; - -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.poifs.filesystem.DocumentEntry; -import org.apache.poi.util.LittleEndian; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import org.apache.poi.hslf.model.TextRun; import org.apache.poi.hslf.record.CString; import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.record.StyleTextPropAtom; -import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextCharsAtom; -import org.apache.poi.hslf.model.TextRun; +import org.apache.poi.hslf.record.TextHeaderAtom; +import org.apache.poi.poifs.filesystem.DocumentEntry; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.util.LittleEndian; /** * This class will get all the text from a Powerpoint Document, including @@ -122,7 +124,7 @@ public final class QuickButCruddyTextExtractor { */ public String getTextAsString() { StringBuffer ret = new StringBuffer(); - Vector textV = getTextAsVector(); + List textV = getTextAsVector(); for(String text : textV) { ret.append(text); if(! text.endsWith("\n")) { @@ -133,11 +135,11 @@ public final class QuickButCruddyTextExtractor { } /** - * Fetches the ALL the text of the powerpoint file, in a vector of + * Fetches the ALL the text of the powerpoint file, in a List of * strings, one per text record */ - public Vector getTextAsVector() { - Vector textV = new Vector(); + public List getTextAsVector() { + List textV = new ArrayList(); // Set to the start of the file int walkPos = 0; @@ -158,7 +160,7 @@ public final class QuickButCruddyTextExtractor { * If it is a text record, grabs out the text. Whatever happens, returns * the position of the next record, or -1 if no more. */ - public int findTextRecords(int startPos, Vector textV) { + public int findTextRecords(int startPos, List textV) { // Grab the length, and the first option byte // Note that the length doesn't include the 8 byte atom header int len = (int)LittleEndian.getUInt(pptContents,startPos+4); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java index dca88b5191..8b8146f132 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java @@ -17,18 +17,29 @@ package org.apache.poi.hslf.record; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.POILogger; - -import org.apache.poi.ddf.*; -import org.apache.poi.hslf.model.ShapeTypes; - import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Vector; -import java.util.Iterator; + +import org.apache.poi.ddf.DefaultEscherRecordFactory; +import org.apache.poi.ddf.EscherBoolProperty; +import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.ddf.EscherDgRecord; +import org.apache.poi.ddf.EscherOptRecord; +import org.apache.poi.ddf.EscherProperties; +import org.apache.poi.ddf.EscherRGBProperty; +import org.apache.poi.ddf.EscherRecord; +import org.apache.poi.ddf.EscherSimpleProperty; +import org.apache.poi.ddf.EscherSpRecord; +import org.apache.poi.ddf.EscherSpgrRecord; +import org.apache.poi.ddf.EscherTextboxRecord; +import org.apache.poi.ddf.UnknownEscherRecord; +import org.apache.poi.hslf.model.ShapeTypes; +import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogger; /** * These are actually wrappers onto Escher drawings. Make use of @@ -38,8 +49,6 @@ import java.util.Iterator; * (msofbtClientTextbox) records. * Also provides easy access to the EscherTextboxRecords, so that their * text may be extracted and used in Sheets - * - * @author Nick Burch */ // For now, pretending to be an atom. Might not always be, but that @@ -84,7 +93,7 @@ public final class PPDrawing extends RecordAtom { // Build up a tree of Escher records contained within final DefaultEscherRecordFactory erf = new DefaultEscherRecordFactory(); - final Vector escherChildren = new Vector(); + final List escherChildren = new ArrayList(); findEscherChildren(erf, contents, 8, len-8, escherChildren); this.childRecords = (EscherRecord[]) escherChildren.toArray(new EscherRecord[escherChildren.size()]); @@ -92,7 +101,7 @@ public final class PPDrawing extends RecordAtom { this.textboxWrappers = findInDgContainer((EscherContainerRecord) this.childRecords[0]); } else { // Find and EscherTextboxRecord's, and wrap them up - final Vector textboxes = new Vector(); + final List textboxes = new ArrayList(); findEscherTextboxRecord(childRecords, textboxes); this.textboxWrappers = (EscherTextboxWrapper[]) textboxes.toArray(new EscherTextboxWrapper[textboxes.size()]); } @@ -159,7 +168,7 @@ public final class PPDrawing extends RecordAtom { /** * Tree walking way of finding Escher Child Records */ - private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, Vector found) { + private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, List found) { int escherBytes = LittleEndian.getInt( source, startPos + 4 ) + 8; @@ -196,7 +205,7 @@ public final class PPDrawing extends RecordAtom { /** * Look for EscherTextboxRecords */ - private void findEscherTextboxRecord(EscherRecord[] toSearch, Vector found) { + private void findEscherTextboxRecord(EscherRecord[] toSearch, List found) { for(int i=0; i sets = new Vector(); + List sets = new ArrayList(); for(int i=0; i<_children.length; i++) { if(_children[i] instanceof SlidePersistAtom) { // Find where the next SlidePersistAtom is @@ -107,7 +108,7 @@ public final class SlideListWithText extends RecordContainer { } } - // Turn the vector into an array + // Turn the list into an array slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] ); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java index 8b236b31ee..44263ace5c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestCruddyExtractor.java @@ -18,8 +18,9 @@ package org.apache.poi.hslf.extractor; +import java.util.List; + import junit.framework.TestCase; -import java.util.Vector; import org.apache.poi.POIDataSamples; @@ -64,7 +65,7 @@ public final class TestCruddyExtractor extends TestCase { public void testReadAsVector() { // Extract the text from the file as a vector - Vector foundTextV = te.getTextAsVector(); + List foundTextV = te.getTextAsVector(); // Ensure they match assertEquals(allTheText.length,foundTextV.size()); -- 2.39.5