Various small fixes.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4258 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,6 +27,15 @@ public dynamic class TypedArray extends Array
|
|||||||
return "[L" + cname + ";";
|
return "[L" + cname + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory method to create a TypedArray for holding objects
|
||||||
|
* of the specified type.
|
||||||
|
*/
|
||||||
|
public static function create (of :Class) :TypedArray
|
||||||
|
{
|
||||||
|
return new TypedArray(getJavaType(of));
|
||||||
|
}
|
||||||
|
|
||||||
public function getJavaType () :String
|
public function getJavaType () :String
|
||||||
{
|
{
|
||||||
return _jtype;
|
return _jtype;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class ArrayUtil
|
|||||||
arr :Array, element :Object, firstOnly :Boolean) :void
|
arr :Array, element :Object, firstOnly :Boolean) :void
|
||||||
{
|
{
|
||||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||||
if (arr[ii] === element) {
|
if (Util.equals(arr[ii], element)) {
|
||||||
arr.splice(ii--, 1);
|
arr.splice(ii--, 1);
|
||||||
if (firstOnly) {
|
if (firstOnly) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ public class ClassUtil
|
|||||||
return s.replace("::", ".");
|
return s.replace("::", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new instance that is the same class as the specified
|
||||||
|
* object. The class must have a zero-arg constructor.
|
||||||
|
*/
|
||||||
|
public static function newInstance (obj :Object) :Object
|
||||||
|
{
|
||||||
|
var clazz :Class = getClass(obj);
|
||||||
|
return new clazz();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getClass (obj :Object) :Class
|
public static function getClass (obj :Object) :Class
|
||||||
{
|
{
|
||||||
return getClassByName(getClassName(obj));
|
return getClassByName(getClassName(obj));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public interface Map
|
|||||||
function get (key :Object) :*;
|
function get (key :Object) :*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the specified function, which accepts to args: key and value,
|
* Call the specified function, which accepts two args: key and value,
|
||||||
* for every mapping.
|
* for every mapping.
|
||||||
*/
|
*/
|
||||||
function forEach (fn :Function) :void;
|
function forEach (fn :Function) :void;
|
||||||
|
|||||||
@@ -25,6 +25,17 @@ public class Util
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A nicer test for equals that works if the objects implement Equalable
|
||||||
|
*/
|
||||||
|
public static function equals (obj1 :Object, obj2 :Object) :Boolean
|
||||||
|
{
|
||||||
|
// catch various common cases (both primitive or null)
|
||||||
|
return (obj1 === obj2) ||
|
||||||
|
// otherwise, they're only possibly still equal if Equalable
|
||||||
|
((obj1 is Equalable) && (obj1 as Equalable).equals(obj2));
|
||||||
|
}
|
||||||
|
|
||||||
public static function cast (obj :Object, clazz :Class) :Object
|
public static function cast (obj :Object, clazz :Class) :Object
|
||||||
{
|
{
|
||||||
if (obj == null || obj is clazz) {
|
if (obj == null || obj is clazz) {
|
||||||
|
|||||||
Reference in New Issue
Block a user