Pmd told me this method (thirdRowsValidation) has a complexity of 14 but I cannot reach a patter to reduce the code.
indexBookngEnd, indexTravelStart ... all those variables are indexes from other array made in another loop iteration (Header of the columns of a csv file) - Ref1
public void thirdRowsValidation(String thirdRowCsv) {
String[] lines1 = thirdRowCsv.split(",");
for (int i = 0; i < lines1.length; i++) {
if (indexBookngEnd == i && "".equals(temporalValidateBookngEnd)) {
temporalValidateBookngEnd = (" to " + lines1[i] + "\n");
}
if (indexBookngStart == i
&& !("".equals(temporalValidateBookngEnd))) {
finalOutput.append("Then it should have booking window ");
indexBookngStart = -1;
}
if (indexTravelEnd == i && "".equals(temporalValidateTravelEnd)) {
temporalValidateTravelEnd = (" to " + lines1[i] + "\n");
}
if (indexTravelStart == i
&& !("".equals(temporalValidateTravelEnd))) {
finalOutput.append("Then it should have travel window ");
String idHeaderColumn = String.format("%1$-" + 5 + "s", "id");
String typeHEaderColumn = String.format("%1$-" + 50 + "s","type");
finalOutput.append("| ");
finalOutput.append(idHeaderColumn);
indexTravelStart = -1;
}
if (indexPackageDescription == i) {
temporalPackages = String.format("%1$-" + 50 + "s", lines1[i]);
}
if (indexPackageCode == i
&& !(lines1[i].matches("[+-]?\\d*(\\.\\d+)?"))
&& indexTravelStart == -1) {
finalOutput.append("| ");
}
}
}
Ref1:
public void secondRowValidation(String secondRowCsv) {
String[] lines1 = secondRowCsv.split(",");
for (int i = 0; i < lines1.length; i++) {
if ("Bookng start".equalsIgnoreCase(lines1[i])) {
indexBookngStart = i;
}
if ("Bookng end".equalsIgnoreCase(lines1[i])) {
indexBookngEnd = i;
}
Array from \n and later for ","
public String getStoryFromCsv(String convert) {
String[] lines = convert.split("(\n)");
for (int j = 0; j < lines.length; j++) {
arrayPerRow = lines[j];
if (j == 0) { // get marketing type and number
firstRowValidation(arrayPerRow);
}
if (j == 1) { // get headers
secondRowValidation(arrayPerRow);
}
if (j > 1) { // get info and append according to headers
thirdRowsValidation(arrayPerRow);
}
}
So what I have is: - The method thirdRowsValidation() has an NPath complexity of 649 - The method 'thirdRowsValidation' has a Cyclomatic Complexity of 14.
At the end I'm reaching a text like this just for you guys have an idea:
Then it should have booking window 8/8/16 to 10/8/16
Then it should have travel window 11/6/16 to 12/25/16
And it should have online packages:
| id | type |
| 34534 | aaa Pkg |
| D434E | MKW Pkg + asdasdasdasdasdasdas |
| F382K | sds Pkg + Ddding |
| X582F | OYL Pkg + Deluxe Dining |