考虑以下枚举类
public enum ClassA {
CHECK1("X", 0),
CHECK2("Y", 2),
CHECK3("Z", 1);
private final String id;
private final String cdValue;
private ClsA(String id, String cdValue) {
this.id = id;
this.cdValue = cdValue;
}
private String getId() {
return id;
}
private String getCdValue() {
return cdValue ;
}
private static final List<String> cdValues = new ArrayList<String>();
static {
for (ClassA clsA : ClassA.values()) {
cdValues.add(clsA.getCdValue());
}
}
public boolean isCdValue(String cdValue)
{
if clsValues.contains(cdValue)
return true;
else return false;
}
} …Run Code Online (Sandbox Code Playgroud) 我们目前有两个客户代码"CUSTA"和"CUSTB".CUSTA可以执行操作A1,A2,A3,A4,A5,A6.CUSTB可以根据某些条件执行操作B1,B2,B3,B4,B5,B6.目前他们不再期待更多客户代码,但我希望设计灵活.这些可以存储在数据库中,但正如我所提到的,因为很长一段时间不可能有另一个客户代码,它需要用代码表示.
应用程序逻辑基本算法看起来像
if ConditionX is true
then if customerCode is "CUSTA"
then applicableOperation = 'A1'
else
if customerCode is "CUSTB"
then applicableOperation = 'B1'
end
else
if ConditionY is true
then
if customerCode is "CUSTA"
then applicableOperation = 'A2'
else
if customerCode is "CUSTB"
then applicableOperation = 'B2'
end
else
Run Code Online (Sandbox Code Playgroud)
............... .................
我可以编写switch语句等来清理算法,但主要关注的是如何表示"CUSTA","CUSTB","A1","A2","A3","A4"......"A6" , "B1", "B2" ... "B6".客户代码是否像枚举一样
public enum CustomerCode { CUSTA, CUSTB }
public enum OperationsForA{ A1, A2, A3,...A6 }
public enum OperationsForB{ B1, B2, B3...B6}
Run Code Online (Sandbox Code Playgroud)
我应该创建一个Map …