I have;
public enum Detailed {
PASSED, INPROCESS, ERROR1, ERROR2, ERROR3;
}
and need to convert it to the following;
public enum Simple {
DONE, RUNNING, ERROR;
}
So first PASSED->DONE and INPROCESS->RUNNING, but all errors should be: ERROR. Obviously it is possible to write cases for all values, but there may be a better solution?
One way is to define a method
asSimple()in yourDetailedenum:You can then simply call the method when you want to do the mapping:
It has the advantage of putting the knowledge of the mapping with the
Detailedenum (where perhaps it belongs). It has the disadvantage of having knowledge ofSimplemixed in with the code forDetailed. This may or may not be a bad thing, depending on your system architecture.