I'm working on some code which has a large number of constants to be defined. It primarily deals with Marketplace constants (could be US, UK, INDIA, JAPAN) and associated MarketplaceMerchantMapping which basically maps a MerchantID with a MarketplaceID.
For example:
public enum Marketplace {
US("US"),
JP("JP"),
UK("UK"),
IN("IN"),
NZ("NZ"),
CA("CA"),
FR("FR"),
...
...
// This could go up to some 400 marketplaces
private final String stringValue;
public boolean isWest() {
return this == US || this == CA || this == UK;
}
public boolean isEast() {
return this == IN || this == NZ || this == JP;
}
}
public enum MarketplaceMerchantMapping {
USMAP(MarketplaceID.US, MerchantID.US, Marketplace.US),
JPMAP(MarketplaceID.JP, MerchantID.JP, Marketplace.JP),
UKMAP(MarketplaceID.UK, MerchantID.UK, Marketplace.UK),
NZMAP(MarketplaceID.NZ, MerchantID.NZ, Marketplace.NZ),
INMAP(MarketplaceID.IN, MerchantID.IN, Marketplace.IN),
CAMAP(MarketplaceID.CA, MerchantID.CA, Marketplace.CA),
FRMAP(MarketplaceID.FR, MerchantID.FR, Marketplace.FR),
...
...
// THis can go up to 400 Marketplaces * Number of merchantIds in each marketplace.
}
There are other similar constants defined similarly as enums or static constants.
This really is not scalable because every time we add support for a new Marketplace and Merchants, we need to go and update a bunch of files and test them and these config changes themselves take up a lot of developer time.
Ideally, I would like to know if there some way to define these constants in some config file and read those files to create the constants. Is there a way to create such enum constants by reading and parsing some config file?
So that if I have a config file with the following entries:
ConfigFile.cfg:
WestMarketplaces = ("US", "AG", "MX", "CA", ...) // Expand this later as required
EastMarketplaces = ("IN", "AU", "SG", "JP", ...) // Expand this later as required
EUMarketplaces = ("UK", "FR", "SP", ...) // Expand this later as required
WestMerchantIds = ("WA", "WB", "WC", "WD", ...) // Expand this later as required
WestMerchantIds = ("EA", "EB", "EC", "WD", ...) // Expand this later as required
EUMerchantIds = ("EUA", "EUB", "EUC", "WDD", ...) // Expand this later as required
marketplaceMerchantMapping = {
"US" = "WA";
"CA" = "WB";
"MX" = "WC";
"AU" = "EA";
"IN" = "EB";
"JP" = "EC";
"UK" = "EUA";
"FR" = "EUB";
...
} // Expand this later as required
Then, can it read these constants from the config file and build the appropriate enums or static constants?
Is this possible to do?