More type safety.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4244 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-07-05 00:51:22 +00:00
parent a89473d1b5
commit 94b79826d4
9 changed files with 59 additions and 54 deletions
@@ -17,7 +17,7 @@ import com.threerings.presents.dobj.Subscriber;
public class ConfigObjectManager implements AdminService.ConfigInfoListener public class ConfigObjectManager implements AdminService.ConfigInfoListener
{ {
public ConfigObjectManager(Client client) { public ConfigObjectManager(Client client) {
_serverconfig = new HashMap(); _serverconfig = new HashMap<String,ConfigObject>();
_client = client; _client = client;
_client.addClientObserver(new SessionObserver() { _client.addClientObserver(new SessionObserver() {
// documentation inherited from interface SessionObserver // documentation inherited from interface SessionObserver
@@ -63,21 +63,21 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
// documentation inherited from interface AdminService.ConfigInfoListener // documentation inherited from interface AdminService.ConfigInfoListener
public void requestFailed (String reason) { public void requestFailed (String reason) {
Log.warning("Oh bugger, we didn't get the config data because " + reason); Log.warning("Oh bugger, we didn't get the config data: " + reason);
} }
/** /**
* Returns the ConfigObject identified by the given key * Returns the ConfigObject identified by the given key
*/ */
public ConfigObject getServerConfig (String key) { public ConfigObject getServerConfig (String key) {
return (ConfigObject)_serverconfig.get(key); return _serverconfig.get(key);
} }
/** /**
* This class takes care of the details of subscribing to and placing * This class takes care of the details of subscribing to and placing
* an individual ConfigObject that the server knows about into a HashMap * an individual ConfigObject that the server knows about into a HashMap
*/ */
protected class ConfigObjectSubscriber implements Subscriber protected class ConfigObjectSubscriber implements Subscriber<ConfigObject>
{ {
/** /**
* This method requests that we place a subscription to the * This method requests that we place a subscription to the
@@ -91,8 +91,8 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
} }
// documentation inherited from interface Subscriber // documentation inherited from interface Subscriber
public void objectAvailable (DObject object) { public void objectAvailable (ConfigObject object) {
_cobj = (ConfigObject)object; _cobj = object;
_serverconfig.put(_key, _cobj); _serverconfig.put(_key, _cobj);
} }
@@ -126,7 +126,7 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener
protected ConfigObjectSubscriber[] _csubscribers; protected ConfigObjectSubscriber[] _csubscribers;
/** Our local copy of the server-side runtime configuration */ /** Our local copy of the server-side runtime configuration */
protected HashMap _serverconfig; protected HashMap<String,ConfigObject> _serverconfig;
/** Our distributed object manager */ /** Our distributed object manager */
protected DObjectManager _dobjmgr; protected DObjectManager _dobjmgr;
@@ -124,7 +124,7 @@ public class DSetEditor extends JPanel
*/ */
public DSet.Entry getSelectedEntry () public DSet.Entry getSelectedEntry ()
{ {
return (DSet.Entry) _table.getSelectedObject(); return (DSet.Entry)_table.getSelectedObject();
} }
// documentation inherited // documentation inherited
@@ -159,7 +159,9 @@ public class DSetEditor extends JPanel
{ {
if (event.getName().equals(_setName)) { if (event.getName().equals(_setName)) {
DSet.Entry entry = event.getEntry(); DSet.Entry entry = event.getEntry();
int index = _keys.insertSorted(entry.getKey()); @SuppressWarnings("unchecked") Comparable<Object> key =
(Comparable<Object>)entry.getKey();
int index = _keys.insertSorted(key);
_table.insertDatum(entry, index); _table.insertDatum(entry, index);
} }
} }
@@ -204,11 +206,13 @@ public class DSetEditor extends JPanel
protected void refreshData () protected void refreshData ()
{ {
_keys = new ComparableArrayList(); _keys = new ComparableArrayList<Comparable<Object>>();
DSet.Entry[] entries = new DSet.Entry[_set.size()]; DSet.Entry[] entries = new DSet.Entry[_set.size()];
_set.toArray(entries); _set.toArray(entries);
for (int ii=0; ii < entries.length; ii++) { for (int ii = 0; ii < entries.length; ii++) {
_keys.insertSorted(entries[ii].getKey()); @SuppressWarnings("unchecked") Comparable<Object> key =
(Comparable<Object>)entries[ii].getKey();
_keys.insertSorted(key);
} }
_table.setData(entries); // this works because DSet itself is sorted _table.setData(entries); // this works because DSet itself is sorted
} }
@@ -220,10 +224,10 @@ public class DSetEditor extends JPanel
protected String _setName; protected String _setName;
/** The set itself. */ /** The set itself. */
protected DSet _set; protected DSet<?> _set;
/** An array we use to track our entries' positions by key. */ /** An array we use to track our entries' positions by key. */
protected ComparableArrayList _keys; protected ComparableArrayList<Comparable<Object>> _keys;
/** The table used to edit. */ /** The table used to edit. */
protected ObjectEditorTable _table; protected ObjectEditorTable _table;
@@ -51,7 +51,7 @@ import com.threerings.admin.data.ConfigObject;
* @see ConfigEditorPanel * @see ConfigEditorPanel
*/ */
public class ObjectEditorPanel extends ScrollablePanel public class ObjectEditorPanel extends ScrollablePanel
implements Subscriber implements Subscriber<ConfigObject>
{ {
/** /**
* Creates an object editor panel for the specified configuration * Creates an object editor panel for the specified configuration
@@ -69,7 +69,7 @@ public class ObjectEditorPanel extends ScrollablePanel
// we'll use this to safely subscribe to and unsubscribe from the // we'll use this to safely subscribe to and unsubscribe from the
// config object // config object
_safesub = new SafeSubscriber(oid, this); _safesub = new SafeSubscriber<ConfigObject>(oid, this);
_safesub.subscribe(_ctx.getDObjectManager()); _safesub.subscribe(_ctx.getDObjectManager());
} }
@@ -94,10 +94,10 @@ public class ObjectEditorPanel extends ScrollablePanel
} }
// documentation inherited from interface // documentation inherited from interface
public void objectAvailable (DObject object) public void objectAvailable (ConfigObject object)
{ {
// keep this for later // keep this for later
_object = (ConfigObject)object; _object = object;
// create our field editors // create our field editors
try { try {
@@ -125,6 +125,6 @@ public class ObjectEditorPanel extends ScrollablePanel
protected PresentsContext _ctx; protected PresentsContext _ctx;
protected String _key; protected String _key;
protected SafeSubscriber _safesub; protected SafeSubscriber<ConfigObject> _safesub;
protected ConfigObject _object; protected ConfigObject _object;
} }
@@ -98,7 +98,7 @@ public abstract class ConfigRegistry
*/ */
public DObject getObject (String key) public DObject getObject (String key)
{ {
ObjectRecord record = (ObjectRecord)_configs.get(key); ObjectRecord record = _configs.get(key);
return (record == null) ? null : record.object; return (record == null) ? null : record.object;
} }
@@ -108,7 +108,7 @@ public abstract class ConfigRegistry
*/ */
public String[] getKeys () public String[] getKeys ()
{ {
return (String[])_configs.keySet().toArray(new String[_configs.size()]); return _configs.keySet().toArray(new String[_configs.size()]);
} }
/** /**
@@ -365,7 +365,8 @@ public abstract class ConfigRegistry
} }
/** A mapping from identifying key to config object. */ /** A mapping from identifying key to config object. */
protected HashMap _configs = new HashMap(); protected HashMap<String,ObjectRecord> _configs =
new HashMap<String,ObjectRecord>();
protected static final int[] INT_ARRAY_PROTO = new int[0]; protected static final int[] INT_ARRAY_PROTO = new int[0];
protected static final float[] FLOAT_ARRAY_PROTO = new float[0]; protected static final float[] FLOAT_ARRAY_PROTO = new float[0];
@@ -86,14 +86,14 @@ public class DatabaseConfigRegistry extends ConfigRegistry
Log.warning("Failed to load object configuration " + Log.warning("Failed to load object configuration " +
"[path=" + _path + "]."); "[path=" + _path + "].");
Log.logStackTrace(pe); Log.logStackTrace(pe);
_data = new HashMap(); _data = new HashMap<String,String>();
} }
super.init(); super.init();
} }
protected boolean getValue (String field, boolean defval) { protected boolean getValue (String field, boolean defval) {
String value = (String)_data.get(field); String value = _data.get(field);
if (value != null) { if (value != null) {
return "true".equalsIgnoreCase(value); return "true".equalsIgnoreCase(value);
} }
@@ -101,7 +101,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected short getValue (String field, short defval) { protected short getValue (String field, short defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
return Short.parseShort(value); return Short.parseShort(value);
@@ -113,7 +113,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected int getValue (String field, int defval) { protected int getValue (String field, int defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
return Integer.parseInt(value); return Integer.parseInt(value);
@@ -125,7 +125,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected long getValue (String field, long defval) { protected long getValue (String field, long defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
return Long.parseLong(value); return Long.parseLong(value);
@@ -137,7 +137,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected float getValue (String field, float defval) { protected float getValue (String field, float defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
return Float.parseFloat(value); return Float.parseFloat(value);
@@ -149,12 +149,12 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected String getValue (String field, String defval) { protected String getValue (String field, String defval) {
String value = (String)_data.get(field); String value = _data.get(field);
return (value == null) ? defval : value; return (value == null) ? defval : value;
} }
protected int[] getValue (String field, int[] defval) { protected int[] getValue (String field, int[] defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
int[] avalue = StringUtil.parseIntArray(value); int[] avalue = StringUtil.parseIntArray(value);
@@ -169,7 +169,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected float[] getValue (String field, float[] defval) { protected float[] getValue (String field, float[] defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
float[] avalue = StringUtil.parseFloatArray(value); float[] avalue = StringUtil.parseFloatArray(value);
@@ -184,7 +184,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected long[] getValue (String field, long[] defval) { protected long[] getValue (String field, long[] defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
long[] avalue = StringUtil.parseLongArray(value); long[] avalue = StringUtil.parseLongArray(value);
@@ -199,7 +199,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected String[] getValue (String field, String[] defval) { protected String[] getValue (String field, String[] defval) {
String value = (String)_data.get(field); String value = _data.get(field);
try { try {
if (value != null) { if (value != null) {
return StringUtil.parseStringArray(value); return StringUtil.parseStringArray(value);
@@ -259,7 +259,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry
} }
protected String _path; protected String _path;
protected HashMap _data; protected HashMap<String,String> _data;
} }
protected ConfigRepository _repo; protected ConfigRepository _repo;
@@ -59,14 +59,14 @@ public class ConfigRepository extends JORARepository
* @return a map containing field/value pairs for all stored configuration * @return a map containing field/value pairs for all stored configuration
* data. * data.
*/ */
public HashMap loadConfig (String object) public HashMap<String,String> loadConfig (String object)
throws PersistenceException throws PersistenceException
{ {
ArrayList list = loadAll( ArrayList<ConfigDatum> list = loadAll(
_ctable, "where OBJECT = " + JDBCUtil.escape(object)); _ctable, "where OBJECT = " + JDBCUtil.escape(object));
HashMap data = new HashMap(); HashMap<String,String> data = new HashMap<String,String>();
for (int ii = 0, ll = list.size(); ii < ll; ii++) { for (int ii = 0, ll = list.size(); ii < ll; ii++) {
ConfigDatum datum = (ConfigDatum)list.get(ii); ConfigDatum datum = list.get(ii);
data.put(datum.field, datum.value); data.put(datum.field, datum.value);
} }
return data; return data;
@@ -62,12 +62,12 @@ public abstract class FieldMarshaller
} }
// if we have an exact match, use that // if we have an exact match, use that
FieldMarshaller fm = (FieldMarshaller)_marshallers.get(ftype); FieldMarshaller fm = _marshallers.get(ftype);
// otherwise if the class is a streamable, use the streamable // otherwise if the class is a streamable, use the streamable
// marshaller // marshaller
if (fm == null && Streamer.isStreamable(ftype)) { if (fm == null && Streamer.isStreamable(ftype)) {
fm = (FieldMarshaller)_marshallers.get(Streamable.class); fm = _marshallers.get(Streamable.class);
} }
return fm; return fm;
@@ -124,7 +124,7 @@ public abstract class FieldMarshaller
protected static void createMarshallers () protected static void createMarshallers ()
{ {
// create our table // create our table
_marshallers = new HashMap(); _marshallers = new HashMap<Class,FieldMarshaller>();
// create a generic marshaller for streamable instances // create a generic marshaller for streamable instances
FieldMarshaller gmarsh = new FieldMarshaller() { FieldMarshaller gmarsh = new FieldMarshaller() {
@@ -270,5 +270,5 @@ public abstract class FieldMarshaller
/** Contains a mapping from field type to field marshaller instance /** Contains a mapping from field type to field marshaller instance
* for that type. */ * for that type. */
protected static HashMap _marshallers; protected static HashMap<Class,FieldMarshaller> _marshallers;
} }
@@ -66,7 +66,7 @@ public class ObjectInputStream extends DataInputStream
public void addTranslation (String oldname, String newname) public void addTranslation (String oldname, String newname)
{ {
if (_translations == null) { if (_translations == null) {
_translations = new HashMap(); _translations = new HashMap<String,String>();
} }
_translations.put(oldname, newname); _translations.put(oldname, newname);
} }
@@ -82,7 +82,7 @@ public class ObjectInputStream extends DataInputStream
// create our classmap if necessary // create our classmap if necessary
if (_classmap == null) { if (_classmap == null) {
_classmap = new HashIntMap(); _classmap = new HashIntMap<ClassMapping>();
} }
try { try {
@@ -107,7 +107,7 @@ public class ObjectInputStream extends DataInputStream
// if we have a translation (used to cope when serialized // if we have a translation (used to cope when serialized
// classes are renamed) use it // classes are renamed) use it
if (_translations != null) { if (_translations != null) {
String tname = (String)_translations.get(cname); String tname = _translations.get(cname);
if (tname != null) { if (tname != null) {
cname = tname; cname = tname;
} }
@@ -132,7 +132,7 @@ public class ObjectInputStream extends DataInputStream
_classmap.put(code, cmap); _classmap.put(code, cmap);
} else { } else {
cmap = (ClassMapping)_classmap.get(code); cmap = _classmap.get(code);
// sanity check // sanity check
if (cmap == null) { if (cmap == null) {
@@ -224,7 +224,7 @@ public class ObjectInputStream extends DataInputStream
/** Used to map classes to numeric codes and the {@link Streamer} /** Used to map classes to numeric codes and the {@link Streamer}
* instance used to write them. */ * instance used to write them. */
protected HashIntMap _classmap; protected HashIntMap<ClassMapping> _classmap;
/** The object currently being read from the stream. */ /** The object currently being read from the stream. */
protected Object _current; protected Object _current;
@@ -237,7 +237,7 @@ public class ObjectInputStream extends DataInputStream
/** An optional set of class name translations to use when /** An optional set of class name translations to use when
* unserializing objects. */ * unserializing objects. */
protected HashMap _translations; protected HashMap<String,String> _translations;
/** Used to activate verbose debug logging. */ /** Used to activate verbose debug logging. */
protected static final boolean STREAM_DEBUG = false; protected static final boolean STREAM_DEBUG = false;
@@ -70,7 +70,7 @@ public class ObjectOutputStream extends DataOutputStream
public void addTranslation (String className, String streamedName) public void addTranslation (String className, String streamedName)
{ {
if (_translations == null) { if (_translations == null) {
_translations = new HashMap(); _translations = new HashMap<String,String>();
} }
_translations.put(className, streamedName); _translations.put(className, streamedName);
} }
@@ -90,12 +90,12 @@ public class ObjectOutputStream extends DataOutputStream
// create our classmap if necessary // create our classmap if necessary
if (_classmap == null) { if (_classmap == null) {
_classmap = new HashMap(); _classmap = new HashMap<Class,ClassMapping>();
} }
// otherwise, look up the class mapping record // otherwise, look up the class mapping record
Class sclass = object.getClass(); Class sclass = object.getClass();
ClassMapping cmap = (ClassMapping)_classmap.get(sclass); ClassMapping cmap = _classmap.get(sclass);
// create a class mapping for this class if we've not got one // create a class mapping for this class if we've not got one
if (cmap == null) { if (cmap == null) {
@@ -119,7 +119,7 @@ public class ObjectOutputStream extends DataOutputStream
writeShort(-cmap.code); writeShort(-cmap.code);
String cname = sclass.getName(); String cname = sclass.getName();
if (_translations != null) { if (_translations != null) {
String tname = (String) _translations.get(cname); String tname = _translations.get(cname);
if (tname != null) { if (tname != null) {
cname = tname; cname = tname;
} }
@@ -191,7 +191,7 @@ public class ObjectOutputStream extends DataOutputStream
/** Used to map classes to numeric codes and the {@link Streamer} /** Used to map classes to numeric codes and the {@link Streamer}
* instance used to write them. */ * instance used to write them. */
protected HashMap _classmap; protected HashMap<Class,ClassMapping> _classmap;
/** A counter used to assign codes to streamed classes. */ /** A counter used to assign codes to streamed classes. */
protected short _nextCode = 1; protected short _nextCode = 1;
@@ -204,5 +204,5 @@ public class ObjectOutputStream extends DataOutputStream
/** An optional set of class name translations to use when serializing /** An optional set of class name translations to use when serializing
* objects. */ * objects. */
protected HashMap _translations; protected HashMap<String,String> _translations;
} }