Code hygiene. Not as pedantic as I'd like, but I couldn't resist the huge time

saver that is Eclipse's "Infer generic types" which leaves HashMap and
ArrayList as the declared type where I would normally prefer to change those to
Map and List and use Maps and Lists to instantiate them.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@593 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2008-08-01 15:56:37 +00:00
parent 60622c3590
commit 659f5bc5e2
64 changed files with 393 additions and 388 deletions
@@ -24,6 +24,7 @@ package com.threerings.media.tile;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;
import com.samskivert.util.LRUHashMap;
@@ -42,7 +43,7 @@ public abstract class SimpleCachingImageProvider implements ImageProvider
// documentation inherited from interface
public BufferedImage getTileSetImage (String path, Colorization[] zations)
{
BufferedImage image = (BufferedImage)_cache.get(path);
BufferedImage image = _cache.get(path);
if (image == null) {
try {
image = loadImage(path);
@@ -69,5 +70,5 @@ public abstract class SimpleCachingImageProvider implements ImageProvider
protected abstract BufferedImage loadImage (String path)
throws IOException;
protected LRUHashMap _cache = new LRUHashMap(10);
protected Map<String, BufferedImage> _cache = new LRUHashMap<String, BufferedImage>(10);
}
@@ -25,8 +25,10 @@ import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Maps;
import com.samskivert.util.StringUtil;
import com.samskivert.util.Throttle;
@@ -35,6 +37,8 @@ import com.threerings.media.image.Colorization;
import com.threerings.media.image.Mirage;
import com.threerings.media.image.ImageUtil;
import com.threerings.media.image.BufferedMirage;
import com.threerings.media.tile.Tile.Key;
import static com.threerings.media.Log.log;
/**
@@ -205,9 +209,9 @@ public abstract class TileSet
_key.tileSet = this;
_key.tileIndex = tileIndex;
_key.zations = zations;
SoftReference sref = (SoftReference)_atiles.get(_key);
SoftReference<Tile> sref = _atiles.get(_key);
if (sref != null) {
tile = (Tile)sref.get();
tile = sref.get();
}
}
@@ -217,7 +221,7 @@ public abstract class TileSet
tile.key = new Tile.Key(this, tileIndex, zations);
initTile(tile, tileIndex, zations);
synchronized (_atiles) {
_atiles.put(tile.key, new SoftReference(tile));
_atiles.put(tile.key, new SoftReference<Tile>(tile));
}
}
@@ -372,10 +376,10 @@ public abstract class TileSet
int asize = 0;
synchronized (_atiles) {
// first total up the active tiles
Iterator iter = _atiles.values().iterator();
Iterator<SoftReference<Tile>> iter = _atiles.values().iterator();
while (iter.hasNext()) {
SoftReference sref = (SoftReference)iter.next();
Tile tile = (Tile)sref.get();
SoftReference<Tile> sref = iter.next();
Tile tile = sref.get();
if (tile != null) {
asize++;
amem += tile.getEstimatedMemoryUsage();
@@ -415,7 +419,7 @@ public abstract class TileSet
private static final long serialVersionUID = 1;
/** A map containing weak references to all "active" tiles. */
protected static HashMap _atiles = new HashMap();
protected static Map<Key, SoftReference<Tile>> _atiles = Maps.newHashMap();
/** A key used to look things up in the cache without creating craploads of keys unduly. */
protected static Tile.Key _key = new Tile.Key(null, 0, null);
@@ -26,6 +26,8 @@ import java.util.Iterator;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.IntMap;
import com.threerings.resource.ResourceBundle;
import com.threerings.resource.ResourceManager;
@@ -88,8 +90,8 @@ public class BundledTileSetRepository
return;
}
HashIntMap idmap = new HashIntMap();
HashMap namemap = new HashMap();
HashIntMap<TileSet> idmap = new HashIntMap<TileSet>();
HashMap<String, Integer> namemap = new HashMap<String, Integer>();
// iterate over the resource bundles in the set, loading up the
// tileset bundles in each resource bundle
@@ -118,7 +120,7 @@ public class BundledTileSetRepository
* Extracts the tileset bundle from the supplied resource bundle
* and registers it.
*/
protected void addBundle (HashIntMap idmap, HashMap namemap,
protected void addBundle (HashIntMap<TileSet> idmap, HashMap<String, Integer> namemap,
ResourceBundle bundle)
{
try {
@@ -137,17 +139,16 @@ public class BundledTileSetRepository
* Adds the tilesets in the supplied bundle to our tileset mapping
* tables. Any tilesets with the same name or id will be overwritten.
*/
protected void addBundle (HashIntMap idmap, HashMap namemap,
protected void addBundle (HashIntMap<TileSet> idmap, HashMap<String, Integer> namemap,
TileSetBundle bundle)
{
IMImageProvider improv = (_imgr == null) ?
null : new IMImageProvider(_imgr, bundle);
// map all of the tilesets in this bundle
for (Iterator iter = bundle.entrySet().iterator(); iter.hasNext(); ) {
HashIntMap.Entry entry = (HashIntMap.Entry)iter.next();
Integer tsid = (Integer)entry.getKey();
TileSet tset = (TileSet)entry.getValue();
for (IntMap.IntEntry<TileSet> entry : bundle.intEntrySet()) {
Integer tsid = entry.getKey();
TileSet tset = entry.getValue();
tset.setImageProvider(improv);
idmap.put(tsid.intValue(), tset);
namemap.put(tset.getName(), tsid);
@@ -155,7 +156,7 @@ public class BundledTileSetRepository
}
// documentation inherited from interface
public Iterator enumerateTileSetIds ()
public Iterator<Integer> enumerateTileSetIds ()
throws PersistenceException
{
waitForBundles();
@@ -163,7 +164,7 @@ public class BundledTileSetRepository
}
// documentation inherited from interface
public Iterator enumerateTileSets ()
public Iterator<TileSet> enumerateTileSets ()
throws PersistenceException
{
waitForBundles();
@@ -175,7 +176,7 @@ public class BundledTileSetRepository
throws NoSuchTileSetException, PersistenceException
{
waitForBundles();
TileSet tset = (TileSet)_idmap.get(tileSetId);
TileSet tset = _idmap.get(tileSetId);
if (tset == null) {
throw new NoSuchTileSetException(tileSetId);
}
@@ -187,7 +188,7 @@ public class BundledTileSetRepository
throws NoSuchTileSetException, PersistenceException
{
waitForBundles();
Integer tsid = (Integer)_namemap.get(setName);
Integer tsid = _namemap.get(setName);
if (tsid != null) {
return tsid.intValue();
}
@@ -199,7 +200,7 @@ public class BundledTileSetRepository
throws NoSuchTileSetException, PersistenceException
{
waitForBundles();
Integer tsid = (Integer)_namemap.get(setName);
Integer tsid = _namemap.get(setName);
if (tsid != null) {
return getTileSet(tsid.intValue());
}
@@ -222,8 +223,8 @@ public class BundledTileSetRepository
protected ImageManager _imgr;
/** A mapping from tileset id to tileset. */
protected HashIntMap _idmap;
protected HashIntMap<TileSet> _idmap;
/** A mapping from tileset name to tileset id. */
protected HashMap _namemap;
protected HashMap<String, Integer> _namemap;
}
@@ -40,7 +40,7 @@ import com.threerings.media.tile.TileSet;
* A tileset bundle is used to load up tilesets by id from a persistent bundle of tilesets stored
* on the local filesystem.
*/
public class TileSetBundle extends HashIntMap
public class TileSetBundle extends HashIntMap<TileSet>
implements Serializable, ImageDataProvider
{
/**
@@ -65,13 +65,13 @@ public class TileSetBundle extends HashIntMap
*/
public final TileSet getTileSet (int tileSetId)
{
return (TileSet)get(tileSetId);
return get(tileSetId);
}
/**
* Enumerates the tileset ids in this tileset bundle.
*/
public Iterator enumerateTileSetIds ()
public Iterator<Integer> enumerateTileSetIds ()
{
return keySet().iterator();
}
@@ -79,7 +79,7 @@ public class TileSetBundle extends HashIntMap
/**
* Enumerates the tilesets in this tileset bundle.
*/
public Iterator enumerateTileSets ()
public Iterator<TileSet> enumerateTileSets ()
{
return values().iterator();
}
@@ -103,9 +103,7 @@ public class TileSetBundle extends HashIntMap
{
out.writeInt(size());
Iterator entries = intEntrySet().iterator();
while (entries.hasNext()) {
IntEntry entry = (IntEntry)entries.next();
for (IntEntry<TileSet> entry : intEntrySet()) {
out.writeInt(entry.getIntKey());
out.writeObject(entry.getValue());
}
@@ -66,9 +66,9 @@ public class DirectoryTileSetBundler extends TileSetBundler
try {
// write all of the image files to the bundle's target path, converting the
// tilesets to trimmed tilesets in the process
Iterator iditer = bundle.enumerateTileSetIds();
Iterator<Integer> iditer = bundle.enumerateTileSetIds();
while (iditer.hasNext()) {
int tileSetId = ((Integer)iditer.next()).intValue();
int tileSetId = iditer.next().intValue();
TileSet set = bundle.getTileSet(tileSetId);
String imagePath = set.getImagePath();
@@ -66,9 +66,9 @@ public class DumpBundle
tsb = BundleUtil.extractBundle(file);
}
Iterator tsids = tsb.enumerateTileSetIds();
Iterator<Integer> tsids = tsb.enumerateTileSetIds();
while (tsids.hasNext()) {
Integer tsid = (Integer)tsids.next();
Integer tsid = tsids.next();
TileSet set = tsb.getTileSet(tsid.intValue());
System.out.println(tsid + " => " + set);
if (dumpTiles) {
@@ -132,15 +132,13 @@ public class TileSetBundler
Digester digester = new Digester();
// push our mappings array onto the stack
ArrayList mappings = new ArrayList();
ArrayList<Mapping> mappings = new ArrayList<Mapping>();
digester.push(mappings);
// create a mapping object for each mapping entry and append it to
// our mapping list
digester.addObjectCreate("bundler-config/mapping",
Mapping.class.getName());
digester.addSetNext("bundler-config/mapping",
"add", "java.lang.Object");
digester.addObjectCreate("bundler-config/mapping", Mapping.class.getName());
digester.addSetNext("bundler-config/mapping", "add", "java.lang.Object");
// configure each mapping object with the path and ruleset
digester.addCallMethod("bundler-config/mapping", "init", 2);
@@ -164,7 +162,7 @@ public class TileSetBundler
// use the mappings we parsed to configure our actual digester
int msize = mappings.size();
for (int i = 0; i < msize; i++) {
Mapping map = (Mapping)mappings.get(i);
Mapping map = mappings.get(i);
try {
TileSetRuleSet ruleset = (TileSetRuleSet)Class.forName(map.ruleset).newInstance();
@@ -229,7 +227,7 @@ public class TileSetBundler
{
// stick an array list on the top of the stack into which we will
// collect parsed tilesets
ArrayList sets = new ArrayList();
ArrayList<TileSet> sets = new ArrayList<TileSet>();
_digester.push(sets);
// parse the tilesets
@@ -255,7 +253,7 @@ public class TileSetBundler
// add all of the parsed tilesets to the tileset bundle
try {
for (int i = 0; i < sets.size(); i++) {
TileSet set = (TileSet)sets.get(i);
TileSet set = sets.get(i);
String name = set.getName();
// let's be robust
@@ -363,13 +361,13 @@ public class TileSetBundler
try {
// write all of the image files to the bundle, converting the
// tilesets to trimmed tilesets in the process
Iterator iditer = bundle.enumerateTileSetIds();
Iterator<Integer> iditer = bundle.enumerateTileSetIds();
// Store off the updated TileSets in a separate Map so we can wait to change the
// bundle till we're done iterating.
HashIntMap<TileSet> toUpdate = new HashIntMap<TileSet>();
while (iditer.hasNext()) {
int tileSetId = ((Integer)iditer.next()).intValue();
int tileSetId = iditer.next().intValue();
TileSet set = bundle.getTileSet(tileSetId);
String imagePath = set.getImagePath();
@@ -86,7 +86,7 @@ public class TileSetBundlerTask extends Task
// deal with the filesets
for (int i = 0; i < _filesets.size(); i++) {
FileSet fs = (FileSet)_filesets.get(i);
FileSet fs = _filesets.get(i);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File fromDir = fs.getDir(getProject());
String[] srcFiles = ds.getIncludedFiles();
@@ -157,5 +157,5 @@ public class TileSetBundlerTask extends Task
protected File _mapfile;
/** A list of filesets that contain tileset bundle definitions. */
protected ArrayList _filesets = new ArrayList();
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
}
@@ -39,13 +39,11 @@ public class DumpTileSetMap
}
try {
MapFileTileSetIDBroker broker =
new MapFileTileSetIDBroker(new File(args[0]));
Iterator iter = broker.enumerateMappings();
MapFileTileSetIDBroker broker = new MapFileTileSetIDBroker(new File(args[0]));
Iterator<String> iter = broker.enumerateMappings();
while (iter.hasNext()) {
String tsname = iter.next().toString();
System.out.println(tsname + " => " +
broker.getTileSetID(tsname));
System.out.println(tsname + " => " + broker.getTileSetID(tsname));
}
} catch (PersistenceException pe) {
@@ -60,14 +60,14 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
_nextTileSetID = readInt(bin);
_storedTileSetID = _nextTileSetID;
// read in our mappings
_map = new HashMap();
_map = new HashMap<String, Integer>();
readMapFile(bin, _map);
bin.close();
} catch (FileNotFoundException fnfe) {
// create a blank map if our map file doesn't exist
_map = new HashMap();
_map = new HashMap<String, Integer>();
} catch (Exception e) {
// other errors are more fatal
@@ -91,7 +91,7 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
public int getTileSetID (String tileSetName)
throws PersistenceException
{
Integer tsid = (Integer)_map.get(tileSetName);
Integer tsid = _map.get(tileSetName);
if (tsid == null) {
tsid = Integer.valueOf(++_nextTileSetID);
_map.put(tileSetName, tsid);
@@ -135,7 +135,7 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
* Reads in a mapping from strings to integers, which should have been
* written via {@link #writeMapFile}.
*/
public static void readMapFile (BufferedReader bin, HashMap map)
public static void readMapFile (BufferedReader bin, HashMap<String, Integer> map)
throws IOException
{
String line;
@@ -159,14 +159,14 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
* Writes out a mapping from strings to integers in a manner that can
* be read back in via {@link #readMapFile}.
*/
public static void writeMapFile (BufferedWriter bout, HashMap map)
public static void writeMapFile (BufferedWriter bout, HashMap<String, Integer> map)
throws IOException
{
String[] lines = new String[map.size()];
Iterator iter = map.keySet().iterator();
Iterator<String> iter = map.keySet().iterator();
for (int ii = 0; iter.hasNext(); ii++) {
String key = (String)iter.next();
Integer value = (Integer)map.get(key);
String key = iter.next();
Integer value = map.get(key);
lines[ii] = key + SEP_STR + value;
}
QuickSort.sort(lines);
@@ -184,7 +184,7 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
*/
protected boolean renameTileSet (String oldName, String newName)
{
Integer tsid = (Integer)_map.get(oldName);
Integer tsid = _map.get(oldName);
if (tsid != null) {
_map.put(newName, tsid);
// fudge our stored tileset ID so that we flush ourselves when
@@ -201,7 +201,7 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
* Used by {@link DumpTileSetMap} to enumerate our tileset ID
* mappings.
*/
protected Iterator enumerateMappings ()
protected Iterator<String> enumerateMappings ()
{
return _map.keySet().iterator();
}
@@ -216,7 +216,7 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
protected int _storedTileSetID;
/** Our mapping from tileset names to ids. */
protected HashMap _map;
protected HashMap<String, Integer> _map;
/** The character we use to separate tileset name from code in the map
* file. */
@@ -27,6 +27,7 @@ import com.samskivert.util.StringUtil;
import com.samskivert.xml.CallMethodSpecialRule;
import com.threerings.media.tile.ObjectTileSet;
import com.threerings.media.tile.TileSet;
import com.threerings.util.DirectionUtil;
@@ -191,7 +192,7 @@ public class ObjectTileSetRuleSet extends SwissArmyTileSetRuleSet
}
@Override
protected Class getTileSetClass ()
protected Class<? extends TileSet> getTileSetClass ()
{
return ObjectTileSet.class;
}
@@ -30,6 +30,7 @@ import com.samskivert.util.StringUtil;
import com.samskivert.xml.CallMethodSpecialRule;
import com.threerings.media.tile.SwissArmyTileSet;
import com.threerings.media.tile.TileSet;
import static com.threerings.media.Log.log;
@@ -155,7 +156,7 @@ public class SwissArmyTileSetRuleSet extends TileSetRuleSet
}
@Override
protected Class getTileSetClass ()
protected Class<? extends TileSet> getTileSetClass ()
{
return SwissArmyTileSet.class;
}
@@ -127,7 +127,7 @@ public abstract class TileSetRuleSet
* A tileset rule set will create tilesets of a particular class,
* which must be provided by the derived class via this method.
*/
protected abstract Class getTileSetClass ();
protected abstract Class<? extends TileSet> getTileSetClass ();
/** The tileset path we append to the prefix to get the full path. */
protected String _tilesetPath = TILESET_PATH;
@@ -23,6 +23,7 @@ package com.threerings.media.tile.tools.xml;
import org.apache.commons.digester.Digester;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.UniformTileSet;
import static com.threerings.media.Log.log;
@@ -86,7 +87,7 @@ public class UniformTileSetRuleSet extends TileSetRuleSet
}
@Override
protected Class getTileSetClass ()
protected Class<? extends TileSet> getTileSetClass ()
{
return UniformTileSet.class;
}