A healthy splash of google-collections

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@822 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Dave Hoover
2009-05-23 01:31:14 +00:00
parent a20117d922
commit d2b9e2ebb9
52 changed files with 246 additions and 191 deletions
@@ -37,6 +37,8 @@ import javax.swing.SwingUtilities;
import javax.swing.event.AncestorEvent;
import javax.swing.event.MouseInputAdapter;
import com.google.common.collect.Lists;
import com.samskivert.swing.Controller;
import com.samskivert.swing.event.AncestorAdapter;
import com.samskivert.swing.event.CommandEvent;
@@ -367,7 +369,7 @@ public class MediaPanel extends JComponent
*/
public void addObscurer (Obscurer obscurer) {
if (_obscurerList == null) {
_obscurerList = new ArrayList<Obscurer>();
_obscurerList = Lists.newArrayList();
}
_obscurerList.add(obscurer);
}
@@ -640,7 +642,7 @@ public class MediaPanel extends JComponent
*/
protected Sprite getHit (MouseEvent me)
{
ArrayList<Sprite> list = new ArrayList<Sprite>();
ArrayList<Sprite> list = Lists.newArrayList();
getSpriteManager().getHitSprites(list, me.getX(), me.getY());
for (int ii = 0, nn = list.size(); ii < nn; ii++) {
Object o = list.get(ii);
@@ -31,6 +31,8 @@ import java.awt.event.MouseWheelEvent;
import javax.swing.SwingUtilities;
import com.google.common.collect.Lists;
import com.samskivert.util.RunAnywhere;
import com.threerings.media.image.ImageUtil;
@@ -462,5 +464,5 @@ public class VirtualMediaPanel extends MediaPanel
protected Rectangle _abounds = new Rectangle();
/** A list of entities to be informed when the view scrolls. */
protected ArrayList<ViewTracker> _trackers = new ArrayList<ViewTracker>();
protected ArrayList<ViewTracker> _trackers = Lists.newArrayList();
}
@@ -25,6 +25,8 @@ import java.util.ArrayList;
import java.awt.Rectangle;
import com.google.common.collect.Lists;
import com.samskivert.swing.util.SwingUtil;
import static com.threerings.media.Log.log;
@@ -42,7 +44,7 @@ public class AnimationArranger
public void positionAvoidAnimation (Animation anim, Rectangle viewBounds)
{
Rectangle abounds = new Rectangle(anim.getBounds());
@SuppressWarnings("unchecked") ArrayList<Animation> avoidables =
@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)) {
@@ -56,7 +58,7 @@ public class AnimationArranger
}
/** The animations that other animations may wish to avoid. */
protected ArrayList<Animation> _avoidAnims = new ArrayList<Animation>();
protected ArrayList<Animation> _avoidAnims = Lists.newArrayList();
/** Automatically removes avoid animations when they're done. */
protected AnimationAdapter _avoidAnimObs = new AnimationAdapter() {
@@ -26,6 +26,8 @@ import java.util.ArrayList;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import com.google.common.collect.Lists;
import com.samskivert.util.StringUtil;
import static com.threerings.media.Log.log;
@@ -284,10 +286,10 @@ public class AnimationSequencer extends Animation
protected AnimationManager _animmgr;
/** Animations that have not been fired. */
protected ArrayList<AnimRecord> _queued = new ArrayList<AnimRecord>();
protected ArrayList<AnimRecord> _queued = Lists.newArrayList();
/** Animations that are currently running. */
protected ArrayList<AnimRecord> _running = new ArrayList<AnimRecord>();
protected ArrayList<AnimRecord> _running = Lists.newArrayList();
/** The timestamp at which we fired the last animation. */
protected long _lastStamp;
@@ -34,6 +34,8 @@ import java.text.ParseException;
import java.awt.Color;
import com.google.common.collect.Lists;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.RandomUtil;
import com.samskivert.util.StringUtil;
@@ -133,7 +135,7 @@ public class ColorPository implements Serializable
{
// figure out our starter ids if we haven't already
if (_starters == null) {
ArrayList<ColorRecord> list = new ArrayList<ColorRecord>();
ArrayList<ColorRecord> list = Lists.newArrayList();
for (ColorRecord color : colors.values()) {
if (color.starter) {
list.add(color);
@@ -144,8 +146,8 @@ public class ColorPository implements Serializable
// sanity check
if (_starters.length < 1) {
log.warning("Requested random starting color from " +
"colorless component class " + this + "].");
log.warning("Requested random starting color from colorless component class",
"class", this);
return null;
}
@@ -36,7 +36,9 @@ import java.awt.Rectangle;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil;
@@ -477,7 +479,7 @@ public class ImageManager
}
if (_colorized == null) {
_colorized = new ArrayList<Tuple<Colorization[], BufferedImage>>();
_colorized = Lists.newArrayList();
}
// we search linearly through our list of colorized copies because it is not likely to
@@ -540,7 +542,7 @@ public class ImageManager
protected LRUHashMap<ImageKey, CacheRecord> _ccache;
/** The set of all keys we've ever seen. */
protected HashSet<ImageKey> _keySet = new HashSet<ImageKey>();
protected HashSet<ImageKey> _keySet = Sets.newHashSet();
/** Throttle our cache status logging to once every 300 seconds. */
protected Throttle _cacheStatThrottle = new Throttle(1, 300000L);
@@ -42,6 +42,8 @@ import javax.sound.sampled.UnsupportedAudioFileException;
import org.apache.commons.io.IOUtils;
import com.google.common.collect.Maps;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.Queue;
import com.samskivert.util.RandomUtil;
@@ -759,7 +761,7 @@ public class JavaSoundPlayer extends SoundPlayer
* The set of locked audio clips; this is separate from the LRU so that locking clips doesn't
* booch up an otherwise normal caching agenda.
*/
protected HashMap<SoundKey,byte[][]> _lockedClips = new HashMap<SoundKey,byte[][]>();
protected HashMap<SoundKey,byte[][]> _lockedClips = Maps.newHashMap();
/** Soundkey command constants. */
protected static final byte PLAY = 0;
@@ -24,6 +24,8 @@ package com.threerings.media.tile.bundle;
import java.util.HashMap;
import java.util.Iterator;
import com.google.common.collect.Maps;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.HashIntMap;
import com.samskivert.util.IntMap;
@@ -74,7 +76,7 @@ public class BundledTileSetRepository
}
/**
* Initializes our bundles,
* Initializes our bundles,
*/
protected void initBundles (ResourceManager rmgr, String name)
{
@@ -91,12 +93,12 @@ public class BundledTileSetRepository
}
HashIntMap<TileSet> idmap = new HashIntMap<TileSet>();
HashMap<String, Integer> namemap = new HashMap<String, Integer>();
HashMap<String, Integer> namemap = Maps.newHashMap();
// iterate over the resource bundles in the set, loading up the
// tileset bundles in each resource bundle
for (int i = 0; i < rbundles.length; i++) {
addBundle(idmap, namemap, rbundles[i]);
for (ResourceBundle rbundle : rbundles) {
addBundle(idmap, namemap, rbundle);
}
// fill in our bundles array and wake up any waiters
@@ -43,6 +43,8 @@ import org.xml.sax.SAXException;
import org.apache.commons.digester.Digester;
import org.apache.commons.io.IOUtils;
import com.google.common.collect.Lists;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.HashIntMap;
@@ -137,7 +139,7 @@ public class TileSetBundler
Digester digester = new Digester();
// push our mappings array onto the stack
ArrayList<Mapping> mappings = new ArrayList<Mapping>();
ArrayList<Mapping> mappings = Lists.newArrayList();
digester.push(mappings);
// create a mapping object for each mapping entry and append it to
@@ -232,7 +234,7 @@ public class TileSetBundler
{
// stick an array list on the top of the stack into which we will
// collect parsed tilesets
ArrayList<TileSet> sets = new ArrayList<TileSet>();
ArrayList<TileSet> sets = Lists.newArrayList();
_digester.push(sets);
// parse the tilesets
@@ -367,7 +369,7 @@ public class TileSetBundler
// write all of the image files to the bundle, converting the
// tilesets to trimmed tilesets in the process
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>();
@@ -31,6 +31,8 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import com.google.common.collect.Lists;
import com.threerings.media.tile.tools.MapFileTileSetIDBroker;
/**
@@ -92,8 +94,8 @@ public class TileSetBundlerTask extends Task
File fromDir = fs.getDir(getProject());
String[] srcFiles = ds.getIncludedFiles();
for (int f = 0; f < srcFiles.length; f++) {
cfile = new File(fromDir, srcFiles[f]);
for (String srcFile : srcFiles) {
cfile = new File(fromDir, srcFile);
// figure out the bundle file based on the definition
// file
@@ -158,5 +160,5 @@ public class TileSetBundlerTask extends Task
protected File _mapfile;
/** A list of filesets that contain tileset bundle definitions. */
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
}
@@ -32,6 +32,8 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import com.google.common.collect.Maps;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.QuickSort;
@@ -60,14 +62,14 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
_nextTileSetID = readInt(bin);
_storedTileSetID = _nextTileSetID;
// read in our mappings
_map = new HashMap<String, Integer>();
_map = Maps.newHashMap();
readMapFile(bin, _map);
bin.close();
} catch (FileNotFoundException fnfe) {
// create a blank map if our map file doesn't exist
_map = new HashMap<String, Integer>();
_map = Maps.newHashMap();
} catch (Exception e) {
// other errors are more fatal
@@ -170,8 +172,8 @@ public class MapFileTileSetIDBroker implements TileSetIDBroker
lines[ii] = key + SEP_STR + value;
}
QuickSort.sort(lines);
for (int ii = 0; ii < lines.length; ii++) {
bout.write(lines[ii], 0, lines[ii].length());
for (String line : lines) {
bout.write(line, 0, line.length());
bout.newLine();
}
bout.flush();
@@ -21,7 +21,6 @@
package com.threerings.media.tile.tools.xml;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -35,6 +34,8 @@ import org.xml.sax.SAXException;
import org.apache.commons.digester.Digester;
import com.google.common.collect.Lists;
import com.samskivert.util.ConfigUtil;
import com.samskivert.xml.ValidatedSetNextRule;
@@ -144,7 +145,7 @@ public class XMLTileSetParser
{
// stick an array list on the top of the stack for collecting
// parsed tilesets
List<TileSet> setlist = new ArrayList<TileSet>();
List<TileSet> setlist = Lists.newArrayList();
_digester.push(setlist);
// now fire up the digester to parse the stream
@@ -56,6 +56,8 @@ import javax.swing.JToggleButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.google.common.collect.Lists;
import com.samskivert.util.QuickSort;
import com.samskivert.swing.HGroupLayout;
@@ -250,7 +252,7 @@ public class RecolorImage extends JPanel
Graphics gfx = img.getGraphics();
int y = 0;
ArrayList<Integer> sortedKeys = new ArrayList<Integer>();
ArrayList<Integer> sortedKeys = Lists.newArrayList();
sortedKeys.addAll(colClass.colors.keySet());
QuickSort.sort(sortedKeys, new Comparator<Integer>() {
@@ -340,7 +342,7 @@ public class RecolorImage extends JPanel
_classList.removeAllItems();
Iterator<ColorPository.ClassRecord> iter = _colRepo.enumerateClasses();
ArrayList<String> names = new ArrayList<String>();
ArrayList<String> names = Lists.newArrayList();
while (iter.hasNext()) {
String str = iter.next().name;
names.add(str);
@@ -32,6 +32,8 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import com.google.common.collect.Lists;
/**
* Creates a file that lists all the resources in a fileset out to an index file.
*/
@@ -44,19 +46,19 @@ public class ResourceIndexerTask extends Task
{
_filesets.add(set);
}
public void setIndexFile (String file)
{
_indexFile = file;
}
@Override
public void execute () throws BuildException
{
PrintWriter fout = null;
try {
fout = new PrintWriter(new FileWriter(_indexFile));
for (FileSet fs : _filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] srcFiles = ds.getIncludedFiles();
@@ -64,7 +66,7 @@ public class ResourceIndexerTask extends Task
fout.println(filename);
}
}
} catch (IOException ioe) {
throw new BuildException(ioe);
} finally {
@@ -75,8 +77,8 @@ public class ResourceIndexerTask extends Task
}
/** A list of filesets that contain files to include in the index. */
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
/** The name of the file to which we should write the index. */
protected String _indexFile;
}
@@ -28,6 +28,8 @@ import java.util.TreeSet;
import java.awt.Point;
import com.google.common.collect.Lists;
import com.samskivert.util.HashIntMap;
/**
@@ -270,7 +272,7 @@ public class AStarPathUtil
protected static List<Point> getNodePath (Node n)
{
Node cur = n;
ArrayList<Point> path = new ArrayList<Point>();
ArrayList<Point> path = Lists.newArrayList();
while (cur != null) {
// add to the head of the list since we're traversing from
@@ -337,7 +339,7 @@ public class AStarPathUtil
// construct the open and closed lists
open = new TreeSet<Node>();
closed = new ArrayList<Node>();
closed = Lists.newArrayList();
}
/**
@@ -29,6 +29,8 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import com.google.common.collect.Lists;
import com.samskivert.util.StringUtil;
import com.threerings.util.DirectionCodes;
@@ -237,7 +239,7 @@ public class LineSegmentPath
if (ox != nx || oy != ny) {
pable.setLocation(nx, ny);
return true;
}
}
return false;
}
@@ -340,7 +342,7 @@ public class LineSegmentPath
addNode(p.x, p.y, dir);
last = p;
}
}
}
/**
* Gets the next node in the path.
@@ -348,10 +350,10 @@ public class LineSegmentPath
protected PathNode getNextNode ()
{
return _niter.next();
}
}
/** The nodes that make up the path. */
protected ArrayList<PathNode> _nodes = new ArrayList<PathNode>();
protected ArrayList<PathNode> _nodes = Lists.newArrayList();
/** We use this when moving along this path. */
protected Iterator<PathNode> _niter;
@@ -371,7 +373,7 @@ public class LineSegmentPath
/** The path velocity in pixels per millisecond. */
protected float _vel = DEFAULT_VELOCITY;
/** When moving, the pathable position including fractional pixels. */
/** When moving, the pathable position including fractional pixels. */
protected float _movex, _movey;
/** When moving, the distance to move on each axis per tick. */
@@ -35,8 +35,7 @@ public class PathSequence
implements Path
{
/**
* Conveniently construct a path sequence with the two specified
* paths.
* Conveniently construct a path sequence with the two specified paths.
*/
public PathSequence (Path first, Path second)
{
@@ -21,7 +21,6 @@
package com.threerings.media.util;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Maps;
@@ -64,7 +63,7 @@ public class PerformanceMonitor
Map<String, PerformanceAction> actions = _observers.get(obs);
if (actions == null) {
// create it if it didn't exist
_observers.put(obs, actions = new HashMap<String, PerformanceAction>());
_observers.put(obs, actions = Maps.newHashMap());
}
// add the action to the set we're tracking
@@ -147,7 +146,7 @@ public class PerformanceMonitor
}
/** The observers monitoring some set of actions. */
protected static Map<PerformanceObserver, Map<String, PerformanceAction>> _observers =
protected static Map<PerformanceObserver, Map<String, PerformanceAction>> _observers =
Maps.newHashMap();
/** Used to obtain high resolution time stamps. */
@@ -207,7 +206,7 @@ class PerformanceAction
/** The number of milliseconds between each checkpoint. */
protected long _delta;
/** The time the last time a checkpoint was made. */
/** The time the last time a checkpoint was made. */
protected long _lastDelta;
/** The number of ticks since the last checkpoint. */