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:
@@ -28,12 +28,15 @@ import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.util.IntIntMap;
|
||||
import com.samskivert.util.IntMap;
|
||||
import com.samskivert.util.IntMaps;
|
||||
import com.samskivert.util.Predicate;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
@@ -94,24 +97,30 @@ public class BundledComponentRepository
|
||||
int rcount = (rbundles == null) ? 0 : rbundles.length;
|
||||
for (int i = 0; i < rcount; i++) {
|
||||
if (_actions == null) {
|
||||
_actions = (HashMap)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.ACTIONS_PATH, true);
|
||||
@SuppressWarnings("unchecked") Map<String, ActionSequence> amap =
|
||||
(Map<String, ActionSequence>)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.ACTIONS_PATH, true);
|
||||
_actions = amap;
|
||||
}
|
||||
if (_actionSets == null) {
|
||||
_actionSets = (HashMap)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.ACTION_SETS_PATH, true);
|
||||
@SuppressWarnings("unchecked") Map<String, TileSet> asets =
|
||||
(Map<String, TileSet>)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.ACTION_SETS_PATH, true);
|
||||
_actionSets = asets;
|
||||
}
|
||||
if (_classes == null) {
|
||||
_classes = (HashMap)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.CLASSES_PATH, true);
|
||||
@SuppressWarnings("unchecked") Map<String, ComponentClass> cmap =
|
||||
(Map<String, ComponentClass>)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.CLASSES_PATH, true);
|
||||
_classes = cmap;
|
||||
}
|
||||
}
|
||||
|
||||
// now go back and load up all of the component information
|
||||
for (int i = 0; i < rcount; i++) {
|
||||
HashIntMap comps = null;
|
||||
comps = (HashIntMap)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.COMPONENTS_PATH, true);
|
||||
@SuppressWarnings("unchecked") IntMap<Tuple<String, String>> comps =
|
||||
(IntMap<Tuple<String, String>>)BundleUtil.loadObject(
|
||||
rbundles[i], BundleUtil.COMPONENTS_PATH, true);
|
||||
if (comps == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -120,11 +129,11 @@ public class BundledComponentRepository
|
||||
FrameProvider fprov = new ResourceBundleProvider(_imgr, rbundles[i]);
|
||||
|
||||
// now create char. component instances for each component in the serialized table
|
||||
Iterator iter = comps.keySet().iterator();
|
||||
Iterator<Integer> iter = comps.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
int componentId = ((Integer)iter.next()).intValue();
|
||||
Tuple info = (Tuple)comps.get(componentId);
|
||||
createComponent(componentId, (String)info.left, (String)info.right, fprov);
|
||||
int componentId = iter.next().intValue();
|
||||
Tuple<String, String> info = comps.get(componentId);
|
||||
createComponent(componentId, info.left, info.right, fprov);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,10 +145,10 @@ public class BundledComponentRepository
|
||||
// if we failed to load our classes or actions, create empty hashtables so that we can
|
||||
// safely enumerate our emptiness
|
||||
if (_actions == null) {
|
||||
_actions = new HashMap();
|
||||
_actions = Maps.newHashMap();
|
||||
}
|
||||
if (_classes == null) {
|
||||
_classes = new HashMap();
|
||||
_classes = Maps.newHashMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +167,7 @@ public class BundledComponentRepository
|
||||
public CharacterComponent getComponent (int componentId)
|
||||
throws NoSuchComponentException
|
||||
{
|
||||
CharacterComponent component = (CharacterComponent)_components.get(componentId);
|
||||
CharacterComponent component = _components.get(componentId);
|
||||
if (component == null) {
|
||||
throw new NoSuchComponentException(componentId);
|
||||
}
|
||||
@@ -170,12 +179,12 @@ public class BundledComponentRepository
|
||||
throws NoSuchComponentException
|
||||
{
|
||||
// look up the list for that class
|
||||
ArrayList comps = (ArrayList)_classComps.get(className);
|
||||
ArrayList<CharacterComponent> comps = _classComps.get(className);
|
||||
if (comps != null) {
|
||||
// scan the list for the named component
|
||||
int ccount = comps.size();
|
||||
for (int i = 0; i < ccount; i++) {
|
||||
CharacterComponent comp = (CharacterComponent)comps.get(i);
|
||||
CharacterComponent comp = comps.get(i);
|
||||
if (comp.name.equals(compName)) {
|
||||
return comp;
|
||||
}
|
||||
@@ -187,28 +196,28 @@ public class BundledComponentRepository
|
||||
// documentation inherited
|
||||
public ComponentClass getComponentClass (String className)
|
||||
{
|
||||
return (ComponentClass)_classes.get(className);
|
||||
return _classes.get(className);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Iterator enumerateComponentClasses ()
|
||||
public Iterator<ComponentClass> enumerateComponentClasses ()
|
||||
{
|
||||
return _classes.values().iterator();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Iterator enumerateActionSequences ()
|
||||
public Iterator<ActionSequence> enumerateActionSequences ()
|
||||
{
|
||||
return _actions.values().iterator();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Iterator enumerateComponentIds (final ComponentClass compClass)
|
||||
public Iterator<Integer> enumerateComponentIds (final ComponentClass compClass)
|
||||
{
|
||||
return new Predicate<Integer>() {
|
||||
@Override
|
||||
public boolean isMatch (Integer input) {
|
||||
CharacterComponent comp = (CharacterComponent)_components.get(input);
|
||||
CharacterComponent comp = _components.get(input);
|
||||
return comp.componentClass.equals(compClass);
|
||||
}
|
||||
}.filter(_components.keySet().iterator());
|
||||
@@ -221,7 +230,7 @@ public class BundledComponentRepository
|
||||
int componentId, String cclass, String cname, FrameProvider fprov)
|
||||
{
|
||||
// look up the component class information
|
||||
ComponentClass clazz = (ComponentClass)_classes.get(cclass);
|
||||
ComponentClass clazz = _classes.get(cclass);
|
||||
if (clazz == null) {
|
||||
log.warning("Non-existent component class [class=" + cclass + ", name=" + cname +
|
||||
", id=" + componentId + "].");
|
||||
@@ -235,9 +244,9 @@ public class BundledComponentRepository
|
||||
_components.put(componentId, component);
|
||||
|
||||
// we have a hash of lists for mapping components by class/name
|
||||
ArrayList comps = (ArrayList)_classComps.get(cclass);
|
||||
ArrayList<CharacterComponent> comps = _classComps.get(cclass);
|
||||
if (comps == null) {
|
||||
comps = new ArrayList();
|
||||
comps = new ArrayList<CharacterComponent>();
|
||||
_classComps.put(cclass, comps);
|
||||
}
|
||||
if (!comps.contains(component)) {
|
||||
@@ -280,7 +289,7 @@ public class BundledComponentRepository
|
||||
public ActionFrames getFrames (CharacterComponent component, String action, String type)
|
||||
{
|
||||
// obtain the action sequence definition for this action
|
||||
ActionSequence actseq = (ActionSequence)_actions.get(action);
|
||||
ActionSequence actseq = _actions.get(action);
|
||||
if (actseq == null) {
|
||||
log.warning("Missing action sequence definition [action=" + action +
|
||||
", component=" + component + "].");
|
||||
@@ -300,9 +309,9 @@ public class BundledComponentRepository
|
||||
|
||||
// look to see if this tileset is already cached (as the custom action or the default
|
||||
// action)
|
||||
TileSet aset = (TileSet)_setcache.get(cpath);
|
||||
TileSet aset = _setcache.get(cpath);
|
||||
if (aset == null) {
|
||||
aset = (TileSet)_setcache.get(dpath);
|
||||
aset = _setcache.get(dpath);
|
||||
if (aset != null) {
|
||||
// save ourselves a lookup next time
|
||||
_setcache.put(cpath, aset);
|
||||
@@ -384,7 +393,7 @@ public class BundledComponentRepository
|
||||
protected ResourceBundle _bundle;
|
||||
|
||||
/** Cache of tilesets loaded from our bundle. */
|
||||
protected HashMap _setcache = new HashMap();
|
||||
protected Map<String, TileSet> _setcache = Maps.newHashMap();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -527,19 +536,19 @@ public class BundledComponentRepository
|
||||
protected ImageManager _imgr;
|
||||
|
||||
/** A table of action sequences. */
|
||||
protected HashMap _actions;
|
||||
protected Map<String, ActionSequence> _actions;
|
||||
|
||||
/** A table of action sequence tilesets. */
|
||||
protected HashMap _actionSets;
|
||||
protected Map<String, TileSet> _actionSets;
|
||||
|
||||
/** A table of component classes. */
|
||||
protected HashMap _classes;
|
||||
protected Map<String, ComponentClass> _classes;
|
||||
|
||||
/** A table of component lists indexed on classname. */
|
||||
protected HashMap _classComps = new HashMap();
|
||||
protected Map<String, ArrayList<CharacterComponent>> _classComps = Maps.newHashMap();
|
||||
|
||||
/** The component table. */
|
||||
protected HashIntMap _components = new HashIntMap();
|
||||
protected IntMap<CharacterComponent> _components = IntMaps.newHashIntMap();
|
||||
|
||||
/** Whether or not we wipe our bundles on any failure. */
|
||||
protected boolean _wipeOnFailure;
|
||||
|
||||
@@ -141,14 +141,15 @@ public class ComponentBundlerTask extends Task
|
||||
"definitions via the 'actiondef' attribute.");
|
||||
|
||||
// parse in the action tilesets
|
||||
HashMap actsets = parseActionTileSets();
|
||||
HashMap<String, TileSet> actsets = parseActionTileSets();
|
||||
|
||||
// load up our component ID broker
|
||||
ComponentIDBroker broker = loadBroker(_mapfile);
|
||||
|
||||
// check to see if any of the source files are newer than the
|
||||
// target file
|
||||
ArrayList sources = (ArrayList)_filesets.clone();
|
||||
ArrayList<Object> sources = new ArrayList<Object>();
|
||||
sources.addAll(_filesets);
|
||||
sources.add(_mapfile);
|
||||
sources.add(_actionDef);
|
||||
long newest = getNewestDate(sources);
|
||||
@@ -187,7 +188,7 @@ public class ComponentBundlerTask extends Task
|
||||
String[] info = decomposePath(cfile.getPath());
|
||||
|
||||
// make sure we have an action tileset definition
|
||||
TileSet aset = (TileSet)actsets.get(info[2]);
|
||||
TileSet aset = actsets.get(info[2]);
|
||||
if (aset == null) {
|
||||
System.err.println(
|
||||
"No tileset definition for component action " +
|
||||
@@ -292,7 +293,7 @@ public class ComponentBundlerTask extends Task
|
||||
}
|
||||
}
|
||||
|
||||
protected long getNewestDate (ArrayList sources)
|
||||
protected long getNewestDate (ArrayList<Object> sources)
|
||||
{
|
||||
long newest = 0L;
|
||||
for (int ii = 0; ii < sources.size(); ii++) {
|
||||
@@ -414,7 +415,7 @@ public class ComponentBundlerTask extends Task
|
||||
* Parses the action tileset definitions and puts them into a hash
|
||||
* map, keyed on action name.
|
||||
*/
|
||||
protected HashMap parseActionTileSets ()
|
||||
protected HashMap<String, TileSet> parseActionTileSets ()
|
||||
{
|
||||
Digester digester = new Digester();
|
||||
digester.addSetProperties("actions" + ActionRuleSet.ACTION_PATH);
|
||||
@@ -422,7 +423,7 @@ public class ComponentBundlerTask extends Task
|
||||
addTileSetRuleSet(digester, new UniformTileSetRuleSet("/uniformTileset"));
|
||||
|
||||
|
||||
HashMap actsets = new ActionMap();
|
||||
HashMap<String, TileSet> actsets = new ActionMap();
|
||||
digester.push(actsets);
|
||||
|
||||
try {
|
||||
@@ -484,7 +485,7 @@ public class ComponentBundlerTask extends Task
|
||||
}
|
||||
|
||||
/** Used when parsing action tilesets. */
|
||||
public static class ActionMap extends HashMap
|
||||
public static class ActionMap extends HashMap<String, TileSet>
|
||||
{
|
||||
public void setName (String name) {
|
||||
_name = name;
|
||||
@@ -546,13 +547,13 @@ public class ComponentBundlerTask extends Task
|
||||
}
|
||||
|
||||
protected static class HashMapIDBroker
|
||||
extends HashMap implements ComponentIDBroker
|
||||
extends HashMap<Tuple<String, String>, Integer> implements ComponentIDBroker
|
||||
{
|
||||
public int getComponentID (String cclass, String cname)
|
||||
throws PersistenceException
|
||||
{
|
||||
Tuple key = new Tuple(cclass, cname);
|
||||
Integer cid = (Integer)get(key);
|
||||
Tuple<String, String> key = new Tuple<String, String>(cclass, cname);
|
||||
Integer cid = get(key);
|
||||
if (cid == null) {
|
||||
cid = Integer.valueOf(++_nextCID);
|
||||
put(key, cid);
|
||||
@@ -580,11 +581,11 @@ public class ComponentBundlerTask extends Task
|
||||
bout.newLine();
|
||||
|
||||
// write out the keys and values
|
||||
ComparableArrayList lines = new ComparableArrayList();
|
||||
Iterator keys = keySet().iterator();
|
||||
ComparableArrayList<String> lines = new ComparableArrayList<String>();
|
||||
Iterator<Tuple<String, String>> keys = keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
Tuple key = (Tuple)keys.next();
|
||||
Integer value = (Integer)get(key);
|
||||
Tuple<String, String> key = keys.next();
|
||||
Integer value = get(key);
|
||||
String line = key.left + SEP_STR + key.right + SEP_STR + value;
|
||||
lines.add(line);
|
||||
}
|
||||
@@ -595,7 +596,7 @@ public class ComponentBundlerTask extends Task
|
||||
// now write it to the file
|
||||
int lcount = lines.size();
|
||||
for (int ii = 0; ii < lcount; ii++) {
|
||||
String line = (String)lines.get(ii);
|
||||
String line = lines.get(ii);
|
||||
bout.write(line, 0, line.length());
|
||||
bout.newLine();
|
||||
}
|
||||
@@ -626,7 +627,7 @@ public class ComponentBundlerTask extends Task
|
||||
String cname = line.substring(0, sidx);
|
||||
line = line.substring(sidx + SEP_STR.length());
|
||||
try {
|
||||
put(new Tuple(cclass, cname), Integer.valueOf(line));
|
||||
put(new Tuple<String, String>(cclass, cname), Integer.valueOf(line));
|
||||
} catch (NumberFormatException nfe) {
|
||||
String err = "Malformed line, invalid code '" + orig + "'";
|
||||
throw new IOException(err);
|
||||
|
||||
@@ -23,7 +23,6 @@ package com.threerings.cast.bundle.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.samskivert.util.HashIntMap;
|
||||
@@ -51,19 +50,19 @@ public class DumpBundle
|
||||
try {
|
||||
ResourceBundle bundle = new FileResourceBundle(file);
|
||||
|
||||
HashMap actions = (HashMap)BundleUtil.loadObject(
|
||||
HashMap<?, ?> actions = (HashMap<?, ?>)BundleUtil.loadObject(
|
||||
bundle, BundleUtil.ACTIONS_PATH, false);
|
||||
dumpTable("actions: ", actions);
|
||||
|
||||
HashMap actionSets = (HashMap)BundleUtil.loadObject(
|
||||
HashMap<?, ?> actionSets = (HashMap<?, ?>)BundleUtil.loadObject(
|
||||
bundle, BundleUtil.ACTION_SETS_PATH, false);
|
||||
dumpTable("actionSets: ", actionSets);
|
||||
|
||||
HashMap classes = (HashMap)BundleUtil.loadObject(
|
||||
HashMap<?, ?> classes = (HashMap<?, ?>)BundleUtil.loadObject(
|
||||
bundle, BundleUtil.CLASSES_PATH, false);
|
||||
dumpTable("classes: ", classes);
|
||||
|
||||
HashIntMap comps = (HashIntMap)BundleUtil.loadObject(
|
||||
HashIntMap<?> comps = (HashIntMap<?>)BundleUtil.loadObject(
|
||||
bundle, BundleUtil.COMPONENTS_PATH, false);
|
||||
dumpTable("components: ", comps);
|
||||
|
||||
@@ -75,11 +74,10 @@ public class DumpBundle
|
||||
}
|
||||
}
|
||||
|
||||
protected static void dumpTable (String prefix, Map table)
|
||||
protected static void dumpTable (String prefix, Map<?, ?> table)
|
||||
{
|
||||
if (table != null) {
|
||||
Iterator iter = table.entrySet().iterator();
|
||||
System.out.println(prefix + StringUtil.toString(iter));
|
||||
System.out.println(prefix + StringUtil.toString(table.entrySet().iterator()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.Deflater;
|
||||
@@ -98,10 +99,10 @@ public class MetadataBundlerTask extends Task
|
||||
try {
|
||||
|
||||
// parse our metadata
|
||||
Tuple tuple = parseActions();
|
||||
HashMap actions = (HashMap)tuple.left;
|
||||
HashMap actionSets = (HashMap)tuple.right;
|
||||
HashMap classes = parseClasses();
|
||||
Tuple<Map<String, ActionSequence>, Map<String, TileSet>> tuple = parseActions();
|
||||
Map<String, ActionSequence> actions = tuple.left;
|
||||
Map<String, TileSet> actionSets = tuple.right;
|
||||
Map<String, ComponentClass> classes = parseClasses();
|
||||
|
||||
fout = createOutputStream(_target);
|
||||
|
||||
@@ -174,7 +175,7 @@ public class MetadataBundlerTask extends Task
|
||||
digester.addSetNext(ruleSet.getPath(), "add", Object.class.getName());
|
||||
}
|
||||
|
||||
protected Tuple parseActions ()
|
||||
protected Tuple<Map<String, ActionSequence>, Map<String, TileSet>> parseActions ()
|
||||
throws BuildException
|
||||
{
|
||||
// scan through the XML once to read the actions
|
||||
@@ -183,13 +184,13 @@ public class MetadataBundlerTask extends Task
|
||||
arules.setPrefix("actions");
|
||||
digester.addRuleSet(arules);
|
||||
digester.addSetNext("actions" + ActionRuleSet.ACTION_PATH, "add", Object.class.getName());
|
||||
ArrayList actlist = parseList(digester, _actionDef);
|
||||
ArrayList<?> actlist = parseList(digester, _actionDef);
|
||||
|
||||
// now go through a second time reading the tileset info
|
||||
digester = new Digester();
|
||||
addTileSetRuleSet(digester, new SwissArmyTileSetRuleSet());
|
||||
addTileSetRuleSet(digester, new UniformTileSetRuleSet("/uniformTileset"));
|
||||
ArrayList setlist = parseList(digester, _actionDef);
|
||||
ArrayList<?> setlist = parseList(digester, _actionDef);
|
||||
|
||||
// sanity check
|
||||
if (actlist.size() != setlist.size()) {
|
||||
@@ -199,8 +200,8 @@ public class MetadataBundlerTask extends Task
|
||||
}
|
||||
|
||||
// now create our mappings
|
||||
HashMap actmap = new HashMap();
|
||||
HashMap setmap = new HashMap();
|
||||
Map<String, ActionSequence> actmap = new HashMap<String, ActionSequence>();
|
||||
Map<String, TileSet> setmap = new HashMap<String, TileSet>();
|
||||
|
||||
// create the action map
|
||||
for (int i = 0; i < setlist.size(); i++) {
|
||||
@@ -218,10 +219,10 @@ public class MetadataBundlerTask extends Task
|
||||
setmap.put(act.name, set);
|
||||
}
|
||||
|
||||
return new Tuple(actmap, setmap);
|
||||
return new Tuple<Map<String, ActionSequence>, Map<String, TileSet>>(actmap, setmap);
|
||||
}
|
||||
|
||||
protected HashMap parseClasses ()
|
||||
protected Map<String, ComponentClass> parseClasses ()
|
||||
throws BuildException
|
||||
{
|
||||
// load up our action and class info
|
||||
@@ -234,8 +235,8 @@ public class MetadataBundlerTask extends Task
|
||||
digester.addSetNext("classes" + ClassRuleSet.CLASS_PATH,
|
||||
"add", Object.class.getName());
|
||||
|
||||
ArrayList setlist = parseList(digester, _classDef);
|
||||
HashMap clmap = new HashMap();
|
||||
ArrayList<?> setlist = parseList(digester, _classDef);
|
||||
Map<String, ComponentClass> clmap = new HashMap<String, ComponentClass>();
|
||||
|
||||
// create the action map
|
||||
for (int i = 0; i < setlist.size(); i++) {
|
||||
@@ -246,14 +247,14 @@ public class MetadataBundlerTask extends Task
|
||||
return clmap;
|
||||
}
|
||||
|
||||
protected ArrayList parseList (Digester digester, String path)
|
||||
protected ArrayList<?> parseList (Digester digester, String path)
|
||||
throws BuildException
|
||||
{
|
||||
try {
|
||||
FileInputStream fin = new FileInputStream(path);
|
||||
BufferedInputStream bin = new BufferedInputStream(fin);
|
||||
|
||||
ArrayList setlist = new ArrayList();
|
||||
ArrayList<Object> setlist = new ArrayList<Object>();
|
||||
digester.push(setlist);
|
||||
|
||||
// now fire up the digester to parse the stream
|
||||
|
||||
Reference in New Issue
Block a user