java.lang.Objectnet.sf.eBus.util.Enum
All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
OpEnum, PriceType, MessageTypeEnum, ConnectStateEnum, SystemStatusEnum, ReportFrequencyEnum, Participant, DataTypeEnum
java.lang.Map and an
array to store the enumerated objects in the map using the
object name as key and in the array using the object ordinal
as the array index.
Extending Enum
Classes extending Enum should provide the
following:
Map. Use the ordinal as the array index and
the name as the Map's key. Note:
because the ordinal is used as an array index, you should
number the enumerated objects sequentially starting from
0.
public static MyEnum valueOf(int ordinal)
throws ArrayIndexOutOfBoundsException
{
return (_OrdinalMap.get(_ordinal));
}
public static MyEnum valueOf(String name)
{
return ((MyEnum) _NameMap.get(name));
}
See net.sf.eBus.util.logging.ReportFrequencyEnum for an Enum example.
Serializing an Enum
Because all enumerated objects are statically instantiated
and applications depending on == working for two separate
references to the same enumeration object, serialization
must reuse those existing enumeration objects and not create
new ones. If you are extending Enum and need to
serialize your enumeration objects, then do the following:
java.io.Serliazable interface.
Enum
base class will serialize only the _ordinal.
private Object readResolve()
throws ObjectStreamException
{
MyEnum retval = (MyEnum) _ordinalMap.get(_ordinal);
if (retval == null)
{
throw (
new InvalidObjectException(
"invalid ordinal (" + _ordinal + ")"));
}
return (retval);
}
< - a href="mailto:rapp@acm.org">Charles Rapp| Field Summary | ||
|---|---|---|
| protected final transient String | _name | The enumerated object's unique name. |
| protected final Integer | _ordinal | The enumerated object's unique integer index.
|
| Constructor: |
|---|
|
| Method from net.sf.eBus.util.Enum Summary: |
|---|
| compareTo, equals, getName, getOrdinal, hashCode, toString |
| Methods from java.lang.Object: |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from net.sf.eBus.util.Enum Detail: |
|---|
this Enum is less than,
equal to or greater than obj. |
true if obj is equal to
this ClassTypeEnum and false
otherwise. |
|
|
|
|