Fix generics warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@995445 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-09-09 14:28:14 +00:00
parent 60ff5c056d
commit dac67e887e
3 changed files with 41 additions and 50 deletions

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.apache.poi.hwpf.model.CHPBinTable; import org.apache.poi.hwpf.model.CHPBinTable;
import org.apache.poi.hwpf.model.CPSplitCalculator; import org.apache.poi.hwpf.model.CPSplitCalculator;
@ -354,13 +355,13 @@ public final class HWPFDocument extends HWPFDocumentCore
*/ */
public int characterLength() public int characterLength()
{ {
java.util.List textPieces = _tpt.getTextPieces(); List<TextPiece> textPieces = _tpt.getTextPieces();
Iterator textIt = textPieces.iterator(); Iterator<TextPiece> textIt = textPieces.iterator();
int length = 0; int length = 0;
while(textIt.hasNext()) while(textIt.hasNext())
{ {
TextPiece tp = (TextPiece)textIt.next(); TextPiece tp = textIt.next();
length += tp.characterLength(); length += tp.characterLength();
} }
return length; return length;

View File

@ -25,7 +25,6 @@ import org.apache.poi.hwpf.usermodel.Range;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.DefaultEscherRecordFactory;
import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherBlipRecord;
@ -146,42 +145,33 @@ public final class PicturesTable
* @param escherRecords the escher records. * @param escherRecords the escher records.
* @param pictures the list to populate with the pictures. * @param pictures the list to populate with the pictures.
*/ */
private void searchForPictures(List escherRecords, List pictures) private void searchForPictures(List<EscherRecord> escherRecords, List<Picture> pictures)
{ {
Iterator recordIter = escherRecords.iterator(); for(EscherRecord escherRecord : escherRecords) {
while (recordIter.hasNext()) if (escherRecord instanceof EscherBSERecord) {
{ EscherBSERecord bse = (EscherBSERecord) escherRecord;
Object obj = recordIter.next(); EscherBlipRecord blip = bse.getBlipRecord();
if (obj instanceof EscherRecord) if (blip != null)
{ {
EscherRecord escherRecord = (EscherRecord) obj; pictures.add(new Picture(blip.getPicturedata()));
}
else if (bse.getOffset() > 0)
{
// Blip stored in delay stream, which in a word doc, is the main stream
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset());
if (escherRecord instanceof EscherBSERecord) if (record instanceof EscherBlipRecord) {
{ record.fillFields(_mainStream, bse.getOffset(), recordFactory);
EscherBSERecord bse = (EscherBSERecord) escherRecord; blip = (EscherBlipRecord) record;
EscherBlipRecord blip = bse.getBlipRecord(); pictures.add(new Picture(blip.getPicturedata()));
if (blip != null) }
{ }
pictures.add(new Picture(blip.getPicturedata())); }
}
else if (bse.getOffset() > 0)
{
// Blip stored in delay stream, which in a word doc, is the main stream
EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
EscherRecord record = recordFactory.createRecord(_mainStream, bse.getOffset());
if (record instanceof EscherBlipRecord) { // Recursive call.
record.fillFields(_mainStream, bse.getOffset(), recordFactory); searchForPictures(escherRecord.getChildRecords(), pictures);
blip = (EscherBlipRecord) record; }
pictures.add(new Picture(blip.getPicturedata()));
}
}
}
// Recursive call.
searchForPictures(escherRecord.getChildRecords(), pictures);
}
}
} }
/** /**
@ -190,8 +180,8 @@ public final class PicturesTable
* *
* @return a list of Picture objects found in current document * @return a list of Picture objects found in current document
*/ */
public List getAllPictures() { public List<Picture> getAllPictures() {
ArrayList pictures = new ArrayList(); ArrayList<Picture> pictures = new ArrayList<Picture>();
Range range = _document.getOverallRange(); Range range = _document.getOverallRange();
for (int i = 0; i < range.numCharacterRuns(); i++) { for (int i = 0; i < range.numCharacterRuns(); i++) {

View File

@ -57,8 +57,8 @@ public final class TestHWPFPictures extends TestCase {
* Test just opening the files * Test just opening the files
*/ */
public void testOpen() { public void testOpen() {
HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile); HWPFTestDataSamples.openSampleFile(docAFile);
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); HWPFTestDataSamples.openSampleFile(docBFile);
} }
/** /**
@ -74,8 +74,8 @@ public final class TestHWPFPictures extends TestCase {
PicturesTable picA = docA.getPicturesTable(); PicturesTable picA = docA.getPicturesTable();
PicturesTable picB = docB.getPicturesTable(); PicturesTable picB = docB.getPicturesTable();
List picturesA = picA.getAllPictures(); List<Picture> picturesA = picA.getAllPictures();
List picturesB = picB.getAllPictures(); List<Picture> picturesB = picB.getAllPictures();
assertEquals(7, picturesA.size()); assertEquals(7, picturesA.size());
assertEquals(2, picturesB.size()); assertEquals(2, picturesB.size());
@ -87,12 +87,12 @@ public final class TestHWPFPictures extends TestCase {
public void testImageData() { public void testImageData() {
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile); HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
PicturesTable picB = docB.getPicturesTable(); PicturesTable picB = docB.getPicturesTable();
List picturesB = picB.getAllPictures(); List<Picture> picturesB = picB.getAllPictures();
assertEquals(2, picturesB.size()); assertEquals(2, picturesB.size());
Picture pic1 = (Picture)picturesB.get(0); Picture pic1 = picturesB.get(0);
Picture pic2 = (Picture)picturesB.get(1); Picture pic2 = picturesB.get(1);
assertNotNull(pic1); assertNotNull(pic1);
assertNotNull(pic2); assertNotNull(pic2);
@ -114,11 +114,11 @@ public final class TestHWPFPictures extends TestCase {
public void testCompressedImageData() { public void testCompressedImageData() {
HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile); HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
PicturesTable picC = docC.getPicturesTable(); PicturesTable picC = docC.getPicturesTable();
List picturesC = picC.getAllPictures(); List<Picture> picturesC = picC.getAllPictures();
assertEquals(1, picturesC.size()); assertEquals(1, picturesC.size());
Picture pic = (Picture)picturesC.get(0); Picture pic = picturesC.get(0);
assertNotNull(pic); assertNotNull(pic);
// Check the same // Check the same
@ -134,11 +134,11 @@ public final class TestHWPFPictures extends TestCase {
*/ */
public void BROKENtestEscherDrawing() { public void BROKENtestEscherDrawing() {
HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile); HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
List allPictures = docD.getPicturesTable().getAllPictures(); List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
assertEquals(1, allPictures.size()); assertEquals(1, allPictures.size());
Picture pic = (Picture) allPictures.get(0); Picture pic = allPictures.get(0);
assertNotNull(pic); assertNotNull(pic);
byte[] picD = readFile(imgDFile); byte[] picD = readFile(imgDFile);