From 94b79826d49ba34c5020b847a818deb0809fb476 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 5 Jul 2006 00:51:22 +0000 Subject: [PATCH] More type safety. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4244 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../admin/client/ConfigObjectManager.java | 14 +++++------ .../threerings/admin/client/DSetEditor.java | 18 ++++++++------ .../admin/client/ObjectEditorPanel.java | 10 ++++---- .../admin/server/ConfigRegistry.java | 7 +++--- .../admin/server/DatabaseConfigRegistry.java | 24 +++++++++---------- .../server/persist/ConfigRepository.java | 8 +++---- .../com/threerings/io/FieldMarshaller.java | 8 +++---- .../com/threerings/io/ObjectInputStream.java | 12 +++++----- .../com/threerings/io/ObjectOutputStream.java | 12 +++++----- 9 files changed, 59 insertions(+), 54 deletions(-) diff --git a/src/java/com/threerings/admin/client/ConfigObjectManager.java b/src/java/com/threerings/admin/client/ConfigObjectManager.java index 9d7c9c687..63e68c5c2 100644 --- a/src/java/com/threerings/admin/client/ConfigObjectManager.java +++ b/src/java/com/threerings/admin/client/ConfigObjectManager.java @@ -17,7 +17,7 @@ import com.threerings.presents.dobj.Subscriber; public class ConfigObjectManager implements AdminService.ConfigInfoListener { public ConfigObjectManager(Client client) { - _serverconfig = new HashMap(); + _serverconfig = new HashMap(); _client = client; _client.addClientObserver(new SessionObserver() { // documentation inherited from interface SessionObserver @@ -63,21 +63,21 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener // documentation inherited from interface AdminService.ConfigInfoListener 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 */ 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 * an individual ConfigObject that the server knows about into a HashMap */ - protected class ConfigObjectSubscriber implements Subscriber + protected class ConfigObjectSubscriber implements Subscriber { /** * 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 - public void objectAvailable (DObject object) { - _cobj = (ConfigObject)object; + public void objectAvailable (ConfigObject object) { + _cobj = object; _serverconfig.put(_key, _cobj); } @@ -126,7 +126,7 @@ public class ConfigObjectManager implements AdminService.ConfigInfoListener protected ConfigObjectSubscriber[] _csubscribers; /** Our local copy of the server-side runtime configuration */ - protected HashMap _serverconfig; + protected HashMap _serverconfig; /** Our distributed object manager */ protected DObjectManager _dobjmgr; diff --git a/src/java/com/threerings/admin/client/DSetEditor.java b/src/java/com/threerings/admin/client/DSetEditor.java index 8c5c45eb6..3dab682cf 100644 --- a/src/java/com/threerings/admin/client/DSetEditor.java +++ b/src/java/com/threerings/admin/client/DSetEditor.java @@ -124,7 +124,7 @@ public class DSetEditor extends JPanel */ public DSet.Entry getSelectedEntry () { - return (DSet.Entry) _table.getSelectedObject(); + return (DSet.Entry)_table.getSelectedObject(); } // documentation inherited @@ -159,7 +159,9 @@ public class DSetEditor extends JPanel { if (event.getName().equals(_setName)) { DSet.Entry entry = event.getEntry(); - int index = _keys.insertSorted(entry.getKey()); + @SuppressWarnings("unchecked") Comparable key = + (Comparable)entry.getKey(); + int index = _keys.insertSorted(key); _table.insertDatum(entry, index); } } @@ -204,11 +206,13 @@ public class DSetEditor extends JPanel protected void refreshData () { - _keys = new ComparableArrayList(); + _keys = new ComparableArrayList>(); DSet.Entry[] entries = new DSet.Entry[_set.size()]; _set.toArray(entries); - for (int ii=0; ii < entries.length; ii++) { - _keys.insertSorted(entries[ii].getKey()); + for (int ii = 0; ii < entries.length; ii++) { + @SuppressWarnings("unchecked") Comparable key = + (Comparable)entries[ii].getKey(); + _keys.insertSorted(key); } _table.setData(entries); // this works because DSet itself is sorted } @@ -220,10 +224,10 @@ public class DSetEditor extends JPanel protected String _setName; /** The set itself. */ - protected DSet _set; + protected DSet _set; /** An array we use to track our entries' positions by key. */ - protected ComparableArrayList _keys; + protected ComparableArrayList> _keys; /** The table used to edit. */ protected ObjectEditorTable _table; diff --git a/src/java/com/threerings/admin/client/ObjectEditorPanel.java b/src/java/com/threerings/admin/client/ObjectEditorPanel.java index 73690d702..c431cce5a 100644 --- a/src/java/com/threerings/admin/client/ObjectEditorPanel.java +++ b/src/java/com/threerings/admin/client/ObjectEditorPanel.java @@ -51,7 +51,7 @@ import com.threerings.admin.data.ConfigObject; * @see ConfigEditorPanel */ public class ObjectEditorPanel extends ScrollablePanel - implements Subscriber + implements Subscriber { /** * 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 // config object - _safesub = new SafeSubscriber(oid, this); + _safesub = new SafeSubscriber(oid, this); _safesub.subscribe(_ctx.getDObjectManager()); } @@ -94,10 +94,10 @@ public class ObjectEditorPanel extends ScrollablePanel } // documentation inherited from interface - public void objectAvailable (DObject object) + public void objectAvailable (ConfigObject object) { // keep this for later - _object = (ConfigObject)object; + _object = object; // create our field editors try { @@ -125,6 +125,6 @@ public class ObjectEditorPanel extends ScrollablePanel protected PresentsContext _ctx; protected String _key; - protected SafeSubscriber _safesub; + protected SafeSubscriber _safesub; protected ConfigObject _object; } diff --git a/src/java/com/threerings/admin/server/ConfigRegistry.java b/src/java/com/threerings/admin/server/ConfigRegistry.java index 365c81674..cd3c540ac 100644 --- a/src/java/com/threerings/admin/server/ConfigRegistry.java +++ b/src/java/com/threerings/admin/server/ConfigRegistry.java @@ -98,7 +98,7 @@ public abstract class ConfigRegistry */ public DObject getObject (String key) { - ObjectRecord record = (ObjectRecord)_configs.get(key); + ObjectRecord record = _configs.get(key); return (record == null) ? null : record.object; } @@ -108,7 +108,7 @@ public abstract class ConfigRegistry */ 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. */ - protected HashMap _configs = new HashMap(); + protected HashMap _configs = + new HashMap(); protected static final int[] INT_ARRAY_PROTO = new int[0]; protected static final float[] FLOAT_ARRAY_PROTO = new float[0]; diff --git a/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java b/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java index efc58013e..0186edcfa 100644 --- a/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java +++ b/src/java/com/threerings/admin/server/DatabaseConfigRegistry.java @@ -86,14 +86,14 @@ public class DatabaseConfigRegistry extends ConfigRegistry Log.warning("Failed to load object configuration " + "[path=" + _path + "]."); Log.logStackTrace(pe); - _data = new HashMap(); + _data = new HashMap(); } super.init(); } protected boolean getValue (String field, boolean defval) { - String value = (String)_data.get(field); + String value = _data.get(field); if (value != null) { return "true".equalsIgnoreCase(value); } @@ -101,7 +101,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected short getValue (String field, short defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { return Short.parseShort(value); @@ -113,7 +113,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected int getValue (String field, int defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { return Integer.parseInt(value); @@ -125,7 +125,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected long getValue (String field, long defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { return Long.parseLong(value); @@ -137,7 +137,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected float getValue (String field, float defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { return Float.parseFloat(value); @@ -149,12 +149,12 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected String getValue (String field, String defval) { - String value = (String)_data.get(field); + String value = _data.get(field); return (value == null) ? defval : value; } protected int[] getValue (String field, int[] defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { int[] avalue = StringUtil.parseIntArray(value); @@ -169,7 +169,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected float[] getValue (String field, float[] defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { float[] avalue = StringUtil.parseFloatArray(value); @@ -184,7 +184,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected long[] getValue (String field, long[] defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { long[] avalue = StringUtil.parseLongArray(value); @@ -199,7 +199,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected String[] getValue (String field, String[] defval) { - String value = (String)_data.get(field); + String value = _data.get(field); try { if (value != null) { return StringUtil.parseStringArray(value); @@ -259,7 +259,7 @@ public class DatabaseConfigRegistry extends ConfigRegistry } protected String _path; - protected HashMap _data; + protected HashMap _data; } protected ConfigRepository _repo; diff --git a/src/java/com/threerings/admin/server/persist/ConfigRepository.java b/src/java/com/threerings/admin/server/persist/ConfigRepository.java index b6c2a1318..bbcfa949e 100644 --- a/src/java/com/threerings/admin/server/persist/ConfigRepository.java +++ b/src/java/com/threerings/admin/server/persist/ConfigRepository.java @@ -59,14 +59,14 @@ public class ConfigRepository extends JORARepository * @return a map containing field/value pairs for all stored configuration * data. */ - public HashMap loadConfig (String object) + public HashMap loadConfig (String object) throws PersistenceException { - ArrayList list = loadAll( + ArrayList list = loadAll( _ctable, "where OBJECT = " + JDBCUtil.escape(object)); - HashMap data = new HashMap(); + HashMap data = new HashMap(); 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); } return data; diff --git a/src/java/com/threerings/io/FieldMarshaller.java b/src/java/com/threerings/io/FieldMarshaller.java index 8e86e4098..22cbf5a9b 100644 --- a/src/java/com/threerings/io/FieldMarshaller.java +++ b/src/java/com/threerings/io/FieldMarshaller.java @@ -62,12 +62,12 @@ public abstract class FieldMarshaller } // 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 // marshaller if (fm == null && Streamer.isStreamable(ftype)) { - fm = (FieldMarshaller)_marshallers.get(Streamable.class); + fm = _marshallers.get(Streamable.class); } return fm; @@ -124,7 +124,7 @@ public abstract class FieldMarshaller protected static void createMarshallers () { // create our table - _marshallers = new HashMap(); + _marshallers = new HashMap(); // create a generic marshaller for streamable instances FieldMarshaller gmarsh = new FieldMarshaller() { @@ -270,5 +270,5 @@ public abstract class FieldMarshaller /** Contains a mapping from field type to field marshaller instance * for that type. */ - protected static HashMap _marshallers; + protected static HashMap _marshallers; } diff --git a/src/java/com/threerings/io/ObjectInputStream.java b/src/java/com/threerings/io/ObjectInputStream.java index cc3793f1a..5fe529ac4 100644 --- a/src/java/com/threerings/io/ObjectInputStream.java +++ b/src/java/com/threerings/io/ObjectInputStream.java @@ -66,7 +66,7 @@ public class ObjectInputStream extends DataInputStream public void addTranslation (String oldname, String newname) { if (_translations == null) { - _translations = new HashMap(); + _translations = new HashMap(); } _translations.put(oldname, newname); } @@ -82,7 +82,7 @@ public class ObjectInputStream extends DataInputStream // create our classmap if necessary if (_classmap == null) { - _classmap = new HashIntMap(); + _classmap = new HashIntMap(); } try { @@ -107,7 +107,7 @@ public class ObjectInputStream extends DataInputStream // if we have a translation (used to cope when serialized // classes are renamed) use it if (_translations != null) { - String tname = (String)_translations.get(cname); + String tname = _translations.get(cname); if (tname != null) { cname = tname; } @@ -132,7 +132,7 @@ public class ObjectInputStream extends DataInputStream _classmap.put(code, cmap); } else { - cmap = (ClassMapping)_classmap.get(code); + cmap = _classmap.get(code); // sanity check if (cmap == null) { @@ -224,7 +224,7 @@ public class ObjectInputStream extends DataInputStream /** Used to map classes to numeric codes and the {@link Streamer} * instance used to write them. */ - protected HashIntMap _classmap; + protected HashIntMap _classmap; /** The object currently being read from the stream. */ protected Object _current; @@ -237,7 +237,7 @@ public class ObjectInputStream extends DataInputStream /** An optional set of class name translations to use when * unserializing objects. */ - protected HashMap _translations; + protected HashMap _translations; /** Used to activate verbose debug logging. */ protected static final boolean STREAM_DEBUG = false; diff --git a/src/java/com/threerings/io/ObjectOutputStream.java b/src/java/com/threerings/io/ObjectOutputStream.java index 98519ddd3..6ebd8d781 100644 --- a/src/java/com/threerings/io/ObjectOutputStream.java +++ b/src/java/com/threerings/io/ObjectOutputStream.java @@ -70,7 +70,7 @@ public class ObjectOutputStream extends DataOutputStream public void addTranslation (String className, String streamedName) { if (_translations == null) { - _translations = new HashMap(); + _translations = new HashMap(); } _translations.put(className, streamedName); } @@ -90,12 +90,12 @@ public class ObjectOutputStream extends DataOutputStream // create our classmap if necessary if (_classmap == null) { - _classmap = new HashMap(); + _classmap = new HashMap(); } // otherwise, look up the class mapping record 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 if (cmap == null) { @@ -119,7 +119,7 @@ public class ObjectOutputStream extends DataOutputStream writeShort(-cmap.code); String cname = sclass.getName(); if (_translations != null) { - String tname = (String) _translations.get(cname); + String tname = _translations.get(cname); if (tname != null) { cname = tname; } @@ -191,7 +191,7 @@ public class ObjectOutputStream extends DataOutputStream /** Used to map classes to numeric codes and the {@link Streamer} * instance used to write them. */ - protected HashMap _classmap; + protected HashMap _classmap; /** A counter used to assign codes to streamed classes. */ protected short _nextCode = 1; @@ -204,5 +204,5 @@ public class ObjectOutputStream extends DataOutputStream /** An optional set of class name translations to use when serializing * objects. */ - protected HashMap _translations; + protected HashMap _translations; }