In my application, I need to fork out if the input matches some specific 20 elements.
I was thinking about using an enumeration
public enum dateRule { is_on, is_not_on, is_before,...}
and enum constant switch to execute function
switch(dateRule.valueOf(input))
{
case is_on :
case is_not_on :
case is_before :
.
.
.
break;
}
But the input lines will look like "on on", "not included", "before", etc. without _ between words. I found out that an enumeration cannot contain constants containing space.
Possible ways I could figure out:
1, using an if statement to compare 20 possible inputs that give a long if statement, for example
if(input.equals("is on") ||
input.equals("is not on") ||
input.equals("is before") ...) {
2, Work on the input to insert _ between words, but even with other input lines that do not fall under this 20, can have several words.
Is there a better way to implement this?
source
share