相关文章推荐
爱笑的碗  ·  杭州互联网法院调解平台·  2 周前    · 
很拉风的日记本  ·  PHP Fatal error: ...·  9 月前    · 
爽快的手链  ·  geometry - How do CSS ...·  1 年前    · 
谦和的菠萝  ·  SQL Server Native ...·  1 年前    · 
力能扛鼎的饭卡  ·  原 ...·  1 年前    · 

来源: https://stackoverflow.com/questions/37046882/the-cyclomatic-complexity-of-this-method-is-greater-than-authorized

public static boolean isNoneBlank(String... strings) {
    for (String string : strings) {
        if (!StringUtils.isNotBlank(string)) {
            return false;
    return true;

Or if you're already on Java 8 with Streams and Lambda support:

public static boolean isNoneBlank(String... strings) {
    return Arrays.stream(strings).allMatch(StringUtils::isNotBlank);

Now you can make use of it as below:

public boolean isVoNotNull() {
    return isNoneBlank(this.cardNo, this.otp, this.password, this.userid, this.type, this.walletMobileNo);

You could further reduce the boilerplate by removing the unnecessary this.

public boolean isVoNotNull() {
    return isNoneBlank(cardNo, otp, password, userid, type, walletMobileNo);

This all was an appliance of the Don't Repeat Yourself (DRY) software engineering principle.

That said, as msandiford pointed out, it turns out that Apache Commons Lang StringUtilshas since version 3.2 already exactly this method. So if you don't have it yet, consider upgrading Apache Commons Lang to at least 3.2.

public boolean isVoNotNull() {
    return StringUtils.isNoneBlank(cardNo, otp, password, userid, type, walletMobileNo);

shareimprove this answer

int[] array1 = null; array1是数组类型的引用,栈中名为array1的内存间没有存放任何地址。数组数组其实就是数组的长度为0,数组是真正的对象,只是对象中没有元素,也就是说里面没有内容 int[] array = {}; 此时创建了数组数组的长度为0,是一个数组,但是array不是null,它也是一个对象,只不过它的元素个数为0。 2.判断数组是否 Sonar建议汇总标签(格分隔): 工具 编码规范The Cyclomatic Complexity of this method “deleteMission” is 14 which is greater than 10 authorized嵌套复杂度为14,高于限定值10Refactor this code to not nest more than 3 if/for/while/switc request.getParameterValues("choosedelete"); 这里的值是的。但是不知应怎么来判断choosedelete里的值是的。一直出现异常。 但是一直异常不断 后来突然意识的这里很蹊跷;研究了好长时间,终于得出了判断的方法:分析如下: 1,我们必须判断String[] cho