Added the keys() function to the Map interface, replaced instances of

SimpleMap with HashMap. Discarded SimpleMap.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4122 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-05-16 21:06:06 +00:00
parent 4aa8f5a5d5
commit 64e87bb907
12 changed files with 36 additions and 85 deletions
@@ -24,8 +24,9 @@ package com.threerings.crowd.chat.client {
import mx.collections.ArrayCollection;
import com.threerings.util.ArrayUtil;
import com.threerings.util.HashMap;
import com.threerings.util.Map;
import com.threerings.util.ResultListener;
import com.threerings.util.SimpleMap;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
@@ -308,7 +309,7 @@ public class ChatDirector extends BasicDirector
args = StringUtil.trim(text.substring(sidx+1));
}
var possibleCommands :SimpleMap = getCommandHandlers(command);
var possibleCommands :Map = getCommandHandlers(command);
switch (possibleCommands.size()) {
case 0:
return MessageBundle.tcompose(
@@ -840,9 +841,9 @@ public class ChatDirector extends BasicDirector
* specified command (i.e. the specified command is a prefix of their
* registered command string).
*/
internal function getCommandHandlers (command :String) :SimpleMap
internal function getCommandHandlers (command :String) :Map
{
var matches :SimpleMap = new SimpleMap();
var matches :Map = new HashMap();
var user :BodyObject =
(_cctx.getClient().getClientObject() as BodyObject);
var keys :Array = _handlers.keys();
@@ -977,7 +978,7 @@ public class ChatDirector extends BasicDirector
/** A mapping from auxiliary chat objects to the types under which
* they are registered. */
protected var _auxes :SimpleMap = new SimpleMap();
protected var _auxes :HashMap = new HashMap();
// /** Validator of who may be added to the chatters list. */
// protected var _chatterValidator :ChatterValidator;
@@ -990,7 +991,7 @@ public class ChatDirector extends BasicDirector
// new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY);
/** Registered chat command handlers. */
protected static const _handlers :SimpleMap = new SimpleMap();
protected static const _handlers :HashMap = new HashMap();
/** A history of chat commands. */
protected static const _history :Array = new Array();
@@ -1,7 +1,7 @@
package com.threerings.crowd.chat.client {
import com.threerings.util.Map;
import com.threerings.util.MessageBundle;
import com.threerings.util.SimpleMap;
import com.threerings.util.StringUtil;
import com.threerings.crowd.chat.data.ChatCodes;
@@ -34,7 +34,7 @@ public class HelpHandler extends CommandHandler
}
// handle "/help help" and "/help boguscmd"
var possibleCmds :SimpleMap = _chatdir.getCommandHandlers(hcmd);
var possibleCmds :Map = _chatdir.getCommandHandlers(hcmd);
if ((hcmd === "help") || (possibleCmds.size() == 0)) {
possibleCmds = _chatdir.getCommandHandlers("");
possibleCmds.remove("help"); // remove help from the list
@@ -6,9 +6,6 @@ import flash.utils.ByteArray;
import flash.utils.IDataInput;
import com.threerings.util.ClassUtil;
import com.threerings.util.SimpleMap;
//import com.threerings.presents.Log;
public class ObjectInputStream
{
@@ -235,7 +232,6 @@ public class ObjectInputStream
private static var _tempy :int = 0;
}
}
@@ -4,7 +4,7 @@ import flash.utils.ByteArray;
import flash.utils.IDataOutput;
import com.threerings.util.ClassUtil;
import com.threerings.util.SimpleMap;
import com.threerings.util.HashMap;
public class ObjectOutputStream
{
@@ -180,6 +180,6 @@ public class ObjectOutputStream
protected var _streamer :Streamer;
/** A map of classname to ClassMapping info. */
protected var _classMap :SimpleMap = new SimpleMap();
protected var _classMap :HashMap = new HashMap();
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
package com.threerings.io {
import com.threerings.util.SimpleMap;
import com.threerings.util.HashMap;
/**
* Maintains a set of translations between actionscript class names
@@ -28,10 +28,10 @@ public class Translations
}
/** A mapping of actionscript names to java names. */
protected static var _toServer :SimpleMap = new SimpleMap();
protected static var _toServer :HashMap = new HashMap();
/** A mapping of java names to actionscript names. */
protected static var _fromServer :SimpleMap = new SimpleMap();
protected static var _fromServer :HashMap = new HashMap();
// initialize some standard classes
addTranslation("Object", "java.lang.Object");
@@ -28,7 +28,7 @@ import flash.utils.Timer;
import mx.collections.IList;
import com.threerings.util.ClassUtil;
import com.threerings.util.SimpleMap;
import com.threerings.util.HashMap;
import com.threerings.presents.dobj.DEvent;
import com.threerings.presents.dobj.DObject;
@@ -437,19 +437,19 @@ public class ClientDObjectMgr
protected var _actions :Array = new Array();
/** All of the distributed objects that are active on this client. */
protected var _ocache :SimpleMap = new SimpleMap(); //HashIntMap();
protected var _ocache :HashMap = new HashMap();
/** Objects that have been marked for death. */
protected var _dead :SimpleMap = new SimpleMap(); //HashIntMap();
protected var _dead :HashMap = new HashMap();
/** Pending object subscriptions. */
protected var _penders :SimpleMap = new SimpleMap(); //HashIntMap();
protected var _penders :HashMap = new HashMap();
/** A mapping from distributed object class to flush delay. */
protected var _delays :SimpleMap = new SimpleMap(); //HashMap();
protected var _delays :HashMap = new HashMap();
/** A set of objects waiting to be flushed. */
protected var _flushes :SimpleMap = new SimpleMap(); //HashIntMap();
protected var _flushes :HashMap = new HashMap();
/** Flushes objects every now and again. */
protected var _flushInterval :Timer;
@@ -3,7 +3,7 @@ package com.threerings.presents.client {
import mx.collections.IViewCursor;
import mx.collections.ArrayCollection;
import com.threerings.util.SimpleMap;
import com.threerings.util.HashMap;
import com.threerings.presents.data.ListenerMarshaller;
@@ -346,10 +346,10 @@ public class InvocationDirector
/** Used to keep track of invocation service listeners which will
* receive responses from invocation service requests. */
protected var _listeners :SimpleMap = new SimpleMap();
protected var _listeners :HashMap = new HashMap();
/** Used to keep track of invocation notification receivers. */
protected var _receivers :SimpleMap = new SimpleMap();
protected var _receivers :HashMap = new HashMap();
/** All registered receivers are maintained in a list so that we can
* assign receiver ids to them when we go online. */
+6
View File
@@ -18,5 +18,11 @@ public class Byte
{
return (other is Byte) && (value === (other as Byte).value);
}
// documentation inherited
public function toString () :String
{
return "Byte(" + value + ")";
}
}
}
+1
View File
@@ -192,6 +192,7 @@ public class Hashtable
return _simpleSize + _entriesSize;
}
// documentation inherited from interface Map
public function keys () :Array
{
var keys :Array = new Array();
+5
View File
@@ -26,6 +26,11 @@ public interface Map
*/
function isEmpty () :Boolean;
/**
* Return all the unique keys in this Map, in Array form.
*/
function keys () :Array;
/**
* Store a value in the map associated with the specified key.
* Returns the previous value stored for that key, or undefined.
+1 -1
View File
@@ -177,7 +177,7 @@ public class MessageManager
// protected var _loader :ClassLoader;
/** A cache of instantiated message bundles. */
protected var _cache :SimpleMap = new SimpleMap();
protected var _cache :HashMap = new HashMap();
/** Our top-level message bundle, from which others obtain messages if
* they can't find them within themselves. */
-58
View File
@@ -1,58 +0,0 @@
package com.threerings.util {
/**
* I will likely extend this out to be a fully-featured map.
*/
public class SimpleMap extends Object
{
public function clear () :void
{
_data = new Object();
_size = 0;
}
public function get (key :Object) :Object
{
var skey :String = key.toString();
return _data[skey];
}
public function keys () :Array
{
var arr :Array = new Array();
for (var skey :String in _data) {
arr.push(skey);
}
return arr;
}
public function put (key :Object, value :Object) :Object
{
var skey :String = key.toString();
var oldValue :* = _data[skey];
_data[skey] = value;
if (oldValue === undefined) {
_size++;
}
return (oldValue as Object);
}
public function remove (key :Object) :Object
{
var skey :String = key.toString();
var value :Object = _data[skey];
delete _data[skey];
_size--;
return value;
}
public function size () :int
{
return _size;
}
protected var _data :Object = new Object();
protected var _size :int = 0;
}
}