An integer selector calculated from the combined values of parent
and child
will be faster:
public enum Stuff { DEPARTMENT, OPERATOR, TERMINAL };
Stuff parent = ...;
Stuff child = ...;
int selector = parent.ordinal() * Stuff.values().length + child.ordinal();
switch(selector)
{
case 0 : // parent=DEPARTMENT child=DEPARTMENT
...
case 1 : // parent=DEPARTMENT child=OPERATOR
...
...
case 3 : // parent=OPERATOR child=DEPARTMENT
...
case 8: // parent=TERMINAL child=TERMINAL
...
}
Some combinations may not be meaningful, just omit them and provide a default
with nothing in it. You could also define constants in the enum:
private static final int n = values().length; // for brevity
public static final int DEPARTMENT_DEPARTMENT = DEPARTMENT.ordinal() * n + DEPARTMENT.ordinal()
...
and use those in the case statements.