I have one enum
\'class\' called Example
as follows:
enum Example {
//enums belonging to group A:
enumA1,
enumA2,
enumA3,
//en
I would use a very simple enum constructor which associates the corresponding group with the enum value:
public enum Example {
ENUM_A1 (Group.A),
ENUM_A2 (Group.A),
ENUM_A3 (Group.A),
ENUM_B1 (Group.B),
ENUM_B2 (Group.B),
ENUM_B3 (Group.B),
ENUM_C1 (Group.C),
ENUM_C2 (Group.C),
ENUM_C3 (Group.C);
private Group group;
Example(Group group) {
this.group = group;
}
public boolean isInGroup(Group group) {
return this.group == group;
}
public enum Group {
A,
B,
C;
}
}
Usage:
import static Example.*;
import Example.Group;
...
ENUM_A1.isInGroup(Group.A); // true
ENUM_A1.isInGroup(Group.B); // false
To do the subgroups you can do a similar kind of structure for Group as for Example, using Group(SubGroup ... subgroups)
as a constructor and an EnumSet
to contain the subgroups.