Fix more HSLF generics warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1024390 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-10-19 20:12:19 +00:00
parent de0dcda820
commit 77e11df1be
10 changed files with 56 additions and 61 deletions

View File

@ -43,14 +43,14 @@ public class ExObjList extends RecordContainer {
* Returns all the ExHyperlinks * Returns all the ExHyperlinks
*/ */
public ExHyperlink[] getExHyperlinks() { public ExHyperlink[] getExHyperlinks() {
ArrayList links = new ArrayList(); ArrayList<ExHyperlink> links = new ArrayList<ExHyperlink>();
for(int i=0; i<_children.length; i++) { for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof ExHyperlink) { 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()]);
} }
/** /**

View File

@ -165,7 +165,7 @@ public class ExOleObjStg extends RecordAtom implements PositionDependentRecord,
myLastOnDiskOffset = offset; myLastOnDiskOffset = offset;
} }
public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) { public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
return; return;
} }

View File

@ -30,8 +30,8 @@ import java.util.*;
*/ */
public final class FontCollection extends RecordContainer { public final class FontCollection extends RecordContainer {
private List fonts; private List<String> fonts;
private byte[] _header; private byte[] _header;
protected FontCollection(byte[] source, int start, int len) { protected FontCollection(byte[] source, int start, int len) {
// Grab the header // Grab the header
@ -41,7 +41,7 @@ public final class FontCollection extends RecordContainer {
_children = Record.findChildRecords(source,start+8,len-8); _children = Record.findChildRecords(source,start+8,len-8);
// Save font names into <code>List</code> // Save font names into <code>List</code>
fonts = new ArrayList(); fonts = new ArrayList<String>();
for (int i = 0; i < _children.length; i++){ for (int i = 0; i < _children.length; i++){
if(_children[i] instanceof FontEntityAtom) { if(_children[i] instanceof FontEntityAtom) {
FontEntityAtom atom = (FontEntityAtom)_children[i]; FontEntityAtom atom = (FontEntityAtom)_children[i];
@ -123,6 +123,6 @@ public final class FontCollection extends RecordContainer {
// No font with that id // No font with that id
return null; return null;
} }
return (String)fonts.get(id); return fonts.get(id);
} }
} }

View File

@ -63,8 +63,8 @@ public final class MainMaster extends SheetContainer {
// Find our children // Find our children
_children = Record.findChildRecords(source,start+8,len-8); _children = Record.findChildRecords(source,start+8,len-8);
ArrayList tx = new ArrayList(); ArrayList<TxMasterStyleAtom> tx = new ArrayList<TxMasterStyleAtom>();
ArrayList clr = new ArrayList(); ArrayList<ColorSchemeAtom> clr = new ArrayList<ColorSchemeAtom>();
// Find the interesting ones in there // Find the interesting ones in there
for(int i=0; i<_children.length; i++) { for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlideAtom) { if(_children[i] instanceof SlideAtom) {
@ -72,9 +72,9 @@ public final class MainMaster extends SheetContainer {
} else if(_children[i] instanceof PPDrawing) { } else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i]; ppDrawing = (PPDrawing)_children[i];
} else if(_children[i] instanceof TxMasterStyleAtom) { } else if(_children[i] instanceof TxMasterStyleAtom) {
tx.add(_children[i]); tx.add( (TxMasterStyleAtom)_children[i] );
} else if(_children[i] instanceof ColorSchemeAtom) { } else if(_children[i] instanceof ColorSchemeAtom) {
clr.add(_children[i]); clr.add( (ColorSchemeAtom)_children[i] );
} }
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) { 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()]); txmasters = tx.toArray(new TxMasterStyleAtom[tx.size()]);
clrscheme = (ColorSchemeAtom[])clr.toArray(new ColorSchemeAtom[clr.size()]); clrscheme = clr.toArray(new ColorSchemeAtom[clr.size()]);
} }
/** /**

View 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. * Since we're a container, we don't mind if other records move about.
* If we're told they have, just return straight off. * If we're told they have, just return straight off.
*/ */
public void updateOtherRecordReferences(Hashtable oldToNewReferencesLookup) { public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
return; return;
} }
} }

View File

@ -19,11 +19,13 @@ package org.apache.poi.hslf.record;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Vector; import java.util.ArrayList;
import org.apache.poi.util.LittleEndian; import java.util.List;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* This abstract class represents a record in the PowerPoint document. * 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 * Default method for finding child records of a container record
*/ */
public static Record[] findChildRecords(byte[] b, int start, int len) { 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 // Jump our little way along, creating records as we go
int pos = start; int pos = start;
@ -134,10 +136,7 @@ public abstract class Record
} }
// Turn the vector into an array, and return // Turn the vector into an array, and return
Record[] cRecords = new Record[children.size()]; Record[] cRecords = children.toArray( new Record[children.size()] );
for(int i=0; i < children.size(); i++) {
cRecords[i] = (Record)children.get(i);
}
return cRecords; return cRecords;
} }
@ -165,7 +164,7 @@ public abstract class Record
// A spot of reflection gets us the (byte[],int,int) constructor // A spot of reflection gets us the (byte[],int,int) constructor
// From there, we instanciate the class // From there, we instanciate the class
// Any special record handling occurs once we have the class // Any special record handling occurs once we have the class
Class c = null; Class<? extends Record> c = null;
try { try {
c = RecordTypes.recordHandlingClass((int)type); c = RecordTypes.recordHandlingClass((int)type);
if(c == null) { if(c == null) {
@ -177,9 +176,9 @@ public abstract class Record
} }
// Grab the right constructor // 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 // 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) { } catch(InstantiationException ie) {
throw new RuntimeException("Couldn't instantiate the class for type with id " + type + " on class " + c + " : " + ie, 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) { } catch(java.lang.reflect.InvocationTargetException ite) {

View File

@ -31,8 +31,8 @@ import java.lang.reflect.Field;
* @author Nick Burch * @author Nick Burch
*/ */
public final class RecordTypes { public final class RecordTypes {
public static HashMap typeToName; public static HashMap<Integer,String> typeToName;
public static HashMap typeToClass; public static HashMap<Integer,Class<? extends Record>> typeToClass;
public static final Type Unknown = new Type(0,null); public static final Type Unknown = new Type(0,null);
public static final Type Document = new Type(1000,Document.class); public static final Type Document = new Type(1000,Document.class);
@ -217,7 +217,7 @@ public final class RecordTypes {
* @return name of the record * @return name of the record
*/ */
public static String recordName(int type) { 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; if (name == null) name = "Unknown" + type;
return name; return name;
} }
@ -231,33 +231,33 @@ public final class RecordTypes {
* @param type section of the record header * @param type section of the record header
* @return class to handle the record, or null if an unknown (eg Escher) record * @return class to handle the record, or null if an unknown (eg Escher) record
*/ */
public static Class recordHandlingClass(int type) { public static Class<? extends Record> recordHandlingClass(int type) {
Class c = (Class)typeToClass.get(Integer.valueOf(type)); Class<? extends Record> c = typeToClass.get(Integer.valueOf(type));
return c; return c;
} }
static { static {
typeToName = new HashMap(); typeToName = new HashMap<Integer,String>();
typeToClass = new HashMap(); typeToClass = new HashMap<Integer,Class<? extends Record>>();
try { try {
Field[] f = RecordTypes.class.getFields(); Field[] f = RecordTypes.class.getFields();
for (int i = 0; i < f.length; i++){ 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 // Escher record, only store ID -> Name
if (val instanceof Integer) { if (val instanceof Integer) {
typeToName.put(val, f[i].getName()); typeToName.put((Integer)val, f[i].getName());
} }
// PowerPoint record, store ID -> Name and ID -> Class // PowerPoint record, store ID -> Name and ID -> Class
if (val instanceof Type) { if (val instanceof Type) {
Type t = (Type)val; Type t = (Type)val;
Class c = t.handlingClass; Class<? extends Record> c = t.handlingClass;
Integer id = Integer.valueOf(t.typeID); Integer id = Integer.valueOf(t.typeID);
if(c == null) { c = UnknownRecordPlaceholder.class; } if(c == null) { c = UnknownRecordPlaceholder.class; }
typeToName.put(id, f[i].getName()); typeToName.put(id, f[i].getName());
typeToClass.put(id, c); typeToClass.put(id, c);
} }
} }
} catch (IllegalAccessException e){ } catch (IllegalAccessException e){
throw new RuntimeException("Failed to initialize records types"); throw new RuntimeException("Failed to initialize records types");
@ -272,8 +272,8 @@ public final class RecordTypes {
*/ */
public static class Type { public static class Type {
public int typeID; public int typeID;
public Class handlingClass; public Class<? extends Record> handlingClass;
public Type(int typeID, Class handlingClass) { public Type(int typeID, Class<? extends Record> handlingClass) {
this.typeID = typeID; this.typeID = typeID;
this.handlingClass = handlingClass; this.handlingClass = handlingClass;
} }

View File

@ -82,7 +82,7 @@ public final class SlideListWithText extends RecordContainer {
// Group our children together into SlideAtomsSets // Group our children together into SlideAtomsSets
// That way, model layer code can just grab the sets to use, // That way, model layer code can just grab the sets to use,
// without having to try to match the children together // 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++) { for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlidePersistAtom) { if(_children[i] instanceof SlidePersistAtom) {
// Find where the next SlidePersistAtom is // Find where the next SlidePersistAtom is
@ -108,10 +108,7 @@ public final class SlideListWithText extends RecordContainer {
} }
// Turn the vector into an array // Turn the vector into an array
slideAtomsSets = new SlideAtomsSet[sets.size()]; slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
for(int i=0; i<slideAtomsSets.length; i++) {
slideAtomsSets[i] = (SlideAtomsSet)sets.get(i);
}
} }
/** /**

View File

@ -115,7 +115,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
} }
public TextSpecInfoRun[] getTextSpecInfoRuns(){ public TextSpecInfoRun[] getTextSpecInfoRuns(){
ArrayList lst = new ArrayList(); ArrayList<TextSpecInfoRun> lst = new ArrayList<TextSpecInfoRun>();
int pos = 0; int pos = 0;
int[] bits = {1, 0, 2}; int[] bits = {1, 0, 2};
while(pos < _data.length) { while(pos < _data.length) {
@ -139,8 +139,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
} }
lst.add(run); lst.add(run);
} }
return (TextSpecInfoRun[])lst.toArray(new TextSpecInfoRun[lst.size()]); return lst.toArray(new TextSpecInfoRun[lst.size()]);
} }
public static class TextSpecInfoRun { public static class TextSpecInfoRun {

View File

@ -121,10 +121,10 @@ public final class UserEditAtom extends PositionDependentRecordAtom
* At write-out time, update the references to PersistPtrs and * At write-out time, update the references to PersistPtrs and
* other UserEditAtoms to point to their new positions * 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 // Look up the new positions of our preceding UserEditAtomOffset
if(lastUserEditAtomOffset != 0) { if(lastUserEditAtomOffset != 0) {
Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset)); Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
if(newLocation == null) { if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the UserEditAtom that used to be at " + lastUserEditAtomOffset); 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 // Ditto for our PersistPtr
Integer newLocation = (Integer)oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset)); Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(persistPointersOffset));
if(newLocation == null) { if(newLocation == null) {
throw new RuntimeException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset); throw new RuntimeException("Couldn't find the new location of the PersistPtr that used to be at " + persistPointersOffset);
} }