i am working on a large application which has differnt conditions(ifs) and different methods associated with it.Please suggest a way to optimize below mentioned code(reduce as much of nested ifs as possible).I would like the code to able incorporate any other specific condition with ease.(I use property files to fetch conditions)
.
public getParameter(String parameter)
{
if(parameter=specific condition1
||parameter=specific condition2)
{
do this
}
if(parameter=specific condition3)
{
do something else
}
if(parameter=specific condition4)
{
do something else
}
if(parameter=general condition)
{
do something else
}
else {
do something else
}
Say you have a property file with
(it seems you have a fixed set of actions)
You may load it with
Now you have a map linking action names (“do1”, etc.) to sets of possible values (“val1”, etc.).
You may execute the rules with
(I let you add the necessary checks to avoid null pointer exceptions for example)