[英]How can I improve this logic?
I have to implement following logic in java:我必须在java中实现以下逻辑:
If Q3 size is more than zero then make another query Q4 on data D2 based on condition C4如果 Q3 大小大于零,则根据条件 C4 对数据 D2 进行另一个查询 Q4
Now if Q1 result size is zero then execute query Q5 on data D1 based on condition C5现在,如果 Q1 结果大小为零,则根据条件 C5 对数据 D1 执行查询 Q5
So I'm thinking about to write the below logic:所以我正在考虑编写以下逻辑:
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);
}
}
}
Is there a better way to improve this logic?有没有更好的方法来改进这个逻辑?
No, it cannot be done better because you have this two dependency chains Q1 -> Q2 -> Q3 -> Q4 and Q5 -> Q6 -> Q7 -> Q8 which are connected by Q1 -> Q5, where A -> B means that B is executed if A fails.不,它不能做得更好,因为你有这两个依赖链 Q1 -> Q2 -> Q3 -> Q4 和 Q5 -> Q6 -> Q7 -> Q8 由 Q1 -> Q5 连接,其中 A -> B 表示如果 A 失败,则执行 B。 You have to go through this chains like you have implemented.你必须像你已经实施的那样经历这个链条。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.