I have an Excel file, which I am reading using Apache POI APIs; which gives me control over cells/columns in my Excel.
I have around 17 columns in my Excel and these are with different datatypes. I want to populate a model object from these column values. So, I came up with something like below to populate my model object:
private WHTApps populateModel(WHTApps whtApp, int columnIndex, Object cellValue) {
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;
}
But, this gives rise to a really high cyclomatic complexity value of 19.
Now how do I reduce the cyclomatic complexity as I have 17 columns which I need to populate in my model object?
WHTApps app1 = populateModel(0, "code");
and ` WHTApps app2 = populateModel(1, "name");` will return different objects. Is that correct? \$\endgroup\$