|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.avalon.framework.Enum
Basic enum class for type-safe enums. Should be used as an abstract base. For example:
import org.apache.avalon.framework.Enum; public final class Color extends Enum { public static final Color RED = new Color( "Red" ); public static final Color GREEN = new Color( "Green" ); public static final Color BLUE = new Color( "Blue" ); private Color( final String color ) { super( color ); } }If further operations, such as iterating over all items, are required, the
Enum(String, Map)
constructor can be used to populate a Map
, from which
further functionality can be derived:
public final class Color extends Enum { static final Map map = new HashMap(); public static final Color RED = new Color( "Red", map ); public static final Color GREEN = new Color( "Green", map ); public static final Color BLUE = new Color( "Blue", map ); private Color( final String color, final Map map ) { super( color, map ); } public static Iterator iterator() { return map.values().iterator(); } }
NOTE: between 4.0 and 4.1, the constructors' access has been changed
from public
to protected
. This is to prevent users
of the Enum breaking type-safety by defining new Enum items. All Enum items
should be defined in the Enum class, as shown above.
Constructor Summary | |
protected |
Enum(java.lang.String name)
Constructor to add a new named item. |
protected |
Enum(java.lang.String name,
java.util.Map map)
Constructor to add a new named item. |
Method Summary | |
boolean |
equals(java.lang.Object other)
Tests for equality. |
java.lang.String |
getName()
Retrieve the name of this Enum item, set in the constructor. |
int |
hashCode()
Returns a hash code value for the object. |
java.lang.String |
toString()
Human readable description of this Enum item. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Enum(java.lang.String name)
Note: access changed from public
to
protected
after 4.0. See class description.
name
- Name of the item.protected Enum(java.lang.String name, java.util.Map map)
Note: access changed from public
to
protected
after 4.0. See class description.
name
- Name of the item.map
- A Map
, to which will be added a pointer to the newly constructed
object.Method Detail |
public final boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public final java.lang.String getName()
String
of this Enum itempublic java.lang.String toString()
toString
in class java.lang.Object
type[name]
, eg.:
Color[Red]
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |