A healthy dash of google-collections

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5798 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Dave Hoover
2009-05-23 01:04:08 +00:00
parent 1bdb2cae16
commit b222eed2fd
34 changed files with 152 additions and 91 deletions
@@ -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<String> _bootGroups = new HashSet<String>(); {
protected HashSet<String> _bootGroups = Sets.newHashSet(); {
_bootGroups.add(InvocationCodes.GLOBAL_GROUP);
}
@@ -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<T extends DObject>
{
public int oid;
public ArrayList<Subscriber<T>> targets = new ArrayList<Subscriber<T>>();
public ArrayList<Subscriber<T>> targets = Lists.newArrayList();
public PendingRequest (int oid)
{
@@ -542,7 +545,7 @@ public class ClientDObjectMgr
protected HashIntMap<PendingRequest<?>> _penders = new HashIntMap<PendingRequest<?>>();
/** A mapping from distributed object class to flush delay. */
protected HashMap<Class<?>, Long> _delays = new HashMap<Class<?>, Long>();
protected HashMap<Class<?>, Long> _delays = Maps.newHashMap();
/** A set of objects waiting to be flushed. */
protected HashIntMap<FlushRecord> _flushes = new HashIntMap<FlushRecord>();
@@ -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<InvocationDecoder> _reclist = new ArrayList<InvocationDecoder>();
protected ArrayList<InvocationDecoder> _reclist = Lists.newArrayList();
/** The last time we flushed our listeners. */
protected long _lastFlushTime;
@@ -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<T extends DSet.Entry>
protected MethodFinder _finder;
/** A cache of already resolved methods. */
protected HashMap<String, Method> _mcache = new HashMap<String, Method>();
protected HashMap<String, Method> _mcache = Maps.newHashMap();
}
@@ -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<Method, Method> _pmethods = new HashMap<Method, Method>();
protected static HashMap<Method, Method> _pmethods = Maps.newHashMap();
}
@@ -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<String,TimeBaseObject> _timeBases =
new HashMap<String,TimeBaseObject>();
protected static HashMap<String,TimeBaseObject> _timeBases = Maps.newHashMap();
/** The invocation manager with which we interoperate. */
protected static InvocationManager _invmgr;
@@ -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<Member> publicConstants = new ArrayList<Member>();
public ArrayList<Member> publicConstants = Lists.newArrayList();
public ArrayList<Member> publicFields = new ArrayList<Member>();
public ArrayList<Member> publicFields = Lists.newArrayList();
public ArrayList<Member> publicStaticMethods = new ArrayList<Member>();
public ArrayList<Member> publicStaticMethods = Lists.newArrayList();
public ArrayList<Member> publicConstructors = new ArrayList<Member>();
public ArrayList<Member> publicConstructors = Lists.newArrayList();
public ArrayList<Member> publicMethods = new ArrayList<Member>();
public ArrayList<Member> publicMethods = Lists.newArrayList();
public ArrayList<Member> protectedConstructors = new ArrayList<Member>();
public ArrayList<Member> protectedConstructors = Lists.newArrayList();
public ArrayList<Member> protectedMethods = new ArrayList<Member>();
public ArrayList<Member> protectedMethods = Lists.newArrayList();
public ArrayList<Member> protectedStaticMethods = new ArrayList<Member>();
public ArrayList<Member> protectedStaticMethods = Lists.newArrayList();
public ArrayList<Member> protectedFields = new ArrayList<Member>();
public ArrayList<Member> protectedFields = Lists.newArrayList();
public ArrayList<Member> protectedConstants = new ArrayList<Member>();
public ArrayList<Member> 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<String> ifaces = new ArrayList<String>();
ArrayList<String> 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")) {
@@ -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<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
protected File _asroot;
}
@@ -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<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
/** A header to put on all generated source files. */
protected String _header;
@@ -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<Field> flist = new ArrayList<Field>();
ArrayList<Field> 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<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
/** Used to do our own classpath business. */
protected ClassLoader _cloader;
@@ -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<String> _providerless = new HashSet<String>();
protected HashSet<String> _providerless = Sets.newHashSet();
/** Specifies the path to the marshaller template. */
protected static final String MARSHALLER_TMPL =
@@ -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<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
protected static final String READ_OPEN =
" // from interface Streamable\n" +
@@ -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<String> toAdd = new HashSet<String>();
HashSet<String> toAdd = Sets.newHashSet();
Iterator<String> 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<String> toMunge = new HashSet<String>();
HashSet<String> 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<String> _imports = new HashSet<String>();
protected List<String> _pushed = new ArrayList<String>();
protected HashSet<String> _imports = Sets.newHashSet();
protected List<String> _pushed = Lists.newArrayList();
protected static Pattern _splitter = Pattern.compile("\\*");
}
@@ -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<CtField> fields = new ArrayList<CtField>();
ArrayList<CtField> 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<String> methods = new HashSet<String>();
HashSet<String> 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<FileSet> _filesets = new ArrayList<FileSet>();
protected ArrayList<FileSet> _filesets = Lists.newArrayList();
/** A list of paths that make up our classpath. */
protected ArrayList<Path> _paths = new ArrayList<Path>();
protected ArrayList<Path> _paths = Lists.newArrayList();
/** The directory to which we write our instrumented class files. */
protected File _outdir;
@@ -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<ListenerArgument> listenerArgs = new ArrayList<ListenerArgument>();
public List<ListenerArgument> 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<FileSet> _filesets = new ArrayList<FileSet>();
protected List<FileSet> _filesets = Lists.newArrayList();
/** A header to put on all generated source files. */
protected String _header;
@@ -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<String> llist = new ArrayList<String>();
ArrayList<String> llist = Lists.newArrayList();
String line = null;
while ((line = bin.readLine()) != null) {
llist.add(line);
@@ -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<Class<?>>());
}
// likewise with the intern mappings
@@ -79,6 +81,7 @@ public class DatagramSequencer
mappedInterns = null;
} else {
_uout.setMappedInterns(new HashSet<String>());
}
// record the transmission
@@ -164,5 +167,5 @@ public class DatagramSequencer
protected int _lastReceived;
/** Records of datagrams sent. */
protected ArrayList<SendRecord> _sendrecs = new ArrayList<SendRecord>();
protected ArrayList<SendRecord> _sendrecs = Lists.newArrayList();
}