[英]How to fix sonar issues for Reduce the number of conditional operators (5) used in the expression (maximum allowed 3) in java
ObjectTest systemError = (ObjectTest ) o;
//New Code
result &= Objects.equals(this.exp1, systemError.exp1);
result &= Objects.equals(this.exp2, systemError.exp2) ;
result &= Objects.equals(this.exp3, systemError.exp3);
result &= Objects.equals(this.exp4, systemError.exp4);
result &= Objects.equals(this.exp5, systemError.exp5) ;
result &= Objects.equals(this.exp6, systemError.exp6);
return result;
//Old Code
return Objects.equals(this.exp, systemError.exp) &&
Objects.equals(this.exp1, systemError.exp1) &&
Objects.equals(this.exp2, systemError.exp2) &&
Objects.equals(this.exp3, systemError.exp3) &&
Objects.equals(this.exp4, systemError.exp4) &&
Objects.equals(this.exp5, systemError.exp5) &&
Objects.equals(this.exp6, systemError.exp6);
Does the New code is the solution for Old code?Can any one shed some confirmation on this.新代码是旧代码的解决方案吗?任何人都可以对此进行确认。
Note that a &= b
is same as a = a & b
which will have the same result as a = a && b
for practical purposes (except for performance as irrespective of the value of a
, b
will also be evaluated in case of a & b
while in case of a && b
, b
is not processed if a
is false
)请注意, a &= b
与a = a & b
相同,出于实际目的,其结果与a = a && b
相同(除了与a
的值无关的性能外, b
也将在 a 的情况下a & b
评估a & b
而在a && b
的情况下,如果a
为false
则不处理b
)
On this basis, your new code can be indeed the solution for the old code provided you start your new code with result = Objects.equals(this.exp, systemError.exp);
在此基础上,如果您以result = Objects.equals(this.exp, systemError.exp);
开始您的新代码,那么您的新代码确实可以成为旧代码的解决方案。 and end it with return result;
并以return result;
Feel free to let me know if you still have any problem understanding it and I will try to elaborate my explanation a bit further.如果您在理解它时仍有任何问题,请随时告诉我,我将尝试进一步详细说明我的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.