I have a class which call country specific functions for different use cases. I want to generalise the logic in such a way that if I specify the country name & the method name, the same method for that country's class gets executed.
Predicate Class:- https://docs.oracle.com/javase/8/docs/api/java/util/function/Predicate.html
private static void countrySpecificMethod(String countryName, Predicate predicate){
if(countryName.equals("EGYPT")){
// call the predicate function in EGYPT class
} else if (countryName.equals("INDIA")) {
// call the predicate function in INDIA class
} else if (countryName.equals("HUNGARY")) {
// call the predicate function in HUNGARY class
} else if(countryName.equals("TURKEY")){
// call the predicate function in TURKEY class
} else if(countryName.equals("ITALY")){
// call the predicate function in ITALY class
} else if(countryName.equals("VIETNAM")){
// call the predicate function in VIETNAM class
} else{
// call the predicate function in same class
}
}
Example:-
countrySpecificMethod("EGYPT", prepareAddress)
It should then call EGYPT.prepareAddress()
countrySpecificMethod("EGYPT", prepareUser)
It should then call EGYPT.prepareUser()
Any help how this can be achieved?