Reduce Cyclomatic Complexity of Switch Statement - Sonar

前端 未结 7 1836
囚心锁ツ
囚心锁ツ 2021-01-17 22:50

I want to reduce cyclomatic complexity of my switch case my code is :

public String getCalenderName() {
        switch (type) {
    case COUNTRY:
        r         


        
相关标签:
7条回答
  • 2021-01-17 23:14
    public String getName() {
        if (type == null) {
            return name;
        }
        if (type == BusinessCalendarType.COUNTRY) {
            return country == null ? name : country.getName() + HOLIDAY_CALENDAR;
        } else if (type == BusinessCalendarType.CCP) {
            return ccp == null ? name : ccp.getName() + " CCP" + HOLIDAY_CALENDAR;
        } else if (type == BusinessCalendarType.EXCHANGE) {
            return exchange == null ? name : exchange.getName() + HOLIDAY_CALENDAR;
        } else if (type == BusinessCalendarType.TENANT)  {
            return tenant == null ? name : tenant.getName() + HOLIDAY_CALENDAR;
        } else {
            return name;
        }
    }
    

    this worked for me

    0 讨论(0)
提交回复
热议问题