Typesafe Enum decoding
Ive implemented the typesafe enum pattern, for use in communication packet headers (three implementations, packet Type, packet Opcode, and ErrorCode).
The instances classes of these need to be convertable to and from an int value. I achieved this with a "toInt()" function returning the value associated with the instance, and a static parse(int i) function that uses a switch to return the instance associated with the incoming integer value.
However, the switch statement inside the parse() function is getting large, and ugly looking, not to mention becoming a maintanance nightmare.
I'm contemplating adding a static Hashtable to each typesafe enum class, that holds a list of the instances, with the int code as the key. Is this sound? Is there a "proper" way of doing this, or simply a better way?
PyrosX

