Utility function for converting from ordinal to Enum
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5849 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -143,6 +143,18 @@ public class Enum
|
|||||||
return Integer.compare(this.ordinal(), Enum(other).ordinal());
|
return Integer.compare(this.ordinal(), Enum(other).ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Enum of the given class with the given ordinal value.
|
||||||
|
*/
|
||||||
|
public static function fromOrdinal (clazz :Class, ordinal :int) :Enum
|
||||||
|
{
|
||||||
|
var values :Array = (_enums[ClassUtil.getClass(clazz)] as Array);
|
||||||
|
if (values != null && ordinal >= 0 && ordinal < values.length) {
|
||||||
|
return values[ordinal];
|
||||||
|
}
|
||||||
|
throw new ArgumentError("No such enum [class=" + clazz + ", ordinal=" + ordinal + "].");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn a String name into an Enum constant.
|
* Turn a String name into an Enum constant.
|
||||||
*/
|
*/
|
||||||
@@ -181,7 +193,7 @@ public class Enum
|
|||||||
protected var _name :String;
|
protected var _name :String;
|
||||||
|
|
||||||
/** An array of enums for each enum class. */
|
/** An array of enums for each enum class. */
|
||||||
private static const _enums :Dictionary = new Dictionary(true);
|
private static const _enums :Dictionary = new Dictionary(true);
|
||||||
|
|
||||||
/** Is further instantiation of enum constants for a class allowed? */
|
/** Is further instantiation of enum constants for a class allowed? */
|
||||||
private static const _blocked :Dictionary = new Dictionary(true);
|
private static const _blocked :Dictionary = new Dictionary(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user