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
This commit is contained in:
Nick Burch 2014-07-24 16:41:43 +00:00
parent 70b21ffe56
commit bb91152a12
6 changed files with 52 additions and 43 deletions

View File

@ -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<XSSFSingleXmlCell> getRelatedSingleXMLCell() {
List<XSSFSingleXmlCell> relatedSimpleXmlCells = new Vector<XSSFSingleXmlCell>();
List<XSSFSingleXmlCell> relatedSimpleXmlCells = new ArrayList<XSSFSingleXmlCell>();
int sheetNumber = mapInfo.getWorkbook().getNumberOfSheets();
for (int i = 0; i < sheetNumber; i++) {
@ -102,7 +98,7 @@ public class XSSFMap {
*/
public List<XSSFTable> getRelatedTables() {
List<XSSFTable> tables = new Vector<XSSFTable>();
List<XSSFTable> tables = new ArrayList<XSSFTable>();
int sheetNumber = mapInfo.getWorkbook().getNumberOfSheets();
for (int i = 0; i < sheetNumber; i++) {

View File

@ -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<XSSFXmlColumnPr> getXmlColumnPrs() {
if(xmlColumnPr==null){
xmlColumnPr = new Vector<XSSFXmlColumnPr>();
for(CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){
if(column.getXmlColumnPr()!=null){
xmlColumnPr = new ArrayList<XSSFXmlColumnPr>();
for (CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){
if (column.getXmlColumnPr()!=null){
XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr());
xmlColumnPr.add(columnPr);
}

View File

@ -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<String> textV = getTextAsVector();
List<String> 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<String> getTextAsVector() {
Vector<String> textV = new Vector<String>();
public List<String> getTextAsVector() {
List<String> textV = new ArrayList<String>();
// 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<String> textV) {
public int findTextRecords(int startPos, List<String> 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);

View File

@ -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<EscherRecord> escherChildren = new Vector<EscherRecord>();
final List<EscherRecord> escherChildren = new ArrayList<EscherRecord>();
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<EscherTextboxWrapper> textboxes = new Vector<EscherTextboxWrapper>();
final List<EscherTextboxWrapper> textboxes = new ArrayList<EscherTextboxWrapper>();
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<EscherRecord> found) {
private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, List<EscherRecord> 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<EscherTextboxWrapper> found) {
private void findEscherTextboxRecord(EscherRecord[] toSearch, List<EscherTextboxWrapper> found) {
for(int i=0; i<toSearch.length; i++) {
if(toSearch[i] instanceof EscherTextboxRecord) {
EscherTextboxRecord tbr = (EscherTextboxRecord)toSearch[i];

View File

@ -19,7 +19,8 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.util.LittleEndian;
@ -82,7 +83,7 @@ public final class SlideListWithText extends RecordContainer {
// Group our children together into SlideAtomsSets
// That way, model layer code can just grab the sets to use,
// without having to try to match the children together
Vector<SlideAtomsSet> sets = new Vector<SlideAtomsSet>();
List<SlideAtomsSet> sets = new ArrayList<SlideAtomsSet>();
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()] );
}

View File

@ -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<String> foundTextV = te.getTextAsVector();
// Ensure they match
assertEquals(allTheText.length,foundTextV.size());