I need to fire different methods depending on the value of parent
and child
which are different values of the same enum type. Currently I do this:
switch (parent)
{
case DEPARTMENT:
{
switch (child)
{
case TERMINAL:
{
event1();
break;
}
case OPERATOR:
{
event2();
break;
}
}
break;
}
case OPERATOR:
{
switch (child)
{
case TERMINAL:
{
event3();
break;
}
}
break;
}
}
The actual code contains 5-10 cases, with each case executing one or more long lines of code (methods with multiple arguments).
I tried populating a two-dimensional array with Runnable
s but it executed 2x slower.
Is there an alternative way of writing this, which would be more readable, yet nearly as fast?