From 77e11df1bee3fa49c71376b1955a59e7b19b36a0 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 19 Oct 2010 20:12:19 +0000 Subject: [PATCH] Fix more HSLF generics warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1024390 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/record/ExObjList.java | 6 +-- .../apache/poi/hslf/record/ExOleObjStg.java | 2 +- .../poi/hslf/record/FontCollection.java | 8 ++-- .../apache/poi/hslf/record/MainMaster.java | 12 ++--- .../PositionDependentRecordContainer.java | 2 +- .../org/apache/poi/hslf/record/Record.java | 21 ++++----- .../apache/poi/hslf/record/RecordTypes.java | 46 +++++++++---------- .../poi/hslf/record/SlideListWithText.java | 7 +-- .../poi/hslf/record/TextSpecInfoAtom.java | 5 +- .../apache/poi/hslf/record/UserEditAtom.java | 6 +-- 10 files changed, 55 insertions(+), 60 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java index a511ef6095..6c40ecf180 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java @@ -43,14 +43,14 @@ public class ExObjList extends RecordContainer { * Returns all the ExHyperlinks */ public ExHyperlink[] getExHyperlinks() { - ArrayList links = new ArrayList(); + ArrayList links = new ArrayList(); 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()]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java index 36fbebf4c4..4fee85ead1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java @@ -165,7 +165,7 @@ public class ExOleObjStg extends RecordAtom implements PositionDependentRecord, myLastOnDiskOffset = offset; } - public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) { + public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) { return; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java index be6cdde42c..0f7f05148b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java @@ -30,8 +30,8 @@ import java.util.*; */ public final class FontCollection extends RecordContainer { - private List fonts; - private byte[] _header; + private List 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 List - fonts = new ArrayList(); + fonts = new ArrayList(); 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); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java index 4424e2db75..eb1dade780 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java @@ -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 tx = new ArrayList(); + ArrayList clr = new ArrayList(); // 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()]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java index 652c6d860e..a297f302b6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PositionDependentRecordContainer.java @@ -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 oldToNewReferencesLookup) { return; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index d6280cb0f9..09126999e5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -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 children = new ArrayList(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 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 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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index 68ebf98a31..0920b14384 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -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 typeToName; + public static HashMap> 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 recordHandlingClass(int type) { + Class c = typeToClass.get(Integer.valueOf(type)); return c; } static { - typeToName = new HashMap(); - typeToClass = new HashMap(); + typeToName = new HashMap(); + typeToClass = new HashMap>(); 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 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 handlingClass; + public Type(int typeID, Class handlingClass) { this.typeID = typeID; this.handlingClass = handlingClass; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index 45fbd72479..bb417a6dde 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -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 sets = new Vector(); 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 lst = new ArrayList(); 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 { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java index 971fbf4c6a..0a2c8a03ba 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java @@ -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 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); } -- 2.39.5