I need a suggestion for a proper approach to applying conditions in Java.
I have 100 conditions based on which I need to change the value of the String variable that will be displayed to the user.
approximate condition: a<5 && (b>0 && c>8) && d>9 || x!=4 a<5 && (b>0 && c>8) && d>9 || x!=4
Additional conditions exist, but the variables are the same.
I'm doing it right now:
if(condition1) else if(condition2) else if(condition3) ...
An alternative to a case switch will obviously be nested in if-else ie
if(condition1) switch(x) { case y: blah-blah } else if(condition2) switch(x) { case y: blah-blah } else if(condition3) ...
But I'm looking for some more elegant solutions, such as using an interface for this with polymorphic support. What could be, what can I do to avoid lines of code, or what should be right.
--- Edit ---

I really require this on an Android device. But its more java built here.
These are small snapshots of the conditions that I have with me. More will be added if some of them are correct. This will obviously require more if-else, and they can also be nested. In this case, the processing will be slow.
I save messages in a separate class with various string variables that I saved, so if the condition becomes true, then I select a static variable from a single class and show that one. Would it be correct to save the resulting messages.
java switch-statement if-statement condition
Prateek
source share