Some fixups and enhancements.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4294 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-28 02:48:52 +00:00
parent ad74efc332
commit 7c17069a16
4 changed files with 69 additions and 8 deletions
+23 -1
View File
@@ -1,8 +1,10 @@
package com.threerings.io {
import com.threerings.util.ClassUtil;
import com.threerings.util.Cloneable;
public dynamic class TypedArray extends Array
implements Cloneable
{
/**
* Create a TypedArray
@@ -21,9 +23,18 @@ public dynamic class TypedArray extends Array
*/
public static function getJavaType (of :Class) :String
{
if (of === Boolean) {
return "[Z";
} else if (of === int) { // Number will be int if something like 3.0
return "[I";
} else if (of === Number) {
return "[D";
}
var cname :String = Translations.getToServer(
ClassUtil.getClassName(of));
// TODO: primitive types
return "[L" + cname + ";";
}
@@ -41,6 +52,17 @@ public dynamic class TypedArray extends Array
return _jtype;
}
// from Cloneable
public function clone () :Object
{
var clazz :Class = ClassUtil.getClass(this);
var copy :TypedArray = new clazz(_jtype);
for (var ii :int = length - 1; ii >= 0; ii--) {
copy[ii] = this[ii];
}
return copy;
}
/** The 'type' of this array, which doesn't really mean anything
* except gives it a clue as to how to stream to our server. */
protected var _jtype :String;
@@ -7,6 +7,8 @@ import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.core.Application;
import com.threerings.util.ObserverList;
import com.threerings.presents.data.ClientObject;
@@ -26,10 +28,10 @@ public class Client extends EventDispatcher
private static const log :Log = Log.getLog(Client);
public function Client (creds :Credentials, stage :Stage)
public function Client (creds :Credentials, app :Application)
{
_creds = creds;
_stage = stage;
_app = app;
}
/**
@@ -94,12 +96,17 @@ public class Client extends EventDispatcher
_ports = ports;
}
public function callLater (fn :Function, args :Array = null) :void
{
_app.callLater(fn, args);
}
/**
* @return the Stage object we're living in.
*/
public function getStage () :Stage
{
return _stage;
return _app.stage;
}
public function getHostname () :String
@@ -365,8 +372,8 @@ public class Client extends EventDispatcher
/** The credentials we used to authenticate with the server. */
protected var _creds :Credentials;
/** The stage we're on, needed for creating the Communicator. */
protected var _stage :Stage;
/** The app we're in, needed for creating the Communicator. */
protected var _app :Application;
/** The version string reported to the server at auth time. */
protected var _version :String = "";
+17 -1
View File
@@ -1,7 +1,11 @@
package com.threerings.util {
/**
* Contains methods that should be in Array, but aren't.
* Contains methods that should be in Array, but aren't. Additionally
* contains methods that understand the interfaces in this package.
* So, for example, removeFirst() understands Equalable and will remove
* an element that is equals() to the specified element, rather than just
* ===.
*/
public class ArrayUtil
{
@@ -24,6 +28,18 @@ public class ArrayUtil
});
}
public static function indexOf (arr :Array, element :Object) :int
{
if (arr != null) {
for (var ii :int = 0; ii < arr.length; ii++) {
if (Util.equals(arr[ii], element)) {
return ii;
}
}
}
return -1; // never found
}
/**
* Remove the first instance of the specified element from the array.
*/
+17 -1
View File
@@ -4,6 +4,22 @@ import mx.utils.*;
public class StringUtil
{
/**
* Get a reasonable hash code for the specified String.
*/
public static function hashCode (str :String) :int
{
var code :int = 0;
if (str != null) {
// sample at most 8 chars
var lastChar :int = Math.min(8, str.length);
for (var ii :int = 0; ii < lastChar; ii++) {
code = code * 31 + str.charCodeAt(ii);
}
}
return code;
}
public static function isBlank (str :String) :Boolean
{
return (str == null) || (str.search("\\S") == -1);
@@ -15,7 +31,7 @@ public class StringUtil
public static function endsWith (str :String, substr :String) :Boolean
{
var startDex :int = str.length - substr.length;
return (startDex >= 0) && (str.indexOf(substr, startDex) > 0);
return (startDex >= 0) && (str.indexOf(substr, startDex) >= 0);
}
/**