anyone has ideas about making this block of if-else statements simpler other than purely using switch-case statements? Thanks for your time!
public void onButtonClick(int type, int state) {
if (type == 1) {
if (state == 1)
jsonDataToString(); // method 1
else if (state == 2)
filterRecordFile(); // method 2
else if (state == 3)
filterResourceFile(); // method 3
} else if (type == 2) {
if (state == 1)
jsonDataToString(); // method 1
else if (state == 2)
filterHasBackup(); // method 4
else if (state == 3)
filterNotBackup(); // method 5
} else if (type == 3) {
if (state == 1)
jsonDataToString(); // method 1
else if (state == 2)
filterOverSize(); // method 6
else if (state == 3)
filterDownSize(); // method 7
}
}
state == 1, the same method is executed unrelated to the value oftype.onButtonClick()looks like you might be using that in action listeners or something like that. If you're assigning the same listener to multiple buttons and just use type and state to distinguish between them then I'd suggest using different listeners instead.