Apache POI和圈代码的复杂性

时间:2017-08-14 05:31:38

标签: java excel apache-poi cyclomatic-complexity

我有一个Excel文件,我正在使用Apache POI API阅读;这让我可以控制Excel中的单元格/列。

我的Excel中有大约17列,这些列具有不同的数据类型。我想从这些列值填充模型对象。所以,我提出了类似下面的内容来填充我的模型对象:

private WHTApps populateModel(int columnIndex, Object cellValue) {
        WHTApps whtApp = new WHTApps();
        switch (columnIndex) {
        case 0:
            whtApp.setVendorCode((int) cellValue);
            break;
        case 1:
            whtApp.setVendorName((String) cellValue);
            break;
        case 2:
            whtApp.setCountry((String) cellValue);
            break;
        case 3:
            whtApp.setApplicationReceivedFromUSDate((Date) cellValue);
            break;
        case 4:
            whtApp.setContractNumber((String) cellValue);
            break;
        case 5:
            whtApp.setContractEffectiveDate((Date) cellValue);
            break;
        case 6:
            whtApp.setContractExpirationDate((Date) cellValue);
            break;
        case 7:
            whtApp.setAutomaticRenewal((String) cellValue);
            break;
        case 8:
            whtApp.setReducedRate((int) cellValue);
            break;
        case 9:
            whtApp.setForm17((String) cellValue);
            break;
        case 10:
            whtApp.setResidencyCertIssueDate((Date) cellValue);
            break;
        case 11:
            whtApp.setTaxAuthoritySubmissionDate((Date) cellValue);
            break;
        case 12:
            whtApp.setTaxAuthorityAcceptanceDate((Date) cellValue);
            break;
        case 13:
            whtApp.setStatus((String) cellValue);
            break;
        case 14:
            whtApp.setForm17Expiration((Date) cellValue);
            break;
        case 15:
            whtApp.setComments((String) cellValue);
            break;
        case 16:
            whtApp.setRemarks((String) cellValue);
            break;
        case 17:
            whtApp.setCategory((String) cellValue);
            break;
        default:
        }

        return whtApp;
    }

但是,这导致了极高的圈复杂度值19。

现在我如何减少圈复杂度,因为我需要在模型对象中填充17列?

感谢您帮助我

阿克沙伊

0 个答案:

没有答案