From 60622c3590b286934ac6be58f86dac945198f6b8 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 1 Aug 2008 14:39:57 +0000 Subject: [PATCH] Some code hygiene. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@592 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../com/threerings/media/AbstractMedia.java | 6 +-- .../threerings/media/image/ColorPository.java | 43 ++++++++----------- .../media/tile/TileSetRepository.java | 4 +- .../tile/tools/xml/XMLTileSetParser.java | 25 +++++------ 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/java/com/threerings/media/AbstractMedia.java b/src/java/com/threerings/media/AbstractMedia.java index 12d8bfa2..f3d179c5 100644 --- a/src/java/com/threerings/media/AbstractMedia.java +++ b/src/java/com/threerings/media/AbstractMedia.java @@ -212,7 +212,7 @@ public abstract class AbstractMedia * Queues the supplied notification up to be dispatched to this * abstract media's observers. */ - public void queueNotification (ObserverList.ObserverOp amop) + public void queueNotification (ObserverList.ObserverOp amop) { if (_observers != null) { if (_mgr != null) { @@ -330,7 +330,7 @@ public abstract class AbstractMedia protected void addObserver (Object obs) { if (_observers == null) { - _observers = new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY); + _observers = ObserverList.newFastUnsafe(); } _observers.add(obs); } @@ -376,7 +376,7 @@ public abstract class AbstractMedia protected AbstractMediaManager _mgr; /** Our observers. */ - protected ObserverList _observers = null; + protected ObserverList _observers = null; /** The tick stamp associated with our first call to {@link #tick}. * This is set up automatically in {@link #willStart}. */ diff --git a/src/java/com/threerings/media/image/ColorPository.java b/src/java/com/threerings/media/image/ColorPository.java index 560d58d0..c63a64d7 100644 --- a/src/java/com/threerings/media/image/ColorPository.java +++ b/src/java/com/threerings/media/image/ColorPository.java @@ -75,7 +75,7 @@ public class ColorPository implements Serializable public int defaultId; /** A table of target colors included in this class. */ - public HashIntMap colors = new HashIntMap(); + public HashIntMap colors = new HashIntMap(); /** Used when parsing the color definitions. */ public void addColor (ColorRecord record) @@ -114,9 +114,7 @@ public class ColorPository implements Serializable } // Look for name matches among all colors - Iterator iter = colors.values().iterator(); - while (iter.hasNext()) { - ColorRecord color = (ColorRecord)iter.next(); + for (ColorRecord color : colors.values()) { if (color.name.equalsIgnoreCase(name)) { return color.colorId; } @@ -132,16 +130,13 @@ public class ColorPository implements Serializable { // figure out our starter ids if we haven't already if (_starters == null) { - ArrayList list = new ArrayList(); - Iterator iter = colors.values().iterator(); - while (iter.hasNext()) { - ColorRecord color = (ColorRecord)iter.next(); + ArrayList list = new ArrayList(); + for (ColorRecord color : colors.values()) { if (color.starter) { list.add(color); } } - _starters = (ColorRecord[]) - list.toArray(new ColorRecord[list.size()]); + _starters = list.toArray(new ColorRecord[list.size()]); } // sanity check @@ -161,7 +156,7 @@ public class ColorPository implements Serializable */ public ColorRecord getDefault () { - return (ColorRecord) colors.get(defaultId); + return colors.get(defaultId); } @Override @@ -249,7 +244,7 @@ public class ColorPository implements Serializable /** * Returns an iterator over all color classes in this pository. */ - public Iterator enumerateClasses () + public Iterator enumerateClasses () { return _classes.values().iterator(); } @@ -268,9 +263,9 @@ public class ColorPository implements Serializable // create the array ColorRecord[] crecs = new ColorRecord[record.colors.size()]; - Iterator iter = record.colors.values().iterator(); + Iterator iter = record.colors.values().iterator(); for (int i = 0; iter.hasNext(); i++) { - crecs[i] = ((ColorRecord)iter.next()); + crecs[i] = iter.next(); } return crecs; } @@ -288,9 +283,9 @@ public class ColorPository implements Serializable } int[] cids = new int[record.colors.size()]; - Iterator crecs = record.colors.values().iterator(); + Iterator crecs = record.colors.values().iterator(); for (int i = 0; crecs.hasNext(); i++) { - cids[i] = ((ColorRecord)crecs.next()).colorId; + cids[i] = crecs.next().colorId; } return cids; } @@ -340,7 +335,7 @@ public class ColorPository implements Serializable { ClassRecord crec = getClassRecord(className); if (crec != null) { - ColorRecord color = (ColorRecord)crec.colors.get(colorId); + ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } @@ -363,7 +358,7 @@ public class ColorPository implements Serializable return null; } - ColorRecord color = (ColorRecord)crec.colors.get(colorId); + ColorRecord color = crec.colors.get(colorId); if (color != null) { return color.getColorization(); } @@ -377,9 +372,9 @@ public class ColorPository implements Serializable */ public ClassRecord getClassRecord (String className) { - Iterator iter = _classes.values().iterator(); + Iterator iter = _classes.values().iterator(); while (iter.hasNext()) { - ClassRecord crec = (ClassRecord)iter.next(); + ClassRecord crec = iter.next(); if (crec.name.equals(className)) { return crec; } @@ -394,7 +389,7 @@ public class ColorPository implements Serializable */ public ColorRecord getColorRecord (int classId, int colorId) { - ClassRecord record = (ClassRecord)_classes.get(classId); + ClassRecord record = _classes.get(classId); if (record == null) { // if they request color class zero, we assume they're just // decoding a blank colorprint, otherwise we complain @@ -406,7 +401,7 @@ public class ColorPository implements Serializable } return null; } - return (ColorRecord)record.colors.get(colorId); + return record.colors.get(colorId); } /** @@ -430,7 +425,7 @@ public class ColorPository implements Serializable return null; } - return (ColorRecord)record.colors.get(colorId); + return record.colors.get(colorId); } /** @@ -491,7 +486,7 @@ public class ColorPository implements Serializable } /** Our mapping from class names to class records. */ - protected HashIntMap _classes = new HashIntMap(); + protected HashIntMap _classes = new HashIntMap(); /** Increase this value when object's serialized state is impacted by * a class change (modification of fields, inheritance). */ diff --git a/src/java/com/threerings/media/tile/TileSetRepository.java b/src/java/com/threerings/media/tile/TileSetRepository.java index f1e22e40..8f30c95a 100644 --- a/src/java/com/threerings/media/tile/TileSetRepository.java +++ b/src/java/com/threerings/media/tile/TileSetRepository.java @@ -37,13 +37,13 @@ public interface TileSetRepository * Returns an iterator over the identifiers of all {@link TileSet} * objects available. */ - public Iterator enumerateTileSetIds () + public Iterator enumerateTileSetIds () throws PersistenceException; /** * Returns an iterator over all {@link TileSet} objects available. */ - public Iterator enumerateTileSets () + public Iterator enumerateTileSets () throws PersistenceException; /** diff --git a/src/java/com/threerings/media/tile/tools/xml/XMLTileSetParser.java b/src/java/com/threerings/media/tile/tools/xml/XMLTileSetParser.java index e369bde3..e01a404f 100644 --- a/src/java/com/threerings/media/tile/tools/xml/XMLTileSetParser.java +++ b/src/java/com/threerings/media/tile/tools/xml/XMLTileSetParser.java @@ -27,7 +27,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.commons.digester.Digester; import org.xml.sax.SAXException; @@ -83,16 +84,16 @@ public class XMLTileSetParser /** * Loads all of the tilesets specified in the supplied XML tileset - * description file and places them into the supplied hashmap indexed + * description file and places them into the supplied map indexed * by tileset name. This method is not reentrant, so don't go calling * it from multiple threads. * * @param path a path, relative to the classpath, at which the tileset * definition file can be found. - * @param tilesets the hashmap into which the tilesets will be placed, + * @param tilesets the map into which the tilesets will be placed, * indexed by tileset name. */ - public void loadTileSets (String path, HashMap tilesets) + public void loadTileSets (String path, Map tilesets) throws IOException { // get an input stream for this XML file @@ -109,16 +110,16 @@ public class XMLTileSetParser /** * Loads all of the tilesets specified in the supplied XML tileset - * description file and places them into the supplied hashmap indexed + * description file and places them into the supplied map indexed * by tileset name. This method is not reentrant, so don't go calling * it from multiple threads. * * @param file the file in which the tileset definition file can be * found. - * @param tilesets the hashmap into which the tilesets will be placed, + * @param tilesets the map into which the tilesets will be placed, * indexed by tileset name. */ - public void loadTileSets (File file, HashMap tilesets) + public void loadTileSets (File file, Map tilesets) throws IOException { // load up the tilesets @@ -127,21 +128,21 @@ public class XMLTileSetParser /** * Loads all of the tilesets specified in the supplied XML tileset - * description file and places them into the supplied hashmap indexed + * description file and places them into the supplied map indexed * by tileset name. This method is not reentrant, so don't go calling * it from multiple threads. * * @param source an input stream from which the tileset definition * file can be read. - * @param tilesets the hashmap into which the tilesets will be placed, + * @param tilesets the map into which the tilesets will be placed, * indexed by tileset name. */ - public void loadTileSets (InputStream source, HashMap tilesets) + public void loadTileSets (InputStream source, Map tilesets) throws IOException { // stick an array list on the top of the stack for collecting // parsed tilesets - ArrayList setlist = new ArrayList(); + List setlist = new ArrayList(); _digester.push(setlist); // now fire up the digester to parse the stream @@ -153,7 +154,7 @@ public class XMLTileSetParser // stick the tilesets from the list into the hashtable for (int i = 0; i < setlist.size(); i++) { - TileSet set = (TileSet)setlist.get(i); + TileSet set = setlist.get(i); if (set.getName() == null) { log.warning("Tileset did not receive name during " + "parsing process [set=" + set + "].");