I'm running into issues with an approach I am taking and am now wondering if I just started down the wrong path and should rethink my approach. Here is what I attempting.
I would like to use an Enum to represent different possible Account Statuses (there are other finite data sets that I will be setting up using a duplicate approach):
- A, Active
- I, Inactive
- P, Pending
Those Account Statuses must be presented to the user in their language if preference.
Example: Account Status is A, show it as Active for English speakers and Activo for Spanish.
There are also situations where I would like to show a dropdown list of all possible Account Statuses in the appropriate locale preference.
Current Approach
Use an AccountStatusEnum class with values of (A,I,P).
In a private static member variable store an EnumMap of localized Account Statuses inside a EnumMap of possible Locales.
Example:
private static EnumMap<LocaleEnum, EnumMap<AccountStatusEnum, String>> localeAccountStatuses = new EnumMap<LocaleEnum, EnumMap<AccountStatusEnum, String>>(LocaleEnum.class);
This would get loaded within a static initialization block.
I could then use the following methods to get all the values for a dropdown:
public static EnumMap<AccountStatusEnum, String> getAccountStatuses(LocaleEnum locale) {
return localeAccountStatuses.get(locale);
}
Or I could use this method to get a single description for a given Enum:
public String getDescription(LocaleEnum locale){
return getAccountStatuses(locale).get(this);
}
Example Usage: AccountStatusEnum.A.getDescription(LocaleEnum.es_MX);
I'm curious about your thoughts on this approach and possible better approaches for accomplishing the same thing.
EDIT The logic to get the values to populate the Enums would be centralized within a single helper class. Therefore if the source of the descriptions changes to come from a new source, the code change is minimized.
Thanks