Packagecom.threerings.util
Classpublic class Enum
ImplementsComparable, Hashable
SubclassesByteEnum

Base enum class for actionscript. Works pretty much like enums in Java, only you've got to do one or two things. To use, you'll want to subclass and have something like the following: public final class Foo extends Enum { public static const ONE :Foo = new Foo("ONE"); public static const TWO :Foo = new Foo("TWO"); finishedEnumerating(Foo); / {at}private / public function Foo (name :String) { super(name); } public static function valueOf (name :String) :Foo { return Enum.valueOf(Foo, name) as Foo; } public static function values () :Array { return Enum.values(Foo); } } Important notes for Enum implementors: - make your class final - create a constructor that calls super(name) - declare your enum constants const, and with the same String as their name. - call finishedEnumerating() at the end of your constants. - your enum objects should be immutable - implement a static valueOf() and values() methods for extra points, as above. Note for Enum users: The same Enum class in different ApplicationDomains could cause confusion, as the Enums will not be equal (neither will their Class objects, or in all probabability, the Hashable, Equalable, or Comparable classes, so there could be larger problems.



Protected Properties
 PropertyDefined by
  _name : String
The String name of this enum value.
Enum
Public Methods
 MethodDefined by
  
Enum(name:String)
Call this constructor in your enum subclass constructor.
Enum
  
compareTo(other:Object):int
Enum
  
equals(other:Object):Boolean
Enum
  
hashCode():int
Enum
  
name():String
Get the name of this enum.
Enum
  
ordinal():int
Get the ordinal of this enum.
Enum
  
toString():String
Return the String representation of this enum.
Enum
  
valueOf():Object
Return the primitive value of this Object.
Enum
  
values(clazz:Class):Array
[static] Get all the enums of the specified class, or null if it's not an enum.
Enum
Protected Methods
 MethodDefined by
  
finishedEnumerating(clazz:Class):void
[static] This should be called by your enum subclass after you've finished enumating the enum constants.
Enum
Property detail
_nameproperty
protected var _name:String

The String name of this enum value.

Constructor detail
Enum()constructor
public function Enum(name:String)

Call this constructor in your enum subclass constructor.

Parameters
name:String
Method detail
compareTo()method
public function compareTo(other:Object):intParameters
other:Object

Returns
int
equals()method 
public final function equals(other:Object):BooleanParameters
other:Object

Returns
Boolean
finishedEnumerating()method 
protected static function finishedEnumerating(clazz:Class):void

This should be called by your enum subclass after you've finished enumating the enum constants. See the example in the class header documentation.

Parameters
clazz:Class
hashCode()method 
public final function hashCode():int

Returns
int
name()method 
public final function name():String

Get the name of this enum.

Returns
String
ordinal()method 
public final function ordinal():int

Get the ordinal of this enum. Note that you should not use the ordinal in normal cases, as it may change if a new enum is defined. Ordinals should only be used if you are writing a data structure that generically handles enums in an efficient manner, and you are never persisting anything where the ordinal can change.

Returns
int
toString()method 
public function toString():String

Return the String representation of this enum.

Returns
String
valueOf()method 
public function valueOf():Object

Return the primitive value of this Object. The default implementation for Enums is to return the ordinal.

Returns
Object
values()method 
public static function values(clazz:Class):Array

Get all the enums of the specified class, or null if it's not an enum.

Parameters
clazz:Class

Returns
Array