How can I simplify this example code to be more elegant, for example in functional style if it possible.
private static String resolveTypes(String messageType, String accountType) {
String result = "";
if(messageType.equals("PDF") && accountType.equals("NEXT")){
result = "2015";
}
if(messageType.equals("CSV") && accountType.equals("NEXT")){
result = "2016";
}
if(messageType.equals("CSV") && accountType.equals("BEFORE")){
result = "2017";
}
if(messageType.equals("PDF") && accountType.equals("BEFORE")){
result = "2018";
}
return result;
}
How would lambdas help at all?
The 'key' class needs functional equals and hashCode impls, here done with lombok's
@Value
.The MAP can also be built up from an input text file (use
getResourceAsStream
and a static initializer if you prefer.