poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r995445 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/HWPFDocument.java src/org/apache/poi/hwpf/model/PicturesTable.java testcases/org/apache/poi/hwpf/TestHWPFPictures.java
Date Thu, 09 Sep 2010 14:28:14 GMT
Author: nick
Date: Thu Sep  9 14:28:14 2010
New Revision: 995445

URL: http://svn.apache.org/viewvc?rev=995445&view=rev
Log:
Fix generics warnings

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=995445&r1=995444&r2=995445&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Thu Sep  9 14:28:14
2010
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Iterator;
+import java.util.List;
 
 import org.apache.poi.hwpf.model.CHPBinTable;
 import org.apache.poi.hwpf.model.CPSplitCalculator;
@@ -354,13 +355,13 @@ public final class HWPFDocument extends 
    */
   public int characterLength()
   {
-    java.util.List textPieces = _tpt.getTextPieces();
-    Iterator textIt = textPieces.iterator();
+    List<TextPiece> textPieces = _tpt.getTextPieces();
+    Iterator<TextPiece> textIt = textPieces.iterator();
 
     int length = 0;
     while(textIt.hasNext())
     {
-      TextPiece tp = (TextPiece)textIt.next();
+      TextPiece tp = textIt.next();
       length += tp.characterLength();
     }
     return length;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java?rev=995445&r1=995444&r2=995445&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java Thu Sep  9 14:28:14
2010
@@ -25,7 +25,6 @@ import org.apache.poi.hwpf.usermodel.Ran
 
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Iterator;
 import org.apache.poi.ddf.DefaultEscherRecordFactory;
 import org.apache.poi.ddf.EscherBSERecord;
 import org.apache.poi.ddf.EscherBlipRecord;
@@ -146,42 +145,33 @@ public final class PicturesTable
      * @param escherRecords the escher records.
      * @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();
-        while (recordIter.hasNext())
-        {
-            Object obj = recordIter.next();
-            if (obj instanceof EscherRecord)
-            {
-                EscherRecord escherRecord = (EscherRecord) obj;
-
-                if (escherRecord instanceof EscherBSERecord)
-                {
-                    EscherBSERecord bse = (EscherBSERecord) escherRecord;
-                    EscherBlipRecord blip = bse.getBlipRecord();
-                    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) {
-                            record.fillFields(_mainStream, bse.getOffset(), recordFactory);
-                            blip = (EscherBlipRecord) record;
-                            pictures.add(new Picture(blip.getPicturedata()));
-                        }
-                    }
-                }
-
-                // Recursive call.
-                searchForPictures(escherRecord.getChildRecords(), pictures);
-            }
-        }
+       for(EscherRecord escherRecord : escherRecords) {
+          if (escherRecord instanceof EscherBSERecord) {
+              EscherBSERecord bse = (EscherBSERecord) escherRecord;
+              EscherBlipRecord blip = bse.getBlipRecord();
+              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) {
+                      record.fillFields(_mainStream, bse.getOffset(), recordFactory);
+                      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
    */
-  public List getAllPictures() {
-    ArrayList pictures = new ArrayList();
+  public List<Picture> getAllPictures() {
+    ArrayList<Picture> pictures = new ArrayList<Picture>();
 
     Range range = _document.getOverallRange();
     for (int i = 0; i < range.numCharacterRuns(); i++) {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java?rev=995445&r1=995444&r2=995445&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFPictures.java Thu Sep 
9 14:28:14 2010
@@ -57,8 +57,8 @@ public final class TestHWPFPictures exte
 	 * Test just opening the files
 	 */
 	public void testOpen() {
-		HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
-		HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
+		HWPFTestDataSamples.openSampleFile(docAFile);
+		HWPFTestDataSamples.openSampleFile(docBFile);
 	}
 
 	/**
@@ -74,8 +74,8 @@ public final class TestHWPFPictures exte
 		PicturesTable picA = docA.getPicturesTable();
 		PicturesTable picB = docB.getPicturesTable();
 
-		List picturesA = picA.getAllPictures();
-		List picturesB = picB.getAllPictures();
+		List<Picture> picturesA = picA.getAllPictures();
+		List<Picture> picturesB = picB.getAllPictures();
 
 		assertEquals(7, picturesA.size());
 		assertEquals(2, picturesB.size());
@@ -87,12 +87,12 @@ public final class TestHWPFPictures exte
 	public void testImageData() {
 		HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
 		PicturesTable picB = docB.getPicturesTable();
-		List picturesB = picB.getAllPictures();
+		List<Picture> picturesB = picB.getAllPictures();
 
 		assertEquals(2, picturesB.size());
 
-		Picture pic1 = (Picture)picturesB.get(0);
-		Picture pic2 = (Picture)picturesB.get(1);
+		Picture pic1 = picturesB.get(0);
+		Picture pic2 = picturesB.get(1);
 
 		assertNotNull(pic1);
 		assertNotNull(pic2);
@@ -114,11 +114,11 @@ public final class TestHWPFPictures exte
 	public void testCompressedImageData() {
 		HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
 		PicturesTable picC = docC.getPicturesTable();
-		List picturesC = picC.getAllPictures();
+		List<Picture> picturesC = picC.getAllPictures();
 
 		assertEquals(1, picturesC.size());
 
-		Picture pic = (Picture)picturesC.get(0);
+		Picture pic = picturesC.get(0);
 		assertNotNull(pic);
 
 		// Check the same
@@ -134,11 +134,11 @@ public final class TestHWPFPictures exte
 	 */
 	public void BROKENtestEscherDrawing() {
 		HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
-		List allPictures = docD.getPicturesTable().getAllPictures();
+		List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
 
 		assertEquals(1, allPictures.size());
 
-		Picture pic = (Picture) allPictures.get(0);
+		Picture pic = allPictures.get(0);
 		assertNotNull(pic);
 		byte[] picD = readFile(imgDFile);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message