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,8 +24,10 @@ package com.threerings.media;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import com.google.common.collect.Lists;
import com.samskivert.util.SortableArrayList;
import com.samskivert.util.ObserverList.ObserverOp;
@@ -265,9 +267,9 @@ public abstract class AbstractMediaManager
/**
* Queues the notification for dispatching after we've ticked all the media.
*/
public void queueNotification (ObserverList observers, ObserverOp event)
public void queueNotification (ObserverList<Object> observers, ObserverOp<Object> event)
{
_notify.add(new Tuple<ObserverList,ObserverOp>(observers, event));
_notify.add(new Tuple<ObserverList<Object>,ObserverOp<Object>>(observers, event));
}
/** Type safety jockeying. */
@@ -279,7 +281,7 @@ public abstract class AbstractMediaManager
protected void dispatchNotifications ()
{
for (int ii = 0, nn = _notify.size(); ii < nn; ii++) {
Tuple<ObserverList,ObserverOp> tuple = _notify.get(ii);
Tuple<ObserverList<Object>,ObserverOp<Object>> tuple = _notify.get(ii);
tuple.left.apply(tuple.right);
}
_notify.clear();
@@ -299,8 +301,7 @@ public abstract class AbstractMediaManager
protected RegionManager _remgr;
/** List of observers to notify at the end of the tick. */
protected ArrayList<Tuple<ObserverList,ObserverOp>> _notify =
new ArrayList<Tuple<ObserverList,ObserverOp>>();
protected List<Tuple<ObserverList<Object>,ObserverOp<Object>>> _notify = Lists.newArrayList();
/** Our render-order sorted list of media. */
@SuppressWarnings("unchecked") protected SortableArrayList<AbstractMedia> _media =
@@ -22,6 +22,7 @@
package com.threerings.media;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import javax.swing.Icon;
@@ -110,7 +111,7 @@ public class IconManager
{
try {
// see if the tileset is already loaded
TileSet set = (TileSet)_icons.get(iconSet);
TileSet set = _icons.get(iconSet);
// load it up if not
if (set == null) {
@@ -166,7 +167,7 @@ public class IconManager
protected String _rsrcSet;
/** A cache of our icon tilesets. */
protected LRUHashMap _icons = new LRUHashMap(ICON_CACHE_SIZE);
protected Map<String, TileSet> _icons = new LRUHashMap<String, TileSet>(ICON_CACHE_SIZE);
/** The suffix we append to an icon set name to obtain the tileset
* image path configuration parameter. */
@@ -645,7 +645,7 @@ public class MediaPanel extends JComponent
*/
protected Sprite getHit (MouseEvent me)
{
ArrayList list = new ArrayList();
ArrayList<Sprite> list = new ArrayList<Sprite>();
getSpriteManager().getHitSprites(list, me.getX(), me.getY());
for (int ii = 0, nn = list.size(); ii < nn; ii++) {
Object o = list.get(ii);
@@ -299,7 +299,7 @@ public class VirtualMediaPanel extends MediaPanel
{
// inform our view trackers
for (int ii = 0, ll = _trackers.size(); ii < ll; ii++) {
((ViewTracker)_trackers.get(ii)).viewLocationDidChange(dx, dy);
_trackers.get(ii).viewLocationDidChange(dx, dy);
}
// pass the word on to our sprite/anim managers via the meta manager
@@ -459,5 +459,5 @@ public class VirtualMediaPanel extends MediaPanel
protected Rectangle _abounds = new Rectangle();
/** A list of entities to be informed when the view scrolls. */
protected ArrayList _trackers = new ArrayList();
protected ArrayList<ViewTracker> _trackers = new ArrayList<ViewTracker>();
}
@@ -123,7 +123,7 @@ public abstract class Animation extends AbstractMedia
protected boolean _finished = false;
/** Used to dispatch {@link AnimationObserver#animationStarted}. */
protected static class AnimStartedOp implements ObserverList.ObserverOp
protected static class AnimStartedOp implements ObserverList.ObserverOp<Object>
{
public AnimStartedOp (Animation anim, long when) {
_anim = anim;
@@ -140,7 +140,7 @@ public abstract class Animation extends AbstractMedia
}
/** Used to dispatch {@link AnimationObserver#animationCompleted}. */
protected static class AnimCompletedOp implements ObserverList.ObserverOp
protected static class AnimCompletedOp implements ObserverList.ObserverOp<Object>
{
public AnimCompletedOp (Animation anim, long when) {
_anim = anim;
@@ -42,7 +42,8 @@ public class AnimationArranger
public void positionAvoidAnimation (Animation anim, Rectangle viewBounds)
{
Rectangle abounds = new Rectangle(anim.getBounds());
ArrayList avoidables = (ArrayList) _avoidAnims.clone();
@SuppressWarnings("unchecked") ArrayList<Animation> avoidables =
(ArrayList<Animation>) _avoidAnims.clone();
// if we are able to place it somewhere, do so
if (SwingUtil.positionRect(abounds, viewBounds, avoidables)) {
anim.setLocation(abounds.x, abounds.y);
@@ -55,7 +56,7 @@ public class AnimationArranger
}
/** The animations that other animations may wish to avoid. */
protected ArrayList _avoidAnims = new ArrayList();
protected ArrayList<Animation> _avoidAnims = new ArrayList<Animation>();
/** Automatically removes avoid animations when they're done. */
protected AnimationAdapter _avoidAnimObs = new AnimationAdapter() {
@@ -234,7 +234,7 @@ public interface AnimationFrameSequencer extends FrameSequencer
protected Animation _animation;
/** Used to dispatch {@link SequencedAnimationObserver#frameReached}. */
protected static class FrameReachedOp implements ObserverList.ObserverOp
protected static class FrameReachedOp implements ObserverList.ObserverOp<Object>
{
public FrameReachedOp (Animation anim, long when,
int frameIdx, int frameSeq) {
@@ -89,11 +89,11 @@ public class AnimationSequencer extends Animation
if (_queued.size() > 0) {
// if there are queued animations we want the most
// recently queued animation
trigger = (AnimRecord)_queued.get(_queued.size()-1);
trigger = _queued.get(_queued.size()-1);
} else if (_running.size() > 0) {
// otherwise, if there are running animations, we want the
// last one in that list
trigger = (AnimRecord)_running.get(_running.size()-1);
trigger = _running.get(_running.size()-1);
}
// otherwise we have no trigger, we'll just start ASAP
}
@@ -122,7 +122,7 @@ public class AnimationSequencer extends Animation
// add all animations whose time has come
while (_queued.size() > 0) {
AnimRecord arec = (AnimRecord)_queued.get(0);
AnimRecord arec = _queued.get(0);
if (!arec.readyToFire(tickStamp, _lastStamp)) {
// if it's not time to add this animation, all subsequent
// animations must surely wait as well
@@ -284,10 +284,10 @@ public class AnimationSequencer extends Animation
protected AnimationManager _animmgr;
/** Animations that have not been fired. */
protected ArrayList _queued = new ArrayList();
protected ArrayList<AnimRecord> _queued = new ArrayList<AnimRecord>();
/** Animations that are currently running. */
protected ArrayList _running = new ArrayList();
protected ArrayList<AnimRecord> _running = new ArrayList<AnimRecord>();
/** The timestamp at which we fired the last animation. */
protected long _lastStamp;
@@ -13,9 +13,11 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Maps;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil;
@@ -97,9 +99,10 @@ public class ImageManager
// create our image cache
int icsize = getCacheSize();
log.debug("Creating image cache [size=" + icsize + "k].");
_ccache = new LRUHashMap(icsize * 1024, new LRUHashMap.ItemSizer() {
public int computeSize (Object value) {
return (int)((CacheRecord)value).getEstimatedMemoryUsage();
_ccache = new LRUHashMap<ImageKey, CacheRecord>(
icsize * 1024, new LRUHashMap.ItemSizer<CacheRecord>() {
public int computeSize (CacheRecord value) {
return (int)value.getEstimatedMemoryUsage();
}
});
_ccache.setTracking(true);
@@ -257,7 +260,7 @@ public class ImageManager
{
CacheRecord crec = null;
synchronized (_ccache) {
crec = (CacheRecord)_ccache.get(key);
crec = _ccache.get(key);
}
if (crec != null) {
// Log.info("Cache hit [key=" + key + ", crec=" + crec + "].");
@@ -360,7 +363,7 @@ public class ImageManager
return _defaultProvider;
}
ImageDataProvider dprov = (ImageDataProvider)_providers.get(rset);
ImageDataProvider dprov = _providers.get(rset);
if (dprov == null) {
dprov = new ImageDataProvider() {
public BufferedImage loadImage (String path)
@@ -427,9 +430,9 @@ public class ImageManager
int[] eff = null;
synchronized (_ccache) {
Iterator iter = _ccache.values().iterator();
Iterator<CacheRecord> iter = _ccache.values().iterator();
while (iter.hasNext()) {
size += ((CacheRecord)iter.next()).getEstimatedMemoryUsage();
size += iter.next().getEstimatedMemoryUsage();
}
eff = _ccache.getTrackedEffectiveness();
}
@@ -446,7 +449,7 @@ public class ImageManager
_source = source;
}
public BufferedImage getImage (Colorization[] zations, LRUHashMap cache)
public BufferedImage getImage (Colorization[] zations, LRUHashMap<ImageKey, CacheRecord> cache)
{
if (zations == null) {
return _source;
@@ -513,10 +516,10 @@ public class ImageManager
protected OptimalImageCreator _icreator;
/** A cache of loaded images. */
protected LRUHashMap _ccache;
protected LRUHashMap<ImageKey, CacheRecord> _ccache;
/** The set of all keys we've ever seen. */
protected HashSet _keySet = new HashSet();
protected HashSet<ImageKey> _keySet = new HashSet<ImageKey>();
/** Throttle our cache status logging to once every 300 seconds. */
protected Throttle _cacheStatThrottle = new Throttle(1, 300000L);
@@ -532,7 +535,7 @@ public class ImageManager
};
/** Data providers for different resource sets. */
protected HashMap _providers = new HashMap();
protected Map<String, ImageDataProvider> _providers = Maps.newHashMap();
/** Default amount of data we'll store in our image cache. */
protected static int DEFAULT_CACHE_SIZE = 32768;
@@ -602,11 +602,11 @@ public class ImageUtil
* Returns the estimated memory usage in bytes for all buffered images
* in the supplied iterator.
*/
public static long getEstimatedMemoryUsage (Iterator iter)
public static long getEstimatedMemoryUsage (Iterator<BufferedImage> iter)
{
long size = 0;
while (iter.hasNext()) {
BufferedImage image = (BufferedImage)iter.next();
BufferedImage image = iter.next();
size += getEstimatedMemoryUsage(image);
}
return size;
@@ -42,7 +42,7 @@ public class DumpColorPository
try {
ColorPository pos = ColorPository.loadColorPository(
new FileInputStream(args[0]));
Iterator iter = pos.enumerateClasses();
Iterator<ColorPository.ClassRecord> iter = pos.enumerateClasses();
while (iter.hasNext()) {
System.out.println(iter.next());
}
@@ -195,7 +195,7 @@ public class MusicManager
}
String music = names[RandomUtil.getInt(names.length)];
Class playerClass = getMusicPlayerClass(music);
Class<?> playerClass = getMusicPlayerClass(music);
// if we don't have a player for this song, play the next song
if (playerClass == null) {
@@ -246,7 +246,7 @@ public class MusicManager
/**
* Get the appropriate music player for the specified music file.
*/
protected static Class getMusicPlayerClass (String path)
protected static Class<?> getMusicPlayerClass (String path)
{
path = path.toLowerCase();
@@ -42,7 +42,7 @@ public class Sounds
* a <code>sounds.properties</code> file in the
* <code>com.threerings.happy.fun</code> package.
*/
protected static String getPackagePath (Class clazz)
protected static String getPackagePath (Class<?> clazz)
{
return clazz.getPackage().getName().replace('.', '/') + "/";
}
@@ -387,7 +387,7 @@ public abstract class Sprite extends AbstractMedia
}
/** Used to dispatch {@link PathObserver#pathCancelled}. */
protected static class CancelledOp implements ObserverList.ObserverOp
protected static class CancelledOp implements ObserverList.ObserverOp<Object>
{
public CancelledOp (Sprite sprite, Path path) {
_sprite = sprite;
@@ -406,7 +406,7 @@ public abstract class Sprite extends AbstractMedia
}
/** Used to dispatch {@link PathObserver#pathCompleted}. */
protected static class CompletedOp implements ObserverList.ObserverOp
protected static class CompletedOp implements ObserverList.ObserverOp<Object>
{
public CompletedOp (Sprite sprite, Path path, long when) {
_sprite = sprite;
@@ -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;
}
@@ -339,18 +339,16 @@ public class RecolorImage extends JPanel
}
_classList.removeAllItems();
Iterator iter = _colRepo.enumerateClasses();
ArrayList names = new ArrayList();
Iterator<ColorPository.ClassRecord> iter = _colRepo.enumerateClasses();
ArrayList<String> names = new ArrayList<String>();
while (iter.hasNext()) {
String str = ((ColorPository.ClassRecord)iter.next()).name;
String str = iter.next().name;
names.add(str);
}
Collections.sort(names);
iter = names.iterator();
while (iter.hasNext()) {
_classList.addItem(iter.next());
for (String name : names) {
_classList.addItem(name);
}
_classList.setSelectedIndex(0);
@@ -408,7 +408,7 @@ public class AStarPathUtil
* A class that represents a single traversable node in the tile array
* along with its current A*-specific search information.
*/
protected static class Node implements Comparable
protected static class Node implements Comparable<Node>
{
/** The node coordinates. */
public int x, y;
@@ -435,9 +435,9 @@ public class AStarPathUtil
id = _nextid++;
}
public int compareTo (Object o)
public int compareTo (Node o)
{
int bf = ((Node)o).f;
int bf = o.f;
// since the set contract is fulfilled using the equality results
// returned here, and we'd like to allow multiple nodes with
@@ -446,7 +446,7 @@ public class AStarPathUtil
// unique node id since it will return a consistent ordering for
// the objects.
if (f == bf) {
return (this == o) ? 0 : (id - ((Node)o).id);
return (this == o) ? 0 : (id - o.id);
}
return f - bf;
@@ -84,7 +84,7 @@ public class LineSegmentPath
* Constructs a line segment path with the specified list of points.
* An arbitrary direction will be assigned to the starting node.
*/
public LineSegmentPath (List points)
public LineSegmentPath (List<Point> points)
{
createPath(points);
}
@@ -331,12 +331,12 @@ public class LineSegmentPath
* its starting position to the given destination coordinates
* following the given list of screen coordinates.
*/
protected void createPath (List points)
protected void createPath (List<Point> points)
{
Point last = null;
int size = points.size();
for (int ii = 0; ii < size; ii++) {
Point p = (Point)points.get(ii);
Point p = points.get(ii);
int dir = (ii == 0) ? NORTH : DirectionUtil.getDirection(last, p);
addNode(p.x, p.y, dir);
@@ -349,14 +349,14 @@ public class LineSegmentPath
*/
protected PathNode getNextNode ()
{
return (PathNode)_niter.next();
return _niter.next();
}
/** The nodes that make up the path. */
protected ArrayList<PathNode> _nodes = new ArrayList<PathNode>();
/** We use this when moving along this path. */
protected Iterator _niter;
protected Iterator<PathNode> _niter;
/** When moving, the pathable's source path node. */
protected PathNode _src;
@@ -41,17 +41,14 @@ public class ModeUtil
* desired mode is also used.
*/
public static DisplayMode getDisplayMode (
GraphicsDevice gd, int width, int height,
int desiredDepth, int minimumDepth)
GraphicsDevice gd, int width, int height, int desiredDepth, int minimumDepth)
{
DisplayMode[] modes = gd.getDisplayModes();
final int ddepth = desiredDepth;
// we sort modes in order of desirability
Comparator mcomp = new Comparator () {
public int compare (Object o1, Object o2) {
DisplayMode m1 = (DisplayMode)o1;
DisplayMode m2 = (DisplayMode)o2;
Comparator<DisplayMode> mcomp = new Comparator<DisplayMode>() {
public int compare (DisplayMode m1, DisplayMode m2) {
int bd1 = m1.getBitDepth(), bd2 = m2.getBitDepth();
int rr1 = m1.getRefreshRate(), rr2 = m2.getRefreshRate();
@@ -73,7 +70,7 @@ public class ModeUtil
};
// but we only add modes that meet our minimum requirements
TreeSet mset = new TreeSet(mcomp);
TreeSet<DisplayMode> mset = new TreeSet<DisplayMode>(mcomp);
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth() == width &&
modes[i].getHeight() == height &&
@@ -83,7 +80,7 @@ public class ModeUtil
}
}
return (mset.size() > 0) ? (DisplayMode)mset.first() : null;
return (mset.size() > 0) ? mset.first() : null;
}
/**
@@ -40,7 +40,7 @@ public class PathSequence
*/
public PathSequence (Path first, Path second)
{
this(new ArrayList());
this(new ArrayList<Path>());
_paths.add(first);
_paths.add(second);
}
@@ -50,7 +50,7 @@ public class PathSequence
* Note: Paths may be added to the end of the list while
* the pathable is still traversing earlier paths!
*/
public PathSequence (List paths)
public PathSequence (List<Path> paths)
{
_paths = paths;
}
@@ -119,7 +119,7 @@ public class PathSequence
_pable.pathCompleted(tickStamp);
} else {
_curPath = (Path) _paths.remove(0);
_curPath = _paths.remove(0);
_lastInit = initStamp;
_curPath.init(_pableRep, initStamp);
@@ -128,7 +128,7 @@ public class PathSequence
}
/** The list of paths. */
protected List _paths;
protected List<Path> _paths;
/** The timestamp at which we last inited a path. */
protected long _lastInit;
@@ -22,6 +22,9 @@
package com.threerings.media.util;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Maps;
import com.threerings.media.timer.MediaTimer;
import com.threerings.media.timer.NanoTimer;
@@ -58,10 +61,10 @@ public class PerformanceMonitor
public static void register (PerformanceObserver obs, String name, long delta)
{
// get the observer's action hashtable
HashMap actions = (HashMap)_observers.get(obs);
Map<String, PerformanceAction> actions = _observers.get(obs);
if (actions == null) {
// create it if it didn't exist
_observers.put(obs, actions = new HashMap());
_observers.put(obs, actions = new HashMap<String, PerformanceAction>());
}
// add the action to the set we're tracking
@@ -77,7 +80,7 @@ public class PerformanceMonitor
public static void unregister (PerformanceObserver obs, String name)
{
// get the observer's action hashtable
HashMap actions = (HashMap)_observers.get(obs);
Map<String, PerformanceAction> actions = _observers.get(obs);
if (actions == null) {
log.warning("Attempt to unregister by unknown observer " +
"[observer=" + obs + ", name=" + name + "].");
@@ -85,7 +88,7 @@ public class PerformanceMonitor
}
// attempt to remove the specified action
PerformanceAction action = (PerformanceAction)actions.remove(name);
PerformanceAction action = actions.remove(name);
if (action == null) {
log.warning("Attempt to unregister unknown action " +
"[observer=" + obs + ", name=" + name + "].");
@@ -108,7 +111,7 @@ public class PerformanceMonitor
public static void tick (PerformanceObserver obs, String name)
{
// get the observer's action hashtable
HashMap actions = (HashMap)_observers.get(obs);
Map<String, PerformanceAction> actions = _observers.get(obs);
if (actions == null) {
log.warning("Attempt to tick by unknown observer " +
"[observer=" + obs + ", name=" + name + "].");
@@ -116,7 +119,7 @@ public class PerformanceMonitor
}
// get the specified action
PerformanceAction action = (PerformanceAction)actions.get(name);
PerformanceAction action = actions.get(name);
if (action == null) {
log.warning("Attempt to tick unknown value " +
"[observer=" + obs + ", name=" + name + "].");
@@ -144,7 +147,8 @@ public class PerformanceMonitor
}
/** The observers monitoring some set of actions. */
protected static HashMap _observers = new HashMap();
protected static Map<PerformanceObserver, Map<String, PerformanceAction>> _observers =
Maps.newHashMap();
/** Used to obtain high resolution time stamps. */
protected static MediaTimer _timer = new NanoTimer();