Can I refactor like this, are these equivalent and therefore the simpler straighforward version of the code is preferred?
Before refactoring:
if (!matcher.matches() && !matcher2.matches() && !matcher3.matches()
&& !matcher4.matches() && !matcher5.matches()
&& !matcher6.matches() && !matcher7.matches()
&& !matcher8.matches()) {
return true;
} else
return false;
After refactoring:
return (matcher.matches() || matcher2.matches() || matcher3.matches()
|| matcher4.matches() || matcher5.matches()
|| matcher6.matches() || matcher7.matches()
|| matcher8.matches())
Actually, no. The first one is true
only when all matchers don't match. If all matchers don't match in the second statement, you return false
return !(matcher.matches() || matcher2.matches() || matcher3.matches()
|| matcher4.matches() || matcher5.matches()
|| matcher6.matches() || matcher7.matches()
|| matcher8.matches())
This is correct
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With