|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.core.util.enum.BaseEnum
This class acts as the base enumeration for all enumerated types in the system. It provides a simple and convenient mechanism to create new sets of enumeration instances and access them via ordinal or name based lookup.
This class also provides for the system wide storage of these objects, via static reference, so that all instances of a particular value of an enumerated type will in fact be the same instance. This has the advantage of allowing reference equals ("==") operations to work for instance comparison providing for very fast checks.
This base implementation will return null from most methods if unable
to return the requested information. Subclasses are expected to check for
these nulls and throw an appropriate subclass of
EnumNotFoundException
.
Copyright 2002 Sapient
Nested Class Summary | |
private static class |
BaseEnum.EnumTypeAggregator
This inner class of the BaseEnum system catalogs all enumeration instances for one particular class of enumerated values. |
Field Summary | |
private static Map |
enumTypeMap
A static cache of the enum types currently loaded in the system. |
protected String |
name
The string representation of this enumeration instance |
protected int |
ordinal
The ordinal representation of this enumeration instance |
Constructor Summary | |
protected |
BaseEnum(Class enumeratedType,
String name)
Constructs a new instance of the specific enumerated type automatically selecting the next ordinal value for it and placing references to it into the main catalogue for this type. |
protected |
BaseEnum(Class enumeratedType,
String name,
int ordinal)
Constructs a new instance of the specific enumerated type with the specified name and ordinal values. |
Method Summary | |
boolean |
equals(Object that)
This implementation of equals does instance reference comparisons since all instances of single type actually are the same object. |
static BaseEnum |
getByName(String name,
Class enumeratedType)
Static accessor to the specified enumerated type value. |
static BaseEnum |
getByOrdinal(int ordinal,
Class enumeratedType)
Static accessor to the specified enumerated type value. |
private static BaseEnum.EnumTypeAggregator |
getEnumTypeAggregator(Class enumeratedType)
Gets the EnumTypeAggregator for the given enumeratedType |
String |
getName()
Accesses the name of this enumeration instance |
int |
getOrdinal()
Accesses the ordinal represenation of this enumeration instance |
int |
hashCode()
This implementation of hashCode provides the system hashCode (location in memory) since all instances of single type actually are the same object. |
static Iterator |
iterator(Class enumeratedType)
Static accessor to an iterator for all instances of a specific enumeration type. |
String |
toString()
Returns a string representation of this enumeration instance that includes its true class type, its enumeration name and its ordinal value. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected String name
protected int ordinal
private static Map enumTypeMap
Constructor Detail |
protected BaseEnum(Class enumeratedType, String name)
Constructs a new instance of the specific enumerated type automatically selecting the next ordinal value for it and placing references to it into the main catalogue for this type.
Note: Never mix the usage of the two constructors of this class in subclasses. This can lead to improperly numbered enumerations.
enumeratedType
- the class type to buildname
- the name or system wide string key to the enum instanceprotected BaseEnum(Class enumeratedType, String name, int ordinal)
Note: Never mix the usage of the two constructors of this class in subclasses. This can lead to improperly numbered enumerations.
enumeratedType
- the subclass of BaseEnum to create an enumeration
instance ofname
- the String representation (name) of this typeordinal
- the ordinal value reperesentation of this typeMethod Detail |
public String getName()
public int getOrdinal()
public String toString()
toString
in class Object
public final boolean equals(Object that)
equals
in class Object
that
- the enum object to compare against
public final int hashCode()
hashCode
in class Object
public static final BaseEnum getByName(String name, Class enumeratedType)
name
- the name of the enumeration instance to returnenumeratedType
- a subclass of BaseEnum which is the type of
the instance to return
public static final BaseEnum getByOrdinal(int ordinal, Class enumeratedType)
ordinal
- the ordinal value of thisenumeratedType
- a subclass of BaseEnum which is the type of
the instance to return
public static final Iterator iterator(Class enumeratedType)
enumeratedType
- a subclass of BaseEnum which is the type of
the instance to return
private static BaseEnum.EnumTypeAggregator getEnumTypeAggregator(Class enumeratedType)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |