Decide on a set of enum's of similar structure, dynamically based on a parameter.
example :
public enum StateUS {
CALIFORNIA(Sacramento,...)
private String capital;
...
}
public enum StateIN {
KARNATAKA(Bangalore,...)
private String capital;
...
}
public enum Countries {
US, IN
}
// in a different class
public <> getStates(Countries country){
// to return Country.US.equals(country) ? StateUS : StateIN
// so the return enum class can be used for business logic.
}
Based on the value of enum Countries, need to decide whether to use StateUS or StateIN.
what's the best way to implement the same using enum's ? Can a factory class be implemented to decide on enum ?
Solution I can think of is to convert enum's into classes and create a factory class. But this is a tedious procedure and too much of boiler code to get enum functionalities (ex : comparisons).