In my query I can't use hibernate and I need to generate a String as follows:
I have Map<String, String> restrictions
instance with 3 keys (id
, name
and value
) and I want to get the entry (String
).
if (restrictions.get("id") != null && restrictions.get("name") == null && restrictions.get("value") == null){
return "ID = " + restrictions.get("id");
} else if (restrictions.get("id") != null && restrictions.get("name") != null && restrictions.get("value" != null)){
return "ID = " + restrictions.get("id") + " and Name = " + restrictions.get("name");
}
And so forth...
Explicitly writting the if-else
clauses is very unflexible and hardly maintainable way. Any ideas?