我必须在java中实现以下逻辑:
如果Q3大小大于零,则根据条件C4对数据D2进行另一个查询Q4
现在,如果Q1结果大小为零,则根据条件C5对数据D1执行查询Q5
所以我正在考虑写下面的逻辑:
R1 = getResult (dataset D1, condition C1);
//Query on data D1 based on condition C1;
if (R1 is not null)
{
R2 = getResult (dataset R1, condition C2);// Query on data R1 based on condition C2;
if(R2 is null)
{
R3 = getResult (dataset R1, condition C3);// Query on data R1 based on condition C3
if(R3 is null)
{
R4 = getResult (dataset R1, condition C4);// Query on data R1 based on condition C4
display(R4);
}
else
{
display(R3);
}
}
else
{
display(R2);
}
}
else
{
R5 = getResult (dataset D1, condition C5);
if(R5 is not null)
{
R6 = getResult (dataset R5, condition C2);//Query on data R5 based on condition C2;
if(R6 is null)
{
R7 = getResult (dataset R5, condition C3);//Query on data R5 based on condition C3
if(R7 is null)
{
R8 = getResult(dataset R5, condition C4);//Query on data R5 based on condition C3
}
else
{
display(R8);
}
}
else
{
display(R6);
}
}
}
有没有更好的方法来改善这种逻辑?
答案 0 :(得分:0)
不,它不能做得更好,因为你有两个依赖链Q1 - > Q2 - > Q3 - > Q4和Q5 - > Q6 - > Q7 - > Q8通过Q1连接 - > Q5,其中A - > B表示如果A失败则执行B.你必须像你实施的那样经历这个链条。