]> source.dussan.org Git - poi.git/commitdiff
Fix more HSLF generics warnings
authorNick Burch <nick@apache.org>
Tue, 19 Oct 2010 20:12:19 +0000 (20:12 +0000)
committerNick Burch <nick@apache.org>
Tue, 19 Oct 2010 20:12:19 +0000 (20:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1024390 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java
src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java
src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java
src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java
src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java
src/scratchpad/src/org/apache/poi/hslf/record/Record.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java

index a511ef609500f12b6968db55640a78dd9f68efaa..6c40ecf180cb8eace8d71b52bd3aef4349f989fb 100644 (file)
@@ -43,14 +43,14 @@ public class ExObjList extends RecordContainer {
         * Returns all the ExHyperlinks
         */
        public ExHyperlink[] getExHyperlinks() {
-               ArrayList links = new ArrayList();
+               ArrayList<ExHyperlink> links = new ArrayList<ExHyperlink>();
                for(int i=0; i<_children.length; i++) {
                        if(_children[i] instanceof ExHyperlink) {
-                               links.add(_children[i]);
+                               links.add( (ExHyperlink)_children[i] );
                        }
                }
 
-               return (ExHyperlink[])links.toArray(new ExHyperlink[links.size()]);
+               return links.toArray(new ExHyperlink[links.size()]);
        }
 
        /** 
index 36fbebf4c48b320303e012b46d5af20f40ab9b37..4fee85ead1b784c16a97e1d7b76bf910bff82238 100644 (file)
@@ -165,7 +165,7 @@ public class ExOleObjStg extends RecordAtom implements PositionDependentRecord,
         myLastOnDiskOffset = offset;
     }
 
-    public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+    public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
         return;
     }
 
index be6cdde42c20f65b340ce1a2830987dfa0d0598c..0f7f05148b1a034725d8dd5ba5352643b5703078 100644 (file)
@@ -30,8 +30,8 @@ import java.util.*;
  */
 
 public final class FontCollection extends RecordContainer {
-    private List fonts;
-       private byte[] _header;
+    private List<String> fonts;
+    private byte[] _header;
 
        protected FontCollection(byte[] source, int start, int len) {
                // Grab the header
@@ -41,7 +41,7 @@ public final class FontCollection extends RecordContainer {
                _children = Record.findChildRecords(source,start+8,len-8);
 
                // Save font names into <code>List</code>
-               fonts = new ArrayList();
+               fonts = new ArrayList<String>();
                for (int i = 0; i < _children.length; i++){
                        if(_children[i] instanceof FontEntityAtom) {
                    FontEntityAtom atom = (FontEntityAtom)_children[i];
@@ -123,6 +123,6 @@ public final class FontCollection extends RecordContainer {
                        // No font with that id
                        return null;
                }
-               return (String)fonts.get(id);
+               return fonts.get(id);
        }
 }
index 4424e2db75e8c2cb762eaf5941b590287f6d22bc..eb1dade780bc9089dba9dfdeea2f47d615d48d95 100644 (file)
@@ -63,8 +63,8 @@ public final class MainMaster extends SheetContainer {
                // Find our children
                _children = Record.findChildRecords(source,start+8,len-8);
 
-               ArrayList tx = new ArrayList();
-               ArrayList clr = new ArrayList();
+               ArrayList<TxMasterStyleAtom> tx = new ArrayList<TxMasterStyleAtom>();
+               ArrayList<ColorSchemeAtom> clr = new ArrayList<ColorSchemeAtom>();
                // Find the interesting ones in there
                for(int i=0; i<_children.length; i++) {
                        if(_children[i] instanceof SlideAtom) {
@@ -72,9 +72,9 @@ public final class MainMaster extends SheetContainer {
                        } else if(_children[i] instanceof PPDrawing) {
                                ppDrawing = (PPDrawing)_children[i];
                        } else if(_children[i] instanceof TxMasterStyleAtom) {
-                               tx.add(_children[i]);
+                               tx.add( (TxMasterStyleAtom)_children[i] );
                        } else if(_children[i] instanceof ColorSchemeAtom) {
-                               clr.add(_children[i]);
+                               clr.add( (ColorSchemeAtom)_children[i] );
                        }
 
                        if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
@@ -82,8 +82,8 @@ public final class MainMaster extends SheetContainer {
                        }
 
                }
-               txmasters = (TxMasterStyleAtom[])tx.toArray(new TxMasterStyleAtom[tx.size()]);
-               clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]);
+               txmasters = tx.toArray(new TxMasterStyleAtom[tx.size()]);
+               clrscheme = clr.toArray(new ColorSchemeAtom[clr.size()]);
        }
 
        /**
index 652c6d860e35b7d411cbe2c91f8719680a7d65ce..a297f302b69c9116aa69d203b07032c3b08db691 100644 (file)
@@ -60,7 +60,7 @@ public abstract class PositionDependentRecordContainer extends RecordContainer i
         * Since we're a container, we don't mind if other records move about.
         * If we're told they have, just return straight off.
         */
-       public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+       public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
                return;
        }
 }
index d6280cb0f9d468007e080ce14e369ac9118e4dd7..09126999e546475619cb67b0f5b84d415381b8f0 100644 (file)
@@ -19,11 +19,13 @@ 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.hslf.exceptions.CorruptPowerPointFileException;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogger;
 import org.apache.poi.util.POILogFactory;
-import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
+import org.apache.poi.util.POILogger;
 
 /**
  * This abstract class represents a record in the PowerPoint document.
@@ -105,7 +107,7 @@ public abstract class Record
         * Default method for finding child records of a container record
         */
        public static Record[] findChildRecords(byte[] b, int start, int len) {
-               Vector children = new Vector(5);
+               List<Record> children = new ArrayList<Record>(5);
 
                // Jump our little way along, creating records as we go
                int pos = start;
@@ -134,10 +136,7 @@ public abstract class Record
                }
 
                // Turn the vector into an array, and return
-               Record[] cRecords = new Record[children.size()];
-               for(int i=0; i < children.size(); i++) {
-                       cRecords[i] = (Record)children.get(i);
-               }
+               Record[] cRecords = children.toArray( new Record[children.size()] );
                return cRecords;
        }
 
@@ -165,7 +164,7 @@ public abstract class Record
                // A spot of reflection gets us the (byte[],int,int) constructor
                // From there, we instanciate the class
                // Any special record handling occurs once we have the class
-               Class c = null;
+               Class<? extends Record> c = null;
                try {
                        c = RecordTypes.recordHandlingClass((int)type);
                        if(c == null) {
@@ -177,9 +176,9 @@ public abstract class Record
                        }
 
                        // Grab the right constructor
-                       java.lang.reflect.Constructor con = c.getDeclaredConstructor(new Class[] { byte[].class, Integer.TYPE, Integer.TYPE });
+                       java.lang.reflect.Constructor<? extends Record> con = c.getDeclaredConstructor(new Class[] { byte[].class, Integer.TYPE, Integer.TYPE });
                        // Instantiate
-                       toReturn = (Record)(con.newInstance(new Object[] { b, Integer.valueOf(start), Integer.valueOf(len) }));
+                       toReturn = con.newInstance(new Object[] { b, Integer.valueOf(start), Integer.valueOf(len) });
                } catch(InstantiationException ie) {
                        throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, ie);
                } catch(java.lang.reflect.InvocationTargetException ite) {
index 68ebf98a31b463ace8dc9bcd3b3683cc343aa4aa..0920b14384aab117b80c723821ab21e9b83cf247 100644 (file)
@@ -31,8 +31,8 @@ import java.lang.reflect.Field;
  * @author Nick Burch
  */
 public final class RecordTypes {
-    public static HashMap typeToName;
-    public static HashMap typeToClass;
+    public static HashMap<Integer,String> typeToName;
+    public static HashMap<Integer,Class<? extends Record>> typeToClass;
 
     public static final Type Unknown = new Type(0,null);
     public static final Type Document = new Type(1000,Document.class);
@@ -217,7 +217,7 @@ public final class RecordTypes {
      * @return name of the record
      */
     public static String recordName(int type) {
-        String name = (String)typeToName.get(Integer.valueOf(type));
+        String name = typeToName.get(Integer.valueOf(type));
         if (name == null) name = "Unknown" + type;
         return name;
     }
@@ -231,33 +231,33 @@ public final class RecordTypes {
      * @param type section of the record header
      * @return class to handle the record, or null if an unknown (eg Escher) record
      */
-       public static Class recordHandlingClass(int type) {
-               Class c = (Class)typeToClass.get(Integer.valueOf(type));
+       public static Class<? extends Record> recordHandlingClass(int type) {
+               Class<? extends Record> c = typeToClass.get(Integer.valueOf(type));
                return c;
        }
 
     static {
-               typeToName = new HashMap();
-               typeToClass = new HashMap();
+               typeToName = new HashMap<Integer,String>();
+               typeToClass = new HashMap<Integer,Class<? extends Record>>();
         try {
             Field[] f = RecordTypes.class.getFields();
             for (int i = 0; i < f.length; i++){
-                Object val = f[i].get(null);
+               Object val = f[i].get(null);
 
-                               // Escher record, only store ID -> Name
-                if (val instanceof Integer) {
-                    typeToName.put(val, f[i].getName());
-                }
-                               // PowerPoint record, store ID -> Name and ID -> Class
-                               if (val instanceof Type) {
-                                       Type t = (Type)val;
-                                       Class c = t.handlingClass;
-                                       Integer id = Integer.valueOf(t.typeID);
-                                       if(c == null) { c = UnknownRecordPlaceholder.class; }
+               // Escher record, only store ID -> Name
+               if (val instanceof Integer) {
+                  typeToName.put((Integer)val, f[i].getName());
+               }
+               // PowerPoint record, store ID -> Name and ID -> Class
+               if (val instanceof Type) {
+                  Type t = (Type)val;
+                  Class<? extends Record> c = t.handlingClass;
+                  Integer id = Integer.valueOf(t.typeID);
+                  if(c == null) { c = UnknownRecordPlaceholder.class; }
 
-                    typeToName.put(id, f[i].getName());
-                    typeToClass.put(id, c);
-                               }
+                  typeToName.put(id, f[i].getName());
+                  typeToClass.put(id, c);
+               }
             }
         } catch (IllegalAccessException e){
             throw new RuntimeException("Failed to initialize records types");
@@ -272,8 +272,8 @@ public final class RecordTypes {
         */
        public static class Type {
                public int typeID;
-               public Class handlingClass;
-               public Type(int typeID, Class handlingClass) {
+               public Class<? extends Record> handlingClass;
+               public Type(int typeID, Class<? extends Record> handlingClass) {
                        this.typeID = typeID;
                        this.handlingClass = handlingClass;
                }
index 45fbd724793b5450cb1bee2ff1736fdef87cb209..bb417a6dde47a2f84d951bda9b0d395381571183 100644 (file)
@@ -82,7 +82,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 sets = new Vector();
+               Vector<SlideAtomsSet> sets = new Vector<SlideAtomsSet>();
                for(int i=0; i<_children.length; i++) {
                        if(_children[i] instanceof SlidePersistAtom) {
                                // Find where the next SlidePersistAtom is
@@ -108,10 +108,7 @@ public final class SlideListWithText extends RecordContainer {
                }
 
                // Turn the vector into an array
-               slideAtomsSets = new SlideAtomsSet[sets.size()];
-               for(int i=0; i<slideAtomsSets.length; i++) {
-                       slideAtomsSets[i] = (SlideAtomsSet)sets.get(i);
-               }
+               slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
        }
 
        /**
index f0e79761aaa0e7a3637ee9b304c6b42cabd54581..f1452bcf589773ec2866f1c86898578b9a388010 100644 (file)
@@ -115,7 +115,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
     }
 
     public TextSpecInfoRun[] getTextSpecInfoRuns(){
-        ArrayList lst = new ArrayList();
+        ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
         int pos = 0;
         int[] bits = {1, 0, 2};
         while(pos < _data.length) {
@@ -139,8 +139,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
             }
             lst.add(run);
         }
-        return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]);
-
+        return lst.toArray(new TextSpecInfoRun[lst.size()]);
     }
 
     public static class TextSpecInfoRun {
index 971fbf4c6a581c3d6b2c30f6c42a1e1e270a1b7d..0a2c8a03ba65e4c1567695641d8f9091fee67ad8 100644 (file)
@@ -121,10 +121,10 @@ public final class UserEditAtom extends PositionDependentRecordAtom
         * At write-out time, update the references to PersistPtrs and
         *  other UserEditAtoms to point to their new positions
         */
-       public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) {
+       public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
                // Look up the new positions of our preceding UserEditAtomOffset
                if(lastUserEditAtomOffset != 0) {
-                       Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
+                       Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
                        if(newLocation == null) {
                                throw new RuntimeException("Couldn't find the new location of the UserEditAtom that used to be at " + lastUserEditAtomOffset);
                        }
@@ -132,7 +132,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom
                }
 
                // Ditto for our PersistPtr
-               Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
+               Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
                if(newLocation == null) {
                        throw new RuntimeException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset);
                }