Started work on the 'crowd' package.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3935 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Provides a generic iterator for an Array.
|
||||
* No co-modification checking is done.
|
||||
*/
|
||||
public class ArrayIterator
|
||||
implements Iterator
|
||||
{
|
||||
/**
|
||||
* Create an ArrayIterator.
|
||||
*/
|
||||
public function ArrayIterator (arr :Array)
|
||||
{
|
||||
_arr = arr;
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
// documentation inherited from interface Iterator
|
||||
public function hasNext () :Boolean
|
||||
{
|
||||
return (_index < _arr.length);
|
||||
}
|
||||
|
||||
// documentation inherited from interface Iterator
|
||||
public function next () :Object
|
||||
{
|
||||
return _arr[_index++];
|
||||
}
|
||||
|
||||
/** The array we're iterating over. */
|
||||
protected var _arr :Array;
|
||||
|
||||
/** The current index. */
|
||||
protected var _index :int;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Equivalent to java.lang.Byte.
|
||||
*/
|
||||
public class Byte
|
||||
implements Equalable
|
||||
{
|
||||
public var value :int;
|
||||
|
||||
public function Byte (value :int)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// documentation inherited from interface Equalable
|
||||
public function equals (other :Object) :Boolean
|
||||
{
|
||||
return (other is Byte) && (value === (other as Byte).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Equivalent to java.lang.Float.
|
||||
*/
|
||||
public class Float
|
||||
implements Equalable
|
||||
{
|
||||
public var value :Number;
|
||||
|
||||
public function Float (value :Number)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// documentation inherited from interface Equalable
|
||||
public function equals (other :Object) :Boolean
|
||||
{
|
||||
return (other is Float) && (value === (other as Float).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Equivalent to java.lang.Integer.
|
||||
*/
|
||||
public class Integer
|
||||
implements Equalable
|
||||
{
|
||||
public var value :int;
|
||||
|
||||
public function Integer (value :int)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// documentation inherited from interface Equalable
|
||||
public function equals (other :Object) :Boolean
|
||||
{
|
||||
return (other is Integer) && (value === (other as Integer).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Java has Iterator, ActionScript has IViewCursor.
|
||||
* The problem is, IViewCursor defines 14 methods and 5 read-only properties.
|
||||
* That is a serious PITA to write for every collection that might desire
|
||||
* iteration. This provides a simpler alternative.
|
||||
*/
|
||||
public interface Iterator
|
||||
{
|
||||
/**
|
||||
* Is there another element available?
|
||||
*/
|
||||
function hasNext () :Boolean;
|
||||
|
||||
/**
|
||||
* Returns the next element.
|
||||
*/
|
||||
function next () :Object;
|
||||
|
||||
// TODO: remove() ?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* Equivalent to java.lang.Short.
|
||||
*/
|
||||
public class Short
|
||||
implements Equalable
|
||||
{
|
||||
public var value :int;
|
||||
|
||||
public function Short (value :int)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// documentation inherited from interface Equalable
|
||||
public function equals (other :Object) :Boolean
|
||||
{
|
||||
return (other is Short) && (value === (other as Short).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,15 @@ public class Util
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static function cast (obj :Object, clazz :Class) :Object
|
||||
{
|
||||
if (obj == null || obj is clazz) {
|
||||
return obj;
|
||||
} else {
|
||||
throw new Error("wah");
|
||||
}
|
||||
}
|
||||
|
||||
private static const HEX :Array = new Array("0", "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user