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
@@ -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<Object> list = new ArrayList<Object>(ecount);
ArrayList<Object> list = Lists.newArrayListWithCapacity(ecount);
for (int ii = 0; ii < ecount; ii++) {
list.add(ins.readObject());
}
@@ -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<Class<?>, FieldMarshaller>();
_marshallers = Maps.newHashMap();
// create a generic marshaller for streamable instances
FieldMarshaller gmarsh = new FieldMarshaller() {
@@ -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<String, String>();
_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<String>();
_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<ClassMapping>();
_classmap = Lists.newArrayList();
// insert a zeroth element
_classmap.add(null);
}
@@ -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<String, String>();
_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<String, Short>();
_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<Class<?>, ClassMapping>();
_classmap = Maps.newHashMap();
}
// look up the class mapping record
+3 -3
View File
@@ -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<Class<?>, 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 };
@@ -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<Class<?>> _mappedClasses = new HashSet<Class<?>>();
protected Set<Class<?>> _mappedClasses = Sets.newHashSet();
/** The set of pooled strings for which we have written mappings. */
protected Set<String> _mappedInterns = new HashSet<String>();
protected Set<String> _mappedInterns = Sets.newHashSet();
}