From b222eed2fdb2a40ddcff721d648f89add504d0c1 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Sat, 23 May 2009 01:04:08 +0000 Subject: [PATCH] A healthy dash of google-collections git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5798 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../admin/client/ConfigObjectManager.java | 8 ++++--- .../admin/server/ConfigRegistry.java | 4 +++- .../admin/server/DatabaseConfigRegistry.java | 3 ++- .../server/PeeredDatabaseConfigRegistry.java | 3 ++- .../server/persist/ConfigRepository.java | 4 +++- .../crowd/chat/client/ChatDirector.java | 10 ++++---- .../crowd/chat/client/MuteDirector.java | 4 +++- .../crowd/client/PlaceController.java | 4 +++- .../com/threerings/io/BasicStreamers.java | 4 +++- .../com/threerings/io/FieldMarshaller.java | 4 +++- .../com/threerings/io/ObjectInputStream.java | 9 ++++--- .../com/threerings/io/ObjectOutputStream.java | 9 +++---- src/java/com/threerings/io/Streamer.java | 6 ++--- .../io/UnreliableObjectOutputStream.java | 7 +++--- .../threerings/presents/client/Client.java | 4 +++- .../presents/client/ClientDObjectMgr.java | 7 ++++-- .../presents/client/InvocationDirector.java | 4 +++- .../presents/dobj/DynamicListener.java | 4 +++- .../presents/peer/util/PeerUtil.java | 4 +++- .../presents/server/TimeBaseProvider.java | 5 ++-- .../presents/tools/ActionScriptSource.java | 24 ++++++++++--------- .../tools/GenActionScriptBundlesTask.java | 8 ++++--- .../presents/tools/GenActionScriptTask.java | 8 ++++--- .../presents/tools/GenDObjectTask.java | 6 +++-- .../presents/tools/GenServiceTask.java | 17 +++++++------ .../presents/tools/GenStreamableTask.java | 8 ++++--- .../threerings/presents/tools/ImportSet.java | 12 ++++++---- .../tools/InstrumentStreamableTask.java | 15 +++++++----- .../presents/tools/InvocationTask.java | 6 ++--- .../threerings/presents/tools/SourceFile.java | 4 +++- .../presents/util/DatagramSequencer.java | 5 +++- .../com/threerings/util/DependencyGraph.java | 15 +++++++----- .../com/threerings/util/MessageManager.java | 4 +++- src/java/com/threerings/util/TimeUtil.java | 4 +++- 34 files changed, 152 insertions(+), 91 deletions(-) diff --git a/src/java/com/threerings/admin/client/ConfigObjectManager.java b/src/java/com/threerings/admin/client/ConfigObjectManager.java index ad9eecd6f..646b65876 100644 --- a/src/java/com/threerings/admin/client/ConfigObjectManager.java +++ b/src/java/com/threerings/admin/client/ConfigObjectManager.java @@ -23,6 +23,8 @@ package com.threerings.admin.client; import java.util.HashMap; +import com.google.common.collect.Maps; + import com.threerings.presents.client.Client; import com.threerings.presents.client.ClientAdapter; import com.threerings.presents.dobj.DObjectManager; @@ -41,7 +43,7 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener { public ConfigObjectManager (Client client) { - _serverconfig = new HashMap(); + _serverconfig = Maps.newHashMap(); _client = client; _client.addClientObserver(new ClientAdapter() { @Override @@ -57,8 +59,8 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener @Override public void clientDidLogoff (Client client) { // Clean up our subscription to the server's configuration - for (int ii = 0; ii < _csubscribers.length; ii++) { - _csubscribers[ii].cleanup(); + for (ConfigObjectSubscriber _csubscriber : _csubscribers) { + _csubscriber.cleanup(); } } }); diff --git a/src/java/com/threerings/admin/server/ConfigRegistry.java b/src/java/com/threerings/admin/server/ConfigRegistry.java index c0a23b433..4b698e4a0 100644 --- a/src/java/com/threerings/admin/server/ConfigRegistry.java +++ b/src/java/com/threerings/admin/server/ConfigRegistry.java @@ -31,6 +31,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import com.google.common.collect.Maps; + import com.samskivert.io.ByteArrayOutInputStream; import com.samskivert.util.StringUtil; @@ -412,7 +414,7 @@ public abstract class ConfigRegistry } /** A mapping from identifying key to config object. */ - protected HashMap _configs = new HashMap(); + protected HashMap _configs = Maps.newHashMap(); /** If we need to transition serialized Streamables to a new class format in init.. */ protected boolean _transitioning; diff --git a/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java b/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java index 36b1d3d33..05f1b3cc1 100644 --- a/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java +++ b/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java @@ -23,6 +23,7 @@ package com.threerings.admin.server; import java.util.HashMap; +import com.google.common.collect.Maps; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -134,7 +135,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry _data = _repo.loadConfig(_node, _path); } catch (DatabaseException pe) { log.warning("Failed to load object configuration", "path", _path, pe); - _data = new HashMap(); + _data = Maps.newHashMap(); } super.init(); diff --git a/src/java/com/threerings/admin/server/PeeredDatabaseConfigRegistry.java b/src/java/com/threerings/admin/server/PeeredDatabaseConfigRegistry.java index 9ec86eb8f..a234d4a21 100644 --- a/src/java/com/threerings/admin/server/PeeredDatabaseConfigRegistry.java +++ b/src/java/com/threerings/admin/server/PeeredDatabaseConfigRegistry.java @@ -23,6 +23,7 @@ package com.threerings.admin.server; import java.util.ArrayList; +import com.google.common.collect.Lists; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -118,7 +119,7 @@ public class PeeredDatabaseConfigRegistry extends DatabaseConfigRegistry PEER_CACHE_PREFIX + _path, new StreamableTuple(field, value)); } - protected ArrayList _pendingSyncs = new ArrayList(); + protected ArrayList _pendingSyncs = Lists.newArrayList(); } protected PeerManager _peermgr; diff --git a/src/java/com/threerings/admin/server/persist/ConfigRepository.java b/src/java/com/threerings/admin/server/persist/ConfigRepository.java index 8fa1957c4..b1b5ad2ab 100644 --- a/src/java/com/threerings/admin/server/persist/ConfigRepository.java +++ b/src/java/com/threerings/admin/server/persist/ConfigRepository.java @@ -24,6 +24,8 @@ package com.threerings.admin.server.persist; import java.util.HashMap; import java.util.Set; +import com.google.common.collect.Maps; + import com.samskivert.depot.DepotRepository; import com.samskivert.depot.PersistenceContext; import com.samskivert.depot.PersistentRecord; @@ -49,7 +51,7 @@ public class ConfigRepository extends DepotRepository */ public HashMap loadConfig (String node, String object) { - HashMap data = new HashMap(); + HashMap data = Maps.newHashMap(); Where where = new Where(ConfigRecord.OBJECT, object, ConfigRecord.NODE, node); for (ConfigRecord record : findAll(ConfigRecord.class, where)) { data.put(record.field, record.value); diff --git a/src/java/com/threerings/crowd/chat/client/ChatDirector.java b/src/java/com/threerings/crowd/chat/client/ChatDirector.java index 8fff27b4a..f32b32d44 100644 --- a/src/java/com/threerings/crowd/chat/client/ChatDirector.java +++ b/src/java/com/threerings/crowd/chat/client/ChatDirector.java @@ -31,6 +31,9 @@ import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + import com.samskivert.util.Collections; import com.samskivert.util.HashIntMap; import com.samskivert.util.ObserverList; @@ -950,7 +953,7 @@ public class ChatDirector extends BasicDirector */ protected HashMap getCommandHandlers (String command) { - HashMap matches = new HashMap(); + HashMap matches = Maps.newHashMap(); BodyObject user = (BodyObject)_ctx.getClient().getClientObject(); for (Map.Entry entry : _handlers.entrySet()) { String cmd = entry.getKey(); @@ -1436,11 +1439,10 @@ public class ChatDirector extends BasicDirector protected DisplayMessageOp _displayMessageOp = new DisplayMessageOp(); /** Registered chat command handlers. */ - protected static HashMap _handlers = - new HashMap(); + protected static HashMap _handlers = Maps.newHashMap(); /** A history of chat commands. */ - protected static ArrayList _history = new ArrayList(); + protected static ArrayList _history = Lists.newArrayList(); /** The maximum number of chatter usernames to track. */ protected static final int MAX_CHATTERS = 6; diff --git a/src/java/com/threerings/crowd/chat/client/MuteDirector.java b/src/java/com/threerings/crowd/chat/client/MuteDirector.java index edb41ba79..569c2651c 100644 --- a/src/java/com/threerings/crowd/chat/client/MuteDirector.java +++ b/src/java/com/threerings/crowd/chat/client/MuteDirector.java @@ -23,6 +23,8 @@ package com.threerings.crowd.chat.client; import java.util.HashSet; +import com.google.common.collect.Sets; + import com.samskivert.util.CollectionUtil; import com.samskivert.util.ObserverList; @@ -183,7 +185,7 @@ public class MuteDirector extends BasicDirector protected ChatDirector _chatdir; /** The mutelist. */ - protected HashSet _mutelist = new HashSet(); + protected HashSet _mutelist = Sets.newHashSet(); /** List of mutelist observers. */ protected ObserverList _observers = diff --git a/src/java/com/threerings/crowd/client/PlaceController.java b/src/java/com/threerings/crowd/client/PlaceController.java index 50796af4e..aa26dc235 100644 --- a/src/java/com/threerings/crowd/client/PlaceController.java +++ b/src/java/com/threerings/crowd/client/PlaceController.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.awt.event.ActionEvent; +import com.google.common.collect.Lists; + import com.samskivert.swing.Controller; import com.threerings.crowd.data.PlaceConfig; @@ -250,7 +252,7 @@ public abstract class PlaceController extends Controller protected void addDelegate (PlaceControllerDelegate delegate) { if (_delegates == null) { - _delegates = new ArrayList(); + _delegates = Lists.newArrayList(); } _delegates.add(delegate); } diff --git a/src/java/com/threerings/io/BasicStreamers.java b/src/java/com/threerings/io/BasicStreamers.java index 7244a0654..b911ffac9 100644 --- a/src/java/com/threerings/io/BasicStreamers.java +++ b/src/java/com/threerings/io/BasicStreamers.java @@ -28,6 +28,8 @@ import java.util.RandomAccess; import java.io.EOFException; import java.io.IOException; +import com.google.common.collect.Lists; + /** * Code to read and write basic object types (like arrays of primitives, {@link Integer} instances, * {@link Double} instances, etc.). @@ -562,7 +564,7 @@ public class BasicStreamers throws IOException, ClassNotFoundException { int ecount = ins.readInt(); - ArrayList list = new ArrayList(ecount); + ArrayList list = Lists.newArrayListWithCapacity(ecount); for (int ii = 0; ii < ecount; ii++) { list.add(ins.readObject()); } diff --git a/src/java/com/threerings/io/FieldMarshaller.java b/src/java/com/threerings/io/FieldMarshaller.java index f55df54b4..0364d3af5 100644 --- a/src/java/com/threerings/io/FieldMarshaller.java +++ b/src/java/com/threerings/io/FieldMarshaller.java @@ -28,6 +28,8 @@ import java.lang.reflect.ReflectPermission; import java.util.Date; import java.util.HashMap; +import com.google.common.collect.Maps; + import static com.threerings.NaryaLog.log; /** @@ -222,7 +224,7 @@ public abstract class FieldMarshaller protected static void createMarshallers () { // create our table - _marshallers = new HashMap, FieldMarshaller>(); + _marshallers = Maps.newHashMap(); // create a generic marshaller for streamable instances FieldMarshaller gmarsh = new FieldMarshaller() { diff --git a/src/java/com/threerings/io/ObjectInputStream.java b/src/java/com/threerings/io/ObjectInputStream.java index 8f1e6aa56..3dd641471 100644 --- a/src/java/com/threerings/io/ObjectInputStream.java +++ b/src/java/com/threerings/io/ObjectInputStream.java @@ -28,6 +28,9 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + import com.samskivert.util.StringUtil; import static com.threerings.NaryaLog.log; @@ -64,7 +67,7 @@ public class ObjectInputStream extends DataInputStream public void addTranslation (String oldname, String newname) { if (_translations == null) { - _translations = new HashMap(); + _translations = Maps.newHashMap(); } _translations.put(oldname, newname); } @@ -108,7 +111,7 @@ public class ObjectInputStream extends DataInputStream { // create our intern map if necessary if (_internmap == null) { - _internmap = new ArrayList(); + _internmap = Lists.newArrayList(); // insert a zeroth element _internmap.add(null); } @@ -168,7 +171,7 @@ public class ObjectInputStream extends DataInputStream { // create our classmap if necessary if (_classmap == null) { - _classmap = new ArrayList(); + _classmap = Lists.newArrayList(); // insert a zeroth element _classmap.add(null); } diff --git a/src/java/com/threerings/io/ObjectOutputStream.java b/src/java/com/threerings/io/ObjectOutputStream.java index 8bfb0a054..ffe57ceb0 100644 --- a/src/java/com/threerings/io/ObjectOutputStream.java +++ b/src/java/com/threerings/io/ObjectOutputStream.java @@ -21,13 +21,14 @@ package com.threerings.io; -import java.util.HashMap; import java.util.Map; import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; +import com.google.common.collect.Maps; + import static com.threerings.NaryaLog.log; /** @@ -53,7 +54,7 @@ public class ObjectOutputStream extends DataOutputStream public void addTranslation (String className, String streamedName) { if (_translations == null) { - _translations = new HashMap(); + _translations = Maps.newHashMap(); } _translations.put(className, streamedName); } @@ -91,7 +92,7 @@ public class ObjectOutputStream extends DataOutputStream // create our intern map if necessary if (_internmap == null) { - _internmap = new HashMap(); + _internmap = Maps.newHashMap(); } // look up the intern mapping record @@ -163,7 +164,7 @@ public class ObjectOutputStream extends DataOutputStream { // create our classmap if necessary if (_classmap == null) { - _classmap = new HashMap, ClassMapping>(); + _classmap = Maps.newHashMap(); } // look up the class mapping record diff --git a/src/java/com/threerings/io/Streamer.java b/src/java/com/threerings/io/Streamer.java index 11454f28e..afa5be594 100644 --- a/src/java/com/threerings/io/Streamer.java +++ b/src/java/com/threerings/io/Streamer.java @@ -30,7 +30,6 @@ import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,6 +38,7 @@ import java.io.IOException; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.samskivert.util.ClassUtil; @@ -482,7 +482,7 @@ public class Streamer */ protected static void createStreamers () { - _streamers = new HashMap, Streamer>(); + _streamers = Maps.newHashMap(); // register all of the basic streamers int bscount = BasicStreamers.BSTREAMER_TYPES.length; @@ -491,7 +491,7 @@ public class Streamer BasicStreamers.BSTREAMER_INSTANCES[ii]); } } - + /** Used to coerce the type system into quietude when reading enums from the wire. */ protected static enum EnumReader { NOT_USED }; diff --git a/src/java/com/threerings/io/UnreliableObjectOutputStream.java b/src/java/com/threerings/io/UnreliableObjectOutputStream.java index 2a403d365..953999638 100644 --- a/src/java/com/threerings/io/UnreliableObjectOutputStream.java +++ b/src/java/com/threerings/io/UnreliableObjectOutputStream.java @@ -4,12 +4,13 @@ package com.threerings.io; import java.util.Collection; -import java.util.HashSet; import java.util.Set; import java.io.IOException; import java.io.OutputStream; +import com.google.common.collect.Sets; + /** * Extends {@link ObjectOutputStream} for use in unreliable channels, where we must transmit class * mappings with every object until we are explicitly notified that the receiver has cached the @@ -193,8 +194,8 @@ public class UnreliableObjectOutputStream extends ObjectOutputStream } /** The set of classes for which we have written mappings. */ - protected Set> _mappedClasses = new HashSet>(); + protected Set> _mappedClasses = Sets.newHashSet(); /** The set of pooled strings for which we have written mappings. */ - protected Set _mappedInterns = new HashSet(); + protected Set _mappedInterns = Sets.newHashSet(); } diff --git a/src/java/com/threerings/presents/client/Client.java b/src/java/com/threerings/presents/client/Client.java index dec446449..a4e1be960 100644 --- a/src/java/com/threerings/presents/client/Client.java +++ b/src/java/com/threerings/presents/client/Client.java @@ -23,6 +23,8 @@ package com.threerings.presents.client; import java.util.HashSet; +import com.google.common.collect.Sets; + import com.samskivert.util.Interval; import com.samskivert.util.ObserverList; import com.samskivert.util.RunAnywhere; @@ -995,7 +997,7 @@ public class Client protected BootstrapData _bstrap; /** The set of bootstrap service groups this client cares about. */ - protected HashSet _bootGroups = new HashSet(); { + protected HashSet _bootGroups = Sets.newHashSet(); { _bootGroups.add(InvocationCodes.GLOBAL_GROUP); } diff --git a/src/java/com/threerings/presents/client/ClientDObjectMgr.java b/src/java/com/threerings/presents/client/ClientDObjectMgr.java index d465cff19..00b67db0c 100644 --- a/src/java/com/threerings/presents/client/ClientDObjectMgr.java +++ b/src/java/com/threerings/presents/client/ClientDObjectMgr.java @@ -28,6 +28,9 @@ import java.util.List; import java.awt.event.KeyEvent; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + import com.samskivert.util.DebugChords; import com.samskivert.util.HashIntMap; import com.samskivert.util.IntMap; @@ -491,7 +494,7 @@ public class ClientDObjectMgr protected static final class PendingRequest { public int oid; - public ArrayList> targets = new ArrayList>(); + public ArrayList> targets = Lists.newArrayList(); public PendingRequest (int oid) { @@ -542,7 +545,7 @@ public class ClientDObjectMgr protected HashIntMap> _penders = new HashIntMap>(); /** A mapping from distributed object class to flush delay. */ - protected HashMap, Long> _delays = new HashMap, Long>(); + protected HashMap, Long> _delays = Maps.newHashMap(); /** A set of objects waiting to be flushed. */ protected HashIntMap _flushes = new HashIntMap(); diff --git a/src/java/com/threerings/presents/client/InvocationDirector.java b/src/java/com/threerings/presents/client/InvocationDirector.java index a47a3a136..529f088e9 100644 --- a/src/java/com/threerings/presents/client/InvocationDirector.java +++ b/src/java/com/threerings/presents/client/InvocationDirector.java @@ -24,6 +24,8 @@ package com.threerings.presents.client; import java.util.ArrayList; import java.util.Iterator; +import com.google.common.collect.Lists; + import com.samskivert.util.HashIntMap; import com.threerings.presents.client.InvocationReceiver.Registration; @@ -424,7 +426,7 @@ public class InvocationDirector /** All registered receivers are maintained in a list so that we can assign receiver ids to * them when we go online. */ - protected ArrayList _reclist = new ArrayList(); + protected ArrayList _reclist = Lists.newArrayList(); /** The last time we flushed our listeners. */ protected long _lastFlushTime; diff --git a/src/java/com/threerings/presents/dobj/DynamicListener.java b/src/java/com/threerings/presents/dobj/DynamicListener.java index 5b821e47e..3d75eeb3b 100644 --- a/src/java/com/threerings/presents/dobj/DynamicListener.java +++ b/src/java/com/threerings/presents/dobj/DynamicListener.java @@ -25,6 +25,8 @@ import java.lang.reflect.Method; import java.util.HashMap; +import com.google.common.collect.Maps; + import com.samskivert.util.MethodFinder; import com.samskivert.util.StringUtil; @@ -139,5 +141,5 @@ public class DynamicListener protected MethodFinder _finder; /** A cache of already resolved methods. */ - protected HashMap _mcache = new HashMap(); + protected HashMap _mcache = Maps.newHashMap(); } diff --git a/src/java/com/threerings/presents/peer/util/PeerUtil.java b/src/java/com/threerings/presents/peer/util/PeerUtil.java index 479810153..5dffe4d4f 100644 --- a/src/java/com/threerings/presents/peer/util/PeerUtil.java +++ b/src/java/com/threerings/presents/peer/util/PeerUtil.java @@ -27,6 +27,8 @@ import java.lang.reflect.Proxy; import java.util.HashMap; +import com.google.common.collect.Maps; + import com.threerings.presents.client.Client; import com.threerings.presents.client.InvocationService; import com.threerings.presents.server.InvocationProvider; @@ -70,5 +72,5 @@ public class PeerUtil } /** Maps provider interface methods to service interface methods. */ - protected static HashMap _pmethods = new HashMap(); + protected static HashMap _pmethods = Maps.newHashMap(); } diff --git a/src/java/com/threerings/presents/server/TimeBaseProvider.java b/src/java/com/threerings/presents/server/TimeBaseProvider.java index c56712ef4..998e279e7 100644 --- a/src/java/com/threerings/presents/server/TimeBaseProvider.java +++ b/src/java/com/threerings/presents/server/TimeBaseProvider.java @@ -23,6 +23,8 @@ package com.threerings.presents.server; import java.util.HashMap; +import com.google.common.collect.Maps; + import com.threerings.presents.client.TimeBaseService.GotTimeBaseListener; import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.TimeBaseCodes; @@ -91,8 +93,7 @@ public class TimeBaseProvider } /** Used to keep track of our time base objects. */ - protected static HashMap _timeBases = - new HashMap(); + protected static HashMap _timeBases = Maps.newHashMap(); /** The invocation manager with which we interoperate. */ protected static InvocationManager _invmgr; diff --git a/src/java/com/threerings/presents/tools/ActionScriptSource.java b/src/java/com/threerings/presents/tools/ActionScriptSource.java index bca0669af..a19e1bd14 100644 --- a/src/java/com/threerings/presents/tools/ActionScriptSource.java +++ b/src/java/com/threerings/presents/tools/ActionScriptSource.java @@ -36,6 +36,8 @@ import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; +import com.google.common.collect.Lists; + import com.samskivert.util.StringUtil; import com.threerings.util.ActionScript; @@ -116,25 +118,25 @@ public class ActionScriptSource public String[] implementedInterfaces; - public ArrayList publicConstants = new ArrayList(); + public ArrayList publicConstants = Lists.newArrayList(); - public ArrayList publicFields = new ArrayList(); + public ArrayList publicFields = Lists.newArrayList(); - public ArrayList publicStaticMethods = new ArrayList(); + public ArrayList publicStaticMethods = Lists.newArrayList(); - public ArrayList publicConstructors = new ArrayList(); + public ArrayList publicConstructors = Lists.newArrayList(); - public ArrayList publicMethods = new ArrayList(); + public ArrayList publicMethods = Lists.newArrayList(); - public ArrayList protectedConstructors = new ArrayList(); + public ArrayList protectedConstructors = Lists.newArrayList(); - public ArrayList protectedMethods = new ArrayList(); + public ArrayList protectedMethods = Lists.newArrayList(); - public ArrayList protectedStaticMethods = new ArrayList(); + public ArrayList protectedStaticMethods = Lists.newArrayList(); - public ArrayList protectedFields = new ArrayList(); + public ArrayList protectedFields = Lists.newArrayList(); - public ArrayList protectedConstants = new ArrayList(); + public ArrayList protectedConstants = Lists.newArrayList(); public static String toSimpleName (String name) { @@ -306,7 +308,7 @@ public class ActionScriptSource isAbstract = ((jclass.getModifiers() & Modifier.ABSTRACT) != 0); // note our implemented interfaces - ArrayList ifaces = new ArrayList(); + ArrayList ifaces = Lists.newArrayList(); for (Class iclass : jclass.getInterfaces()) { // we cannot use the FooCodes interface pattern in ActionScript so we just nix it if (iclass.getName().endsWith("Codes")) { diff --git a/src/java/com/threerings/presents/tools/GenActionScriptBundlesTask.java b/src/java/com/threerings/presents/tools/GenActionScriptBundlesTask.java index feccbee9a..bebe38f24 100644 --- a/src/java/com/threerings/presents/tools/GenActionScriptBundlesTask.java +++ b/src/java/com/threerings/presents/tools/GenActionScriptBundlesTask.java @@ -36,6 +36,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; + /** * Generates our own ResourceBundle classes. * @@ -62,9 +64,9 @@ public class GenActionScriptBundlesTask extends Task DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); - for (int f = 0; f < srcFiles.length; f++) { + for (String srcFile : srcFiles) { try { - processBundle(new File(fromDir, srcFiles[f])); + processBundle(new File(fromDir, srcFile)); } catch (IOException ioe) { throw new BuildException(ioe); } @@ -162,7 +164,7 @@ public class GenActionScriptBundlesTask extends Task return buf.toString(); } - protected ArrayList _filesets = new ArrayList(); + protected ArrayList _filesets = Lists.newArrayList(); protected File _asroot; } diff --git a/src/java/com/threerings/presents/tools/GenActionScriptTask.java b/src/java/com/threerings/presents/tools/GenActionScriptTask.java index bbcf71eb8..09107a674 100644 --- a/src/java/com/threerings/presents/tools/GenActionScriptTask.java +++ b/src/java/com/threerings/presents/tools/GenActionScriptTask.java @@ -40,6 +40,8 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.velocity.app.VelocityEngine; +import com.google.common.collect.Lists; + import com.samskivert.velocity.VelocityUtil; import com.threerings.io.Streamable; @@ -99,8 +101,8 @@ public class GenActionScriptTask extends Task DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); - for (int f = 0; f < srcFiles.length; f++) { - processClass(new File(fromDir, srcFiles[f])); + for (String srcFile : srcFiles) { + processClass(new File(fromDir, srcFile)); } } } @@ -338,7 +340,7 @@ public class GenActionScriptTask extends Task } /** A list of filesets that contain tile images. */ - protected ArrayList _filesets = new ArrayList(); + protected ArrayList _filesets = Lists.newArrayList(); /** A header to put on all generated source files. */ protected String _header; diff --git a/src/java/com/threerings/presents/tools/GenDObjectTask.java b/src/java/com/threerings/presents/tools/GenDObjectTask.java index 559344700..9a686e4a4 100644 --- a/src/java/com/threerings/presents/tools/GenDObjectTask.java +++ b/src/java/com/threerings/presents/tools/GenDObjectTask.java @@ -43,6 +43,8 @@ import org.apache.tools.ant.util.ClasspathUtils; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; +import com.google.common.collect.Lists; + import com.samskivert.util.StringUtil; import com.samskivert.velocity.VelocityUtil; @@ -151,7 +153,7 @@ public class GenDObjectTask extends Task } // determine which fields we need to deal with - ArrayList flist = new ArrayList(); + ArrayList flist = Lists.newArrayList(); Field[] fields = oclass.getDeclaredFields(); for (Field f : fields) { int mods = f.getModifiers(); @@ -270,7 +272,7 @@ public class GenDObjectTask extends Task } /** A list of filesets that contain tile images. */ - protected ArrayList _filesets = new ArrayList(); + protected ArrayList _filesets = Lists.newArrayList(); /** Used to do our own classpath business. */ protected ClassLoader _cloader; diff --git a/src/java/com/threerings/presents/tools/GenServiceTask.java b/src/java/com/threerings/presents/tools/GenServiceTask.java index 162decd91..e0e0543d8 100644 --- a/src/java/com/threerings/presents/tools/GenServiceTask.java +++ b/src/java/com/threerings/presents/tools/GenServiceTask.java @@ -33,6 +33,7 @@ import org.apache.velocity.VelocityContext; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; import com.samskivert.util.ComparableArrayList; import com.samskivert.util.StringUtil; @@ -74,8 +75,7 @@ public class GenServiceTask extends InvocationTask { this.listener = listener; Method[] methdecls = listener.getDeclaredMethods(); - for (int ii = 0; ii < methdecls.length; ii++) { - Method m = methdecls[ii]; + for (Method m : methdecls) { // service interface methods must be public and abstract if (!Modifier.isPublic(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) { @@ -620,8 +620,7 @@ public class GenServiceTask extends InvocationTask // look through and locate our service methods, also locating any // custom InvocationListener derivations along the way Method[] methdecls = service.getDeclaredMethods(); - for (int ii = 0; ii < methdecls.length; ii++) { - Method m = methdecls[ii]; + for (Method m : methdecls) { // service interface methods must be public and abstract if (!Modifier.isPublic(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) { @@ -629,10 +628,10 @@ public class GenServiceTask extends InvocationTask } // check this method for custom listener declarations Class[] args = m.getParameterTypes(); - for (int aa = 0; aa < args.length; aa++) { - if (_ilistener.isAssignableFrom(args[aa]) && - GenUtil.simpleName(args[aa]).startsWith(sname + ".")) { - checkedAdd(listeners, new ServiceListener(service, args[aa])); + for (Class arg : args) { + if (_ilistener.isAssignableFrom(arg) && + GenUtil.simpleName(arg).startsWith(sname + ".")) { + checkedAdd(listeners, new ServiceListener(service, arg)); } } if (_verbose) { @@ -678,7 +677,7 @@ public class GenServiceTask extends InvocationTask protected File _asroot; /** Services for which we should not generate provider interfaces. */ - protected HashSet _providerless = new HashSet(); + protected HashSet _providerless = Sets.newHashSet(); /** Specifies the path to the marshaller template. */ protected static final String MARSHALLER_TMPL = diff --git a/src/java/com/threerings/presents/tools/GenStreamableTask.java b/src/java/com/threerings/presents/tools/GenStreamableTask.java index 93e1245ed..96fae4d26 100644 --- a/src/java/com/threerings/presents/tools/GenStreamableTask.java +++ b/src/java/com/threerings/presents/tools/GenStreamableTask.java @@ -33,6 +33,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.io.SimpleStreamableObject; import com.threerings.io.Streamable; @@ -60,8 +62,8 @@ public class GenStreamableTask extends Task DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); - for (int f = 0; f < srcFiles.length; f++) { - processClass(new File(fromDir, srcFiles[f])); + for (String srcFile : srcFiles) { + processClass(new File(fromDir, srcFile)); } } } @@ -243,7 +245,7 @@ public class GenStreamableTask extends Task } /** A list of filesets that contain tile images. */ - protected ArrayList _filesets = new ArrayList(); + protected ArrayList _filesets = Lists.newArrayList(); protected static final String READ_OPEN = " // from interface Streamable\n" + diff --git a/src/java/com/threerings/presents/tools/ImportSet.java b/src/java/com/threerings/presents/tools/ImportSet.java index b4b28721d..20ee9f7ee 100644 --- a/src/java/com/threerings/presents/tools/ImportSet.java +++ b/src/java/com/threerings/presents/tools/ImportSet.java @@ -21,12 +21,14 @@ package com.threerings.presents.tools; -import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + import com.samskivert.util.ComparableArrayList; import com.samskivert.util.StringUtil; @@ -247,7 +249,7 @@ public class ImportSet */ public void replace (String... replace) { - HashSet toAdd = new HashSet(); + HashSet toAdd = Sets.newHashSet(); Iterator i = _imports.iterator(); while (i.hasNext()) { String name = i.next(); @@ -292,7 +294,7 @@ public class ImportSet public void duplicateAndMunge (String pattern, String... replace) { Pattern pat = makePattern(pattern); - HashSet toMunge = new HashSet(); + HashSet toMunge = Sets.newHashSet(); for (String name : _imports) { if (pat.matcher(name).matches()) { toMunge.add(name); @@ -355,8 +357,8 @@ public class ImportSet return Pattern.compile(pattern.toString()); } - protected HashSet _imports = new HashSet(); - protected List _pushed = new ArrayList(); + protected HashSet _imports = Sets.newHashSet(); + protected List _pushed = Lists.newArrayList(); protected static Pattern _splitter = Pattern.compile("\\*"); } diff --git a/src/java/com/threerings/presents/tools/InstrumentStreamableTask.java b/src/java/com/threerings/presents/tools/InstrumentStreamableTask.java index 959c2f4b6..b34db0941 100644 --- a/src/java/com/threerings/presents/tools/InstrumentStreamableTask.java +++ b/src/java/com/threerings/presents/tools/InstrumentStreamableTask.java @@ -45,6 +45,9 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + import com.samskivert.io.StreamUtil; import com.threerings.io.BasicStreamers; @@ -107,8 +110,8 @@ public class InstrumentStreamableTask extends Task DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); - for (int f = 0; f < srcFiles.length; f++) { - processClass(new File(fromDir, srcFiles[f])); + for (String srcFile : srcFiles) { + processClass(new File(fromDir, srcFile)); } } } @@ -145,7 +148,7 @@ public class InstrumentStreamableTask extends Task protected void processStreamable (File source, CtClass clazz) throws NotFoundException { - ArrayList fields = new ArrayList(); + ArrayList fields = Lists.newArrayList(); for (CtField field : clazz.getDeclaredFields()) { int modifiers = field.getModifiers(); if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || @@ -155,7 +158,7 @@ public class InstrumentStreamableTask extends Task fields.add(field); } - HashSet methods = new HashSet(); + HashSet methods = Sets.newHashSet(); for (CtMethod method : clazz.getMethods()) { methods.add(method.getName()); } @@ -337,10 +340,10 @@ public class InstrumentStreamableTask extends Task } /** A list of filesets that contain Streamable class files. */ - protected ArrayList _filesets = new ArrayList(); + protected ArrayList _filesets = Lists.newArrayList(); /** A list of paths that make up our classpath. */ - protected ArrayList _paths = new ArrayList(); + protected ArrayList _paths = Lists.newArrayList(); /** The directory to which we write our instrumented class files. */ protected File _outdir; diff --git a/src/java/com/threerings/presents/tools/InvocationTask.java b/src/java/com/threerings/presents/tools/InvocationTask.java index 03bfe1473..52c0f990d 100644 --- a/src/java/com/threerings/presents/tools/InvocationTask.java +++ b/src/java/com/threerings/presents/tools/InvocationTask.java @@ -27,7 +27,6 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -48,6 +47,7 @@ import org.apache.velocity.app.VelocityEngine; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; import com.samskivert.util.Logger; import com.samskivert.util.StringUtil; @@ -105,7 +105,7 @@ public abstract class InvocationTask extends Task { public Method method; - public List listenerArgs = new ArrayList(); + public List listenerArgs = Lists.newArrayList(); /** * Creates a new service method. @@ -461,7 +461,7 @@ public abstract class InvocationTask extends Task } /** A list of filesets that contain tile images. */ - protected List _filesets = new ArrayList(); + protected List _filesets = Lists.newArrayList(); /** A header to put on all generated source files. */ protected String _header; diff --git a/src/java/com/threerings/presents/tools/SourceFile.java b/src/java/com/threerings/presents/tools/SourceFile.java index 4c32b676a..451aadf4a 100644 --- a/src/java/com/threerings/presents/tools/SourceFile.java +++ b/src/java/com/threerings/presents/tools/SourceFile.java @@ -30,6 +30,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import com.google.common.collect.Lists; + import com.samskivert.util.StringUtil; /** @@ -46,7 +48,7 @@ public class SourceFile { // slurp our source file into newline separated strings BufferedReader bin = new BufferedReader(new FileReader(source)); - ArrayList llist = new ArrayList(); + ArrayList llist = Lists.newArrayList(); String line = null; while ((line = bin.readLine()) != null) { llist.add(line); diff --git a/src/java/com/threerings/presents/util/DatagramSequencer.java b/src/java/com/threerings/presents/util/DatagramSequencer.java index 2f088f12f..b683caa2e 100644 --- a/src/java/com/threerings/presents/util/DatagramSequencer.java +++ b/src/java/com/threerings/presents/util/DatagramSequencer.java @@ -27,6 +27,7 @@ import java.util.Set; import java.io.IOException; +import com.google.common.collect.Lists; import com.threerings.io.UnreliableObjectInputStream; import com.threerings.io.UnreliableObjectOutputStream; @@ -72,6 +73,7 @@ public class DatagramSequencer mappedClasses = null; } else { _uout.setMappedClasses(new HashSet>()); + } // likewise with the intern mappings @@ -79,6 +81,7 @@ public class DatagramSequencer mappedInterns = null; } else { _uout.setMappedInterns(new HashSet()); + } // record the transmission @@ -164,5 +167,5 @@ public class DatagramSequencer protected int _lastReceived; /** Records of datagrams sent. */ - protected ArrayList _sendrecs = new ArrayList(); + protected ArrayList _sendrecs = Lists.newArrayList(); } diff --git a/src/java/com/threerings/util/DependencyGraph.java b/src/java/com/threerings/util/DependencyGraph.java index ab941cac4..cbf272938 100644 --- a/src/java/com/threerings/util/DependencyGraph.java +++ b/src/java/com/threerings/util/DependencyGraph.java @@ -3,6 +3,9 @@ package com.threerings.util; import java.util.ArrayList; import java.util.HashMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + /** * Maintains a bidirectional graph to manage the order that the items are removed. Children * must wait until their parents are accessed - thus removing an available element means that @@ -96,8 +99,8 @@ public class DependencyGraph DependencyNode node1 = _nodes.get(elem1); DependencyNode node2 = _nodes.get(elem2); - ArrayList> nodesToCheck = new ArrayList>(); - ArrayList> nodesAlreadyChecked = new ArrayList>(); + ArrayList> nodesToCheck = Lists.newArrayList(); + ArrayList> nodesAlreadyChecked = Lists.newArrayList(); nodesToCheck.addAll(node1.parents); // We prevent circular dependencies when we add dependencies. Otherwise, this'd be @@ -124,10 +127,10 @@ public class DependencyGraph } /** All the nodes included in the graph. */ - protected HashMap> _nodes = new HashMap>(); + protected HashMap> _nodes = Maps.newHashMap(); /** Nodes in the graph with no parents/dependencies. */ - protected ArrayList _orphans = new ArrayList(); + protected ArrayList _orphans = Lists.newArrayList(); /** Represents a node in our dependency graph. */ protected class DependencyNode
@@ -139,8 +142,8 @@ public class DependencyGraph public DependencyNode (DT contents) { this.content = contents; - this.parents = new ArrayList>(); - this.children = new ArrayList>(); + this.parents = Lists.newArrayList(); + this.children = Lists.newArrayList(); } } } diff --git a/src/java/com/threerings/util/MessageManager.java b/src/java/com/threerings/util/MessageManager.java index 260317466..48ddb181d 100644 --- a/src/java/com/threerings/util/MessageManager.java +++ b/src/java/com/threerings/util/MessageManager.java @@ -26,6 +26,8 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import com.google.common.collect.Maps; + import com.samskivert.util.StringUtil; import static com.threerings.NaryaLog.log; @@ -195,7 +197,7 @@ public class MessageManager protected ClassLoader _loader; /** A cache of instantiated message bundles. */ - protected HashMap _cache = new HashMap(); + protected HashMap _cache = Maps.newHashMap(); /** Our top-level message bundle, from which others obtain messages if * they can't find them within themselves. */ diff --git a/src/java/com/threerings/util/TimeUtil.java b/src/java/com/threerings/util/TimeUtil.java index 2674b4213..143fd5927 100644 --- a/src/java/com/threerings/util/TimeUtil.java +++ b/src/java/com/threerings/util/TimeUtil.java @@ -23,6 +23,8 @@ package com.threerings.util; import java.util.ArrayList; +import com.google.common.collect.Lists; + /** * Utility for times. */ @@ -104,7 +106,7 @@ public class TimeUtil minUnit = (byte) Math.min(minUnit, MAX_UNIT); duration = Math.abs(duration); - ArrayList list = new ArrayList(); + ArrayList list = Lists.newArrayList(); int parts = 0; // how many parts are in the translation string? for (byte uu = MILLISECOND; uu <= MAX_UNIT; uu++) { int quantity = getQuantityPerUnit(uu);