I'm trying to refactor some code that looks similar to the code below. I feel that there should be a simpler way to do what it does. My main concern is the call to getDataB() in both if and else blocks of the (!dataA.isEmpty()) condition.
DataA dataA = getDataA();
if (!dataA.isEmpty()) {
if (dataA.getStatus() == Status.FINAL) {
// process finalized dataA
}
if (dataA.getStatus() == Status.RECEIVED) {
DataB dataB = getDataB();
if (!dataB.isEmpty()) {
dataA.setStatus(dataB.getStatus());
// process dataA with updated status from dataB
}
}
if (dataA.getStatus() == STATUS.IN_PROGRESS) {
// process in progress dataA
}
// empty dataA
} else {
Datab dataB = getDataB();
if (!dataB.isEmpty()) {
// process dataB
}
}
if
statementsStatus
orSTATUS
should probably have a consistent capitalisation. – ryan123 Aug 29 '19 at 10:26