I am currently working on rewriting some codes in an Util class.
It has static Sets of configurable property data defined, that needs to be used based on certain boolean flags.
static Set<String> oneDayProperties = D
static Set<String> oneDayPropertiesWithB = D,B
static Set<String> oneDayPropertiesForM = D,B
static Set<String> oneDayPropertiesForMWithB = D,B
static Set<String> oneDayPropertiesForL = D,B
static Set<String> oneDayPropertiesForLWithB = D,B
static Set<String> oneDayPropertiesNonDefault = D,B
.
.
static Set<String> twoDayProperties = D,B
static Set<String> twoDayPropertiesWithB = D,B
static Set<String> twoDayPropertiesForM = D,B
static Set<String> twoDayPropertiesForMWithB = D,B
static Set<String> twoDayPropertiesForL = D,B
static Set<String> twoDayPropertiesForLWithB = D,B
static Set<String> twoDayPropertiesNonDefault = D,B
...
Which Set to return is based on the boolean properties sent as parameters to methods like below. There are multiple methods like this. All methods have the same set of parameters and return Set. Problem is if I need to add one more condition, it will make the code further ugly. Simple boolean parameters can be replaced with enums, but can't think of anything in this case because of these multi-dimensional conditions.
public static Set<String> get1DayProperties(boolean isForL, boolean isForM, boolean isBIncluded, String area) {
if (DataCacheConstants.DEFAULT_AREA.equals(area)) {
if (!isForL) {
return !isForM ? (!isBIncluded ? oneDayProperties : oneDayPropertiesWithB)
: (!isBIncluded ? oneDayPropertiesForM : oneDayPropertiesForMWithB);
}
else {
return !isBIncluded ? oneDayPropertiesForL : oneDayPropertiesForLWithB;
}
}
else {
return oneDayPropertiesNonDefault;
}
}
public static Set<String> get2DayProperties(boolean isForL, boolean isForM, boolean isBIncluded, String area) {
.
.
.
public static Set<String> get3DayProperties(boolean isForL, boolean isForM, boolean isBIncluded, String area) {
.
.
.
Any help with ideas is much appreciated.