我需要在一组规则中编写具有许多条件(最多30个条件)的逻辑,其中包含许多if else条件,并且它可以在所有条件之间或之后结束.
以下是我尝试过的一些示例代码.这给了我结果,但看起来并不好,在一种情况下任何轻微的失误都需要永远跟踪.
到目前为止我所尝试的是,找出共同的条件并重构一些方法.尝试创建具有条件和各种集合的接口将实现它.
如果您有任何建议来设计这个,会对我有所帮助.不寻找详细的解决方案,但即使是暗示也会很棒.
private Boolean RunCondition(Input input) {
Boolean ret=false;
//First if
if(input.a.equals("v1")){
//Somelogic1();
//Second if
if(input.b.equals("v2"))
//Third if
if(input.c >1)
//Fourth if
//Somelogic2();
//Go fetch key Z1 from database and see if d matches.
if(input.d.equals("Z1"))
System.out.println("Passed 1");
// Fourth Else
else{
System.out.println("Failed at fourth");
}
//Third Else
else{
if(input.aa.equals("v2"))
System.out.println("Failed at third");
}
//Second Else
else{
if(input.bb.equals("v2"))
System.out.println("Failed at second");
}
}
//First Else
else{
if(input.cc.equals("v2"))
System.out.println("Failed aat first");
}
return ret;
}
public class Input { …Run Code Online (Sandbox Code Playgroud) 我想将十进制转换为ascii,这是代码返回意外的结果.这是我正在使用的代码.
public static void main(String[] args) {
char ret= (char)146;
System.out.println(ret);// returns nothing.
Run Code Online (Sandbox Code Playgroud)
我希望按照http://www.ascii-code.com/获得角色单曲"'" 任何人都会遇到这个?谢谢.