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
@@ -28,6 +28,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Maps;
import com.samskivert.swing.RuntimeAdjust;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil;
@@ -38,6 +40,7 @@ import com.threerings.media.image.ImageManager;
import com.threerings.util.DirectionCodes;
import com.threerings.cast.CompositedActionFrames.ComponentFrames;
import com.threerings.cast.CompositedActionFrames.CompositedFramesKey;
import static com.threerings.cast.Log.log;
@@ -68,18 +71,18 @@ public class CharacterManager
_crepo = crepo;
// populate our actions table
Iterator iter = crepo.enumerateActionSequences();
Iterator<ActionSequence> iter = crepo.enumerateActionSequences();
while (iter.hasNext()) {
ActionSequence action = (ActionSequence)iter.next();
ActionSequence action = iter.next();
_actions.put(action.name, action);
}
// create a cache for our composited action frames
log.debug("Creating action cache [size=" + _runCacheSize + "k].");
_frameCache = new LRUHashMap(_runCacheSize * 1024, new LRUHashMap.ItemSizer() {
public int computeSize (Object value) {
return (int)((CompositedMultiFrameImage)
value).getEstimatedMemoryUsage();
_frameCache = new LRUHashMap<CompositedFramesKey, CompositedMultiFrameImage>(
_runCacheSize * 1024, new LRUHashMap.ItemSizer<CompositedMultiFrameImage>() {
public int computeSize (CompositedMultiFrameImage value) {
return (int)value.getEstimatedMemoryUsage();
}
});
_frameCache.setTracking(true); // TODO
@@ -100,16 +103,8 @@ public class CharacterManager
* @exception IllegalArgumentException thrown if the supplied class
* does not derive from {@link CharacterSprite}.
*/
public void setCharacterClass (Class charClass)
public void setCharacterClass (Class<? extends CharacterSprite> charClass)
{
// sanity check
if (!CharacterSprite.class.isAssignableFrom(charClass)) {
String errmsg = "Requested to use character sprite class that " +
"does not derive from CharacterSprite " +
"[class=" + charClass.getName() + "].";
throw new IllegalArgumentException(errmsg);
}
// make a note of it
_charClass = charClass;
}
@@ -173,8 +168,8 @@ public class CharacterManager
CharacterDescriptor descrip, String action)
throws NoSuchComponentException
{
Tuple key = new Tuple(descrip, action);
ActionFrames frames = (ActionFrames)_actionFrames.get(key);
Tuple<CharacterDescriptor, String> key = new Tuple<CharacterDescriptor, String>(descrip, action);
ActionFrames frames = _actionFrames.get(key);
if (frames == null) {
// this doesn't actually composite the images, but prepares an
// object to be able to do so
@@ -223,7 +218,7 @@ public class CharacterManager
*/
public ActionSequence getActionSequence (String action)
{
return (ActionSequence)_actions.get(action);
return _actions.get(action);
}
/**
@@ -233,10 +228,9 @@ public class CharacterManager
protected long getEstimatedCacheMemoryUsage ()
{
long size = 0;
Iterator iter = _frameCache.values().iterator();
Iterator<CompositedMultiFrameImage> iter = _frameCache.values().iterator();
while (iter.hasNext()) {
size += ((CompositedMultiFrameImage)
iter.next()).getEstimatedMemoryUsage();
size += iter.next().getEstimatedMemoryUsage();
}
return size;
}
@@ -434,17 +428,18 @@ public class CharacterManager
protected ComponentRepository _crepo;
/** A table of our action sequences. */
protected HashMap _actions = new HashMap();
protected Map<String, ActionSequence> _actions = Maps.newHashMap();
/** A table of composited action sequences (these don't reference the
* actual image data directly and thus take up little memory). */
protected HashMap _actionFrames = new HashMap();
protected Map<Tuple<CharacterDescriptor, String>, ActionFrames> _actionFrames =
Maps.newHashMap();
/** A cache of composited animation frames. */
protected LRUHashMap _frameCache;
protected LRUHashMap<CompositedFramesKey, CompositedMultiFrameImage> _frameCache;
/** The character class to be created. */
protected Class<CharacterSprite> _charClass = CharacterSprite.class;
protected Class<? extends CharacterSprite> _charClass = CharacterSprite.class;
/** The action animation cache, if we have one. */
protected ActionCache _acache;
@@ -46,7 +46,7 @@ public class ComponentClass implements Serializable
/** Used to effect custom render orders for particular actions,
* orientations, etc. */
public static class PriorityOverride
implements Comparable, Serializable
implements Comparable<PriorityOverride>, Serializable
{
/** The overridden render priority value. */
public int renderPriority;
@@ -69,11 +69,10 @@ public class ComponentClass implements Serializable
}
// documentation inherited from interface
public int compareTo (Object other)
public int compareTo (PriorityOverride po)
{
// overrides with both an action and an orientation should
// come first in the list
PriorityOverride po = (PriorityOverride)other;
int pri = priority(), opri = po.priority();
if (pri == opri) {
return hashCode() - po.hashCode();
@@ -150,7 +149,7 @@ public class ComponentClass implements Serializable
// closest match
int ocount = (_overrides != null) ? _overrides.size() : 0;
for (int ii = 0; ii < ocount; ii++) {
PriorityOverride over = (PriorityOverride)_overrides.get(ii);
PriorityOverride over = _overrides.get(ii);
// based on the way the overrides are sorted, the first match
// is the most specific and the one we want
if (over.matches(action, orientation)) {
@@ -168,7 +167,7 @@ public class ComponentClass implements Serializable
public void addPriorityOverride (PriorityOverride override)
{
if (_overrides == null) {
_overrides = new ComparableArrayList();
_overrides = new ComparableArrayList<PriorityOverride>();
}
_overrides.insertSorted(override);
}
@@ -235,7 +234,7 @@ public class ComponentClass implements Serializable
}
/** A list of render priority overrides. */
protected ComparableArrayList _overrides;
protected ComparableArrayList<PriorityOverride> _overrides;
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
@@ -55,17 +55,17 @@ public interface ComponentRepository
* Iterates over the {@link ComponentClass} instances representing all
* available character component classes.
*/
public Iterator enumerateComponentClasses ();
public Iterator<ComponentClass> enumerateComponentClasses ();
/**
* Iterates over the {@link ActionSequence} instances representing
* every available action sequence.
*/
public Iterator enumerateActionSequences ();
public Iterator<ActionSequence> enumerateActionSequences ();
/**
* Iterates over the component ids of all components in the specified
* class.
*/
public Iterator enumerateComponentIds (ComponentClass compClass);
public Iterator<Integer> enumerateComponentIds (ComponentClass compClass);
}
@@ -21,7 +21,8 @@
package com.threerings.cast;
import com.samskivert.util.LRUHashMap;
import java.util.Map;
import com.samskivert.util.StringUtil;
import com.threerings.media.image.ImageManager;
@@ -66,8 +67,9 @@ public class CompositedActionFrames
* source frames and colorization configuration. The actual component
* frame images will not be composited until they are requested.
*/
public CompositedActionFrames (ImageManager imgr, LRUHashMap frameCache,
String action, ComponentFrames[] sources)
public CompositedActionFrames (
ImageManager imgr, Map<CompositedFramesKey, CompositedMultiFrameImage> frameCache,
String action, ComponentFrames[] sources)
{
// sanity check
if (sources == null || sources.length == 0) {
@@ -98,7 +100,7 @@ public class CompositedActionFrames
{
_key.setOrient(orient);
CompositedMultiFrameImage cmfi =
(CompositedMultiFrameImage)_frameCache.get(_key);
_frameCache.get(_key);
if (cmfi == null) {
cmfi = createFrames(orient);
_frameCache.put(new CompositedFramesKey(orient), cmfi);
@@ -183,7 +185,7 @@ public class CompositedActionFrames
protected ImageManager _imgr;
/** Used to cache our composited action frame images. */
protected LRUHashMap _frameCache;
protected Map<CompositedFramesKey, CompositedMultiFrameImage> _frameCache;
/** The action for which we're compositing frames. */
protected String _action;
@@ -65,14 +65,14 @@ public class BuilderModel
{
int size = _listeners.size();
for (int ii = 0; ii < size; ii++) {
((BuilderModelListener)_listeners.get(ii)).modelChanged(event);
_listeners.get(ii).modelChanged(event);
}
}
/**
* Returns a list of the available component classes.
*/
public List getComponentClasses ()
public List<ComponentClass> getComponentClasses ()
{
return Collections.unmodifiableList(_classes);
}
@@ -80,11 +80,11 @@ public class BuilderModel
/**
* Returns the list of components available in the specified class.
*/
public List getComponents (ComponentClass cclass)
public List<Integer> getComponents (ComponentClass cclass)
{
List list = (List)_components.get(cclass);
List<Integer> list = _components.get(cclass);
if (list == null) {
list = new ArrayList();
list = new ArrayList<Integer>();
}
return list;
}
@@ -95,9 +95,9 @@ public class BuilderModel
public int[] getSelectedComponents ()
{
int[] values = new int[_selected.size()];
Iterator iter = _selected.values().iterator();
Iterator<Integer> iter = _selected.values().iterator();
for (int i = 0; iter.hasNext(); i++) {
values[i] = ((Integer)iter.next()).intValue();
values[i] = iter.next().intValue();
}
return values;
}
@@ -122,14 +122,14 @@ public class BuilderModel
for (int ii = 0; ii < _classes.size(); ii++) {
// get the list of components available for this class
ComponentClass cclass = (ComponentClass)_classes.get(ii);
Iterator iter = crepo.enumerateComponentIds(cclass);
ComponentClass cclass = _classes.get(ii);
Iterator<Integer> iter = crepo.enumerateComponentIds(cclass);
while (iter.hasNext()) {
Integer cid = (Integer)iter.next();
ArrayList clist = (ArrayList)_components.get(cclass);
Integer cid = iter.next();
ArrayList<Integer> clist = _components.get(cclass);
if (clist == null) {
_components.put(cclass, clist = new ArrayList());
_components.put(cclass, clist = new ArrayList<Integer>());
}
clist.add(cid);
@@ -138,14 +138,14 @@ public class BuilderModel
}
/** The currently selected character components. */
protected HashMap _selected = new HashMap();
protected HashMap<ComponentClass, Integer> _selected = new HashMap<ComponentClass, Integer>();
/** The hashtable of available component ids for each class. */
protected HashMap _components = new HashMap();
protected HashMap<ComponentClass, ArrayList<Integer>> _components = new HashMap<ComponentClass, ArrayList<Integer>>();
/** The list of all available component classes. */
protected ArrayList _classes = new ArrayList();
protected ArrayList<ComponentClass> _classes = new ArrayList<ComponentClass>();
/** The model listeners. */
protected ArrayList _listeners = new ArrayList();
protected ArrayList<BuilderModelListener> _listeners = new ArrayList<BuilderModelListener>();
}
@@ -42,8 +42,7 @@ public class ClassEditor extends JPanel implements ChangeListener
/**
* Constructs a class editor.
*/
public ClassEditor (
BuilderModel model, ComponentClass cclass, List components)
public ClassEditor (BuilderModel model, ComponentClass cclass, List<Integer> components)
{
_model = model;
_components = components;
@@ -92,7 +91,7 @@ public class ClassEditor extends JPanel implements ChangeListener
*/
protected void setSelectedComponent (int idx)
{
int cid = ((Integer)_components.get(idx)).intValue();
int cid = _components.get(idx).intValue();
_model.setSelectedComponent(_cclass, cid);
}
@@ -100,7 +99,7 @@ public class ClassEditor extends JPanel implements ChangeListener
protected ComponentClass _cclass;
/** The components selectable via this editor. */
protected List _components;
protected List<Integer> _components;
/** The label denoting the currently selected component index. */
protected JLabel _clabel;
@@ -56,14 +56,14 @@ public class ComponentPanel extends JPanel
*/
protected void addClassEditors (BuilderModel model, String cprefix)
{
List classes = model.getComponentClasses();
List<ComponentClass> classes = model.getComponentClasses();
int size = classes.size();
for (int ii = 0; ii < size; ii++) {
ComponentClass cclass = (ComponentClass)classes.get(ii);
ComponentClass cclass = classes.get(ii);
if (!cclass.name.startsWith(cprefix)) {
continue;
}
List ccomps = model.getComponents(cclass);
List<Integer> ccomps = model.getComponents(cclass);
if (ccomps.size() > 0) {
add(new ClassEditor(model, cclass, ccomps));
} else {
@@ -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
@@ -46,7 +46,7 @@ public class CastUtil
String gender, ComponentRepository crepo)
{
// get all available classes
ArrayList classes = new ArrayList();
ArrayList<ComponentClass> classes = new ArrayList<ComponentClass>();
for (int i = 0; i < CLASSES.length; i++) {
String cname = gender + "/" + CLASSES[i];
ComponentClass cclass = crepo.getComponentClass(cname);
@@ -59,7 +59,7 @@ public class CastUtil
}
// make sure there are some components in this class
Iterator iter = crepo.enumerateComponentIds(cclass);
Iterator<Integer> iter = crepo.enumerateComponentIds(cclass);
if (!iter.hasNext()) {
log.info("Skipping class for which we have no components " +
"[class=" + cclass + "].");
@@ -73,17 +73,17 @@ public class CastUtil
int size = classes.size();
int components[] = new int[size];
for (int ii = 0; ii < size; ii++) {
ComponentClass cclass = (ComponentClass)classes.get(ii);
ComponentClass cclass = classes.get(ii);
// get the components available for this class
ArrayList choices = new ArrayList();
Iterator iter = crepo.enumerateComponentIds(cclass);
ArrayList<Integer> choices = new ArrayList<Integer>();
Iterator<Integer> iter = crepo.enumerateComponentIds(cclass);
CollectionUtil.addAll(choices, iter);
// choose a random component
if (choices.size() > 0) {
int idx = RandomUtil.getInt(choices.size());
components[ii] = ((Integer)choices.get(idx)).intValue();
components[ii] = choices.get(idx).intValue();
} else {
log.info("Have no components in class [class=" + cclass + "].");
}
@@ -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();
@@ -79,7 +79,7 @@ public class DirtyItemList
*/
public DirtyItem get (int idx)
{
return (DirtyItem)_items.get(idx);
return _items.get(idx);
}
/**
@@ -121,9 +121,9 @@ public class DirtyItemList
_items.clear();
POS_LOOP:
for (int ii = 0; ii < size; ii++) {
DirtyItem item = (DirtyItem)_ditems.get(ii);
DirtyItem item = _ditems.get(ii);
for (int rr = _items.size()-1; rr >= 0; rr--) {
DirtyItem pitem = (DirtyItem)_items.get(rr);
DirtyItem pitem = _items.get(rr);
// if we render in front of this item, insert
// ourselves immediately following it
if (_rcomp.compare(item, pitem) > 0) {
@@ -145,8 +145,8 @@ public class DirtyItemList
if (DEBUG_SORT) {
log.info("Sorted for render [items=" + toString(_items) + "].");
for (int ii = 0, ll = _items.size()-1; ii < ll; ii++) {
DirtyItem a = (DirtyItem)_items.get(ii);
DirtyItem b = (DirtyItem)_items.get(ii+1);
DirtyItem a = _items.get(ii);
DirtyItem b = _items.get(ii+1);
if (_rcomp.compare(a, b) > 0) {
log.warning("Invalid ordering [a=" + a + ", b=" + b + "].");
}
@@ -163,7 +163,7 @@ public class DirtyItemList
{
int icount = _items.size();
for (int ii = 0; ii < icount; ii++) {
DirtyItem item = (DirtyItem)_items.get(ii);
DirtyItem item = _items.get(ii);
item.paint(gfx);
item.clear();
_freelist.add(item);
@@ -177,7 +177,7 @@ public class DirtyItemList
public void clear ()
{
for (int icount = _items.size(); icount > 0; icount--) {
DirtyItem item = (DirtyItem)_items.remove(0);
DirtyItem item = _items.remove(0);
item.clear();
_freelist.add(item);
}
@@ -198,7 +198,7 @@ public class DirtyItemList
protected DirtyItem getDirtyItem ()
{
if (_freelist.size() > 0) {
return (DirtyItem)_freelist.remove(0);
return _freelist.remove(0);
} else {
return new DirtyItem();
}
@@ -232,12 +232,12 @@ public class DirtyItemList
* Returns an abbreviated string representation of the given dirty
* items. See {@link #toString(DirtyItem)}.
*/
protected static String toString (SortableArrayList items)
protected static String toString (SortableArrayList<DirtyItem> items)
{
StringBuilder buf = new StringBuilder();
buf.append("[");
for (int ii = 0; ii < items.size(); ii++) {
DirtyItem item = (DirtyItem)items.get(ii);
DirtyItem item = items.get(ii);
toString(buf, item);
if (ii < (items.size() - 1)) {
buf.append(", ");
@@ -381,7 +381,7 @@ public class DirtyItemList
* A comparator class for use in sorting dirty items in ascending
* origin x- or y-axis coordinate order.
*/
protected static class OriginComparator implements Comparator
protected static class OriginComparator implements Comparator<DirtyItem>
{
/**
* Constructs an origin comparator that sorts dirty items in
@@ -394,11 +394,8 @@ public class DirtyItemList
}
// documentation inherited
public int compare (Object a, Object b)
public int compare (DirtyItem da, DirtyItem db)
{
DirtyItem da = (DirtyItem)a;
DirtyItem db = (DirtyItem)b;
// if they don't overlap, sort them normally
if (_axis == X_AXIS) {
if (da.ox != db.ox) {
@@ -425,14 +422,11 @@ public class DirtyItemList
* suitable for rendering in the isometric view with proper visual
* results.
*/
protected class RenderComparator implements Comparator
protected class RenderComparator implements Comparator<DirtyItem>
{
// documentation inherited
public int compare (Object a, Object b)
public int compare (DirtyItem da, DirtyItem db)
{
DirtyItem da = (DirtyItem)a;
DirtyItem db = (DirtyItem)b;
// if the two objects are scene objects and they overlap, we
// compare them solely based on their human assigned priority
if ((da.obj instanceof SceneObject) &&
@@ -490,8 +484,8 @@ public class DirtyItemList
protected int comparePartitioned (int axis, DirtyItem da, DirtyItem db)
{
// prepare for the partitioning check
SortableArrayList sitems;
Comparator comp;
SortableArrayList<DirtyItem> sitems;
Comparator<DirtyItem> comp;
boolean swapped = false;
switch (axis) {
case X_AXIS:
@@ -543,7 +537,7 @@ public class DirtyItemList
// check each potentially partitioning item
int startidx = aidx + 1, endidx = startidx + size;
for (int pidx = startidx; pidx < endidx; pidx++) {
DirtyItem dp = (DirtyItem)sitems.get(pidx);
DirtyItem dp = sitems.get(pidx);
if (dp.obj instanceof Sprite) {
// sprites can't partition things
continue;
@@ -652,22 +646,22 @@ public class DirtyItemList
}
/** The list of dirty items. */
protected SortableArrayList _items = new SortableArrayList();
protected SortableArrayList<DirtyItem> _items = new SortableArrayList<DirtyItem>();
/** The list of dirty items sorted by x-position. */
protected SortableArrayList _xitems = new SortableArrayList();
protected SortableArrayList<DirtyItem> _xitems = new SortableArrayList<DirtyItem>();
/** The list of dirty items sorted by y-position. */
protected SortableArrayList _yitems = new SortableArrayList();
protected SortableArrayList<DirtyItem> _yitems = new SortableArrayList<DirtyItem>();
/** The list of dirty items sorted by rear-depth. */
protected SortableArrayList _ditems = new SortableArrayList();
protected SortableArrayList<DirtyItem> _ditems = new SortableArrayList<DirtyItem>();
/** The render comparator we'll use for our final, magical sort. */
protected Comparator _rcomp = new RenderComparator();
protected Comparator<DirtyItem> _rcomp = new RenderComparator();
/** Unused dirty items. */
protected ArrayList _freelist = new ArrayList();
protected ArrayList<DirtyItem> _freelist = new ArrayList<DirtyItem>();
/** Whether to log debug info when comparing pairs of dirty items. */
protected static final boolean DEBUG_COMPARE = false;
@@ -681,20 +675,17 @@ public class DirtyItemList
/** The comparator used to sort dirty items in ascending origin
* x-coordinate order. */
protected static final Comparator ORIGIN_X_COMP =
new OriginComparator(X_AXIS);
protected static final Comparator<DirtyItem> ORIGIN_X_COMP = new OriginComparator(X_AXIS);
/** The comparator used to sort dirty items in ascending origin
* y-coordinate order. */
protected static final Comparator ORIGIN_Y_COMP =
new OriginComparator(Y_AXIS);
protected static final Comparator<DirtyItem> ORIGIN_Y_COMP = new OriginComparator(Y_AXIS);
/** The comparator used to sort dirty items in ascending "rear-depth"
* order. */
protected static final Comparator REAR_DEPTH_COMP = new Comparator() {
public int compare (Object o1, Object o2) {
return (((DirtyItem)o1).getRearDepth() -
((DirtyItem)o2).getRearDepth());
protected static final Comparator<DirtyItem> REAR_DEPTH_COMP = new Comparator<DirtyItem>() {
public int compare (DirtyItem o1, DirtyItem o2) {
return (o1.getRearDepth() - o2.getRearDepth());
}
};
}
@@ -95,7 +95,7 @@ public class ResolutionView extends JPanel
protected void assignColor (SceneBlock block, Color color)
{
IntTuple key = blockKey(block);
BlockGlyph glyph = (BlockGlyph)_blocks.get(key);
BlockGlyph glyph = _blocks.get(key);
if (glyph == null) {
glyph = new BlockGlyph(_metrics, key.left, key.right);
_blocks.put(key, glyph);
@@ -117,8 +117,8 @@ public class ResolutionView extends JPanel
gfx.scale(0.25, 0.25);
// draw our block glyphs
for (Iterator iter = _blocks.values().iterator(); iter.hasNext(); ) {
((BlockGlyph)iter.next()).paint(gfx);
for (Iterator<BlockGlyph> iter = _blocks.values().iterator(); iter.hasNext(); ) {
iter.next().paint(gfx);
}
// draw the view bounds
@@ -158,7 +158,7 @@ public class ResolutionView extends JPanel
protected MisoScenePanel _panel;
protected MisoSceneMetrics _metrics;
protected HashMap _blocks = new HashMap();
protected HashMap<IntTuple, BlockGlyph> _blocks = new HashMap<IntTuple, BlockGlyph>();
protected static final int TILE_SIZE = 10;
protected static final int MAX_WIDTH = 30;
@@ -501,14 +501,13 @@ public class SceneBlock
* Links this block to its neighbors; informs neighboring blocks of
* object coverage.
*/
protected void update (IntMap blocks)
protected void update (IntMap<SceneBlock> blocks)
{
boolean recover = false;
// link up to our neighbors
for (int ii = 0; ii < DX.length; ii++) {
SceneBlock neigh = (SceneBlock)
blocks.get(neighborKey(DX[ii], DY[ii]));
SceneBlock neigh = blocks.get(neighborKey(DX[ii], DY[ii]));
if (neigh != _neighbors[ii]) {
_neighbors[ii] = neigh;
// if we're linking up to a neighbor for the first time;
@@ -546,14 +545,14 @@ public class SceneBlock
/**
* Sets the footprint of this object tile
*/
protected void setCovered (IntMap blocks, SceneObject scobj)
protected void setCovered (IntMap<SceneBlock> blocks, SceneObject scobj)
{
int endx = scobj.info.x - scobj.tile.getBaseWidth() + 1;
int endy = scobj.info.y - scobj.tile.getBaseHeight() + 1;
for (int xx = scobj.info.x; xx >= endx; xx--) {
for (int yy = scobj.info.y; yy >= endy; yy--) {
SceneBlock block = (SceneBlock)blocks.get(blockKey(xx, yy));
SceneBlock block = blocks.get(blockKey(xx, yy));
if (block != null) {
block.setCovered(xx, yy);
}
@@ -55,7 +55,7 @@ public class TilePath extends LineSegmentPath
* coordinates.
*/
public TilePath (MisoSceneMetrics metrics, Sprite sprite,
List tiles, int destx, int desty)
List<Point> tiles, int destx, int desty)
{
// constrain destination pixels to fine coordinates
Point fpos = new Point();
@@ -74,7 +74,7 @@ public class TilePath extends LineSegmentPath
Point spos = new Point();
int size = tiles.size();
for (int ii = 1; ii < size - 1; ii++) {
Point next = (Point)tiles.get(ii);
Point next = tiles.get(ii);
// determine the direction from previous to next node
int dir = MisoUtil.getIsoDirection(prev.x, prev.y, next.x, next.y);
@@ -22,7 +22,7 @@
package com.threerings.miso.data;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.IntListUtil;
@@ -259,8 +259,8 @@ public class SimpleMisoSceneModel extends MisoSceneModel
* Populates the interesting and uninteresting parts of a miso scene
* model given lists of {@link ObjectInfo} records for each.
*/
public static void populateObjects (SimpleMisoSceneModel model,
ArrayList ilist, ArrayList ulist)
public static void populateObjects (
SimpleMisoSceneModel model, List<ObjectInfo> ilist, List<ObjectInfo> ulist)
{
// set up the uninteresting arrays
int ucount = ulist.size();
@@ -268,7 +268,7 @@ public class SimpleMisoSceneModel extends MisoSceneModel
model.objectXs = new short[ucount];
model.objectYs = new short[ucount];
for (int ii = 0; ii < ucount; ii++) {
ObjectInfo info = (ObjectInfo)ulist.get(ii);
ObjectInfo info = ulist.get(ii);
model.objectTileIds[ii] = info.tileId;
model.objectXs[ii] = (short)info.x;
model.objectYs[ii] = (short)info.y;
@@ -177,7 +177,7 @@ public class SparseMisoSceneModel extends MisoSceneModel
return -1;
}
public void getAllObjects (ArrayList list) {
public void getAllObjects (ArrayList<ObjectInfo> list) {
for (ObjectInfo info : objectInfo) {
list.add(info);
}
@@ -276,10 +276,10 @@ public class SparseMisoSceneModel extends MisoSceneModel
* Adds all interesting {@link ObjectInfo} records in this scene to
* the supplied list.
*/
public void getInterestingObjects (ArrayList list)
public void getInterestingObjects (ArrayList<ObjectInfo> list)
{
for (Iterator iter = getSections(); iter.hasNext(); ) {
Section sect = (Section)iter.next();
for (Iterator<Section> iter = getSections(); iter.hasNext(); ) {
Section sect = iter.next();
for (int oo = 0; oo < sect.objectInfo.length; oo++) {
list.add(sect.objectInfo[oo]);
}
@@ -289,12 +289,10 @@ public class SparseMisoSceneModel extends MisoSceneModel
/**
* Adds all {@link ObjectInfo} records in this scene to the supplied list.
*/
public void getAllObjects (ArrayList list)
public void getAllObjects (ArrayList<ObjectInfo> list)
{
for (Iterator iter = getSections(); iter.hasNext(); ) {
Section sect = (Section)iter.next();
sect.getAllObjects(list);
for (Iterator<Section> iter = getSections(); iter.hasNext(); ) {
iter.next().getAllObjects(list);
}
}
@@ -314,8 +312,8 @@ public class SparseMisoSceneModel extends MisoSceneModel
*/
public void visitObjects (ObjectVisitor visitor, boolean interestingOnly)
{
for (Iterator iter = getSections(); iter.hasNext(); ) {
Section sect = (Section)iter.next();
for (Iterator<Section> iter = getSections(); iter.hasNext(); ) {
Section sect = iter.next();
for (int oo = 0; oo < sect.objectInfo.length; oo++) {
ObjectInfo oinfo = sect.objectInfo[oo];
visitor.visit(oinfo);
@@ -48,7 +48,7 @@ public class FringeConfiguration implements Serializable
public int priority;
/** A list of the possible tilesets that can be used for fringing. */
public ArrayList tilesets = new ArrayList();
public ArrayList<FringeTileSetRecord> tilesets = new ArrayList<FringeTileSetRecord>();
/** Used when parsing the tilesets definitions. */
public void addTileset (FringeTileSetRecord record)
@@ -117,7 +117,7 @@ public class FringeConfiguration implements Serializable
*/
public int fringesOn (int first, int second)
{
FringeRecord f1 = (FringeRecord) _frecs.get(first);
FringeRecord f1 = _frecs.get(first);
// we better have a fringe record for the first
if (null != f1) {
@@ -125,7 +125,7 @@ public class FringeConfiguration implements Serializable
// it had better have some tilesets defined
if (f1.tilesets.size() > 0) {
FringeRecord f2 = (FringeRecord) _frecs.get(second);
FringeRecord f2 = _frecs.get(second);
// and we only fringe if second doesn't exist or has a lower
// priority
@@ -144,13 +144,13 @@ public class FringeConfiguration implements Serializable
*/
public FringeTileSetRecord getFringe (int baseset, int hashValue)
{
FringeRecord f = (FringeRecord) _frecs.get(baseset);
return (FringeTileSetRecord) f.tilesets.get(
FringeRecord f = _frecs.get(baseset);
return f.tilesets.get(
hashValue % f.tilesets.size());
}
/** The mapping from base tileset id to fringerecord. */
protected HashIntMap _frecs = new HashIntMap();
protected HashIntMap<FringeRecord> _frecs = new HashIntMap<FringeRecord>();
/** Increase this value when object's serialized state is impacted by
* a class change (modification of fields, inheritance). */
@@ -26,6 +26,7 @@ import org.apache.commons.digester.Digester;
import com.samskivert.util.StringUtil;
import com.samskivert.xml.CallMethodSpecialRule;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.tools.xml.SwissArmyTileSetRuleSet;
import com.threerings.miso.tile.BaseTileSet;
@@ -77,7 +78,7 @@ public class BaseTileSetRuleSet extends SwissArmyTileSetRuleSet
}
@Override
protected Class getTileSetClass ()
protected Class<? extends TileSet> getTileSetClass ()
{
return BaseTileSet.class;
}
@@ -84,14 +84,15 @@ public class SimpleMisoSceneRuleSet implements NestableRuleSet
public void parseAndSet (String bodyText, Object target)
throws Exception
{
ArrayList ilist = (ArrayList)target;
ArrayList ulist = new ArrayList();
@SuppressWarnings("unchecked") ArrayList<ObjectInfo> ilist =
(ArrayList<ObjectInfo>)target;
ArrayList<ObjectInfo> ulist = new ArrayList<ObjectInfo>();
SimpleMisoSceneModel model = (SimpleMisoSceneModel)
digester.peek(1);
// filter interesting and uninteresting into two lists
for (int ii = 0; ii < ilist.size(); ii++) {
ObjectInfo info = (ObjectInfo)ilist.get(ii);
ObjectInfo info = ilist.get(ii);
if (!info.isInteresting()) {
ilist.remove(ii--);
ulist.add(info);
@@ -163,7 +163,7 @@ public class ObjectSet
/** We simply sort the objects in order of their hash code. We don't
* care about their order, it exists only to support binary search. */
protected static final Comparator INFO_COMP = new Comparator() {
protected static final Comparator<Object> INFO_COMP = new Comparator<Object>() {
public int compare (Object o1, Object o2) {
ObjectInfo do1 = (ObjectInfo)o1;
ObjectInfo do2 = (ObjectInfo)o2;
@@ -207,8 +207,8 @@ public class ResourceManager
{
// set up a URL handler so that things can be loaded via urls with the 'resource' protocol
try {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run () {
Handler.registerHandler(ResourceManager.this);
return null;
}
@@ -272,7 +272,7 @@ public class ResourceManager
// resolve the configured resource sets
List<ResourceBundle> dlist = new ArrayList<ResourceBundle>();
Enumeration names = config.propertyNames();
Enumeration<?> names = config.propertyNames();
while (names.hasMoreElements()) {
String key = (String)names.nextElement();
if (!key.startsWith(RESOURCE_SET_PREFIX)) {
@@ -421,7 +421,7 @@ public class ResourceManager
* already resolved, or it may be notified on a brand new thread if the bundle requires
* unpacking.
*/
public void resolveBundle (String path, final ResultListener listener)
public void resolveBundle (String path, final ResultListener<FileResourceBundle> listener)
{
File bfile = getResourceFile(path);
if (bfile == null) {
@@ -442,7 +442,7 @@ public class ResourceManager
}
// start a thread to unpack our bundles
ArrayList list = new ArrayList();
ArrayList<ResourceBundle> list = new ArrayList<ResourceBundle>();
list.add(bundle);
Unpacker unpack = new Unpacker(list, new InitObserver() {
public void progress (int percent, long remaining) {
@@ -513,8 +513,8 @@ public class ResourceManager
if (_localePrefix != null) {
final String rpath = PathUtil.appendPath(
_rootPath, PathUtil.appendPath(_localePrefix, path));
in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run () {
return _loader.getResourceAsStream(rpath);
}
});
@@ -525,8 +525,8 @@ public class ResourceManager
// if we didn't find that, try locale-neutral
final String rpath = PathUtil.appendPath(_rootPath, path);
in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run () {
return _loader.getResourceAsStream(rpath);
}
});
@@ -578,8 +578,8 @@ public class ResourceManager
if (_localePrefix != null) {
final String rpath = PathUtil.appendPath(
_rootPath, PathUtil.appendPath(_localePrefix, path));
InputStream in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run () {
return _loader.getResourceAsStream(rpath);
}
});
@@ -590,8 +590,8 @@ public class ResourceManager
// if we still didn't find anything, try the classloader
final String rpath = PathUtil.appendPath(_rootPath, path);
InputStream in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run () {
return _loader.getResourceAsStream(rpath);
}
});
@@ -71,7 +71,7 @@ public class CompiledConfigTask extends Task
// instantiate and sanity check the parser class
Object pobj = null;
try {
Class pclass = Class.forName(_parser);
Class<?> pclass = Class.forName(_parser);
pobj = pclass.newInstance();
} catch (Exception e) {
throw new BuildException("Error instantiating config parser", e);
@@ -42,7 +42,7 @@ public class BrowserUtil
* @param listener a listener to be notified if we failed to launch the
* browser. <em>Note:</em> it will not be notified of success.
*/
public static void browseURL (URL url, ResultListener listener)
public static void browseURL (URL url, ResultListener<Void> listener)
{
browseURL(url, listener, "firefox");
}
@@ -56,8 +56,7 @@ public class BrowserUtil
* @param genagent the path to the browser to execute on non-Windows,
* non-MacOS.
*/
public static void browseURL (
URL url, ResultListener listener, String genagent)
public static void browseURL (URL url, ResultListener<Void> listener, String genagent)
{
String[] cmd;
if (RunAnywhere.isWindows()) {
@@ -98,7 +97,7 @@ public class BrowserUtil
protected static class BrowserTracker extends Thread
{
public BrowserTracker (Process process, URL url, ResultListener rl) {
public BrowserTracker (Process process, URL url, ResultListener<Void> rl) {
super("BrowserLaunchWaiter");
setDaemon(true);
_process = process;
@@ -142,6 +141,6 @@ public class BrowserUtil
protected Process _process;
protected URL _url;
protected ResultListener _listener;
protected ResultListener<Void> _listener;
};
}
@@ -804,7 +804,7 @@ public class KeyboardManager
protected KeyTranslator _xlate;
/** The list of key observers. */
protected ObserverList _observers = new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
protected ObserverList<KeyObserver> _observers = ObserverList.newFastUnsafe();
/** The operation used to notify observers of actual key events. */
protected KeyObserverOp _keyOp = new KeyObserverOp();
@@ -24,6 +24,7 @@ package com.threerings.cast.bundle;
import java.awt.Component;
import java.util.Iterator;
import com.threerings.cast.ComponentClass;
import com.threerings.media.image.ClientImageManager;
import com.threerings.resource.ResourceManager;
@@ -57,7 +58,7 @@ public class BundledComponentRepositoryTest extends TestCase
// System.out.println("Action sets: " + StringUtil.toString(
// repo._actionSets.values().iterator()));
Iterator iter = repo.enumerateComponentClasses();
Iterator<ComponentClass> iter = repo.enumerateComponentClasses();
while (iter.hasNext()) {
// ComponentClass cclass = (ComponentClass)
iter.next();
@@ -25,6 +25,7 @@ import java.awt.Component;
import java.util.Iterator;
import com.threerings.media.image.ClientImageManager;
import com.threerings.media.tile.TileSet;
import com.threerings.resource.ResourceManager;
import junit.framework.Test;
@@ -46,7 +47,7 @@ public class BundledTileSetRepositoryTest extends TestCase
null, "config/resource/manager.properties", null);
BundledTileSetRepository repo = new BundledTileSetRepository(
rmgr, new ClientImageManager(rmgr, (Component)null), "tilesets");
Iterator sets = repo.enumerateTileSets();
Iterator<TileSet> sets = repo.enumerateTileSets();
while (sets.hasNext()) {
sets.next();
// System.out.println(sets.next());
@@ -25,6 +25,8 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.HashMap;
import com.threerings.media.tile.TileSet;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -38,7 +40,7 @@ public class XMLTileSetParserTest extends TestCase
@Override
public void runTest ()
{
HashMap sets = new HashMap();
HashMap<String, TileSet> sets = new HashMap<String, TileSet>();
XMLTileSetParser parser = new XMLTileSetParser();
// add some rulesets
@@ -51,7 +53,7 @@ public class XMLTileSetParserTest extends TestCase
parser.loadTileSets(TILESET_PATH, sets);
// print them out
Iterator iter = sets.values().iterator();
Iterator<TileSet> iter = sets.values().iterator();
while (iter.hasNext()) {
iter.next();
// System.out.println(iter.next());
@@ -49,10 +49,10 @@ public class ScrollingScene extends MisoSceneModel
{
// locate the water tileset
TileSetRepository tsrepo = ctx.getTileManager().getTileSetRepository();
Iterator iter = tsrepo.enumerateTileSets();
Iterator<TileSet> iter = tsrepo.enumerateTileSets();
String tsname = null;
while (iter.hasNext()) {
TileSet tset = (TileSet)iter.next();
TileSet tset = iter.next();
// yay for built-in regex support!
if (tset.getName().matches(".*[Ww]ater.*") &&
tset instanceof BaseTileSet) {