I have a flow where if a certain condition is true then I should take another approach. That condition can be triggered by different scenarios. But each condition test must be done only if the last one failed. Once a condition is true there is no further logical tests to do. My question is how to do that in an elegant way, the way I'm doing it right now requires an indentation for each condition.
StatusCode statusCode = null;
boolean invokeService = true;
CardPort cardPort = findCardPort(card, port);
if (cardPort == null) {
statusCode = StatusCode.CARD_PORT_NOT_FOUND;
} else {
Sim sim = cardPort.getSim();
if (sim == null) {
statusCode = StatusCode.CARD_WITHOUT_SIM;
} else {
User user = sim.getUser();
if (user == null) {
statusCode = StatusCode.SIM_WITHOUT_USER;
}
}
}
if (statusCode != null) {
invokeService = false;
}