Let's say I want to check the particular condition while iterating the list, I am using many if conditions which will violating the coding standards. I have the following code with many if conditions, How can I reduce the number coding lines and improve the quality of the code with out change of my output.
Please suggest me some good standards while using if conditions.
while (iterator.hasNext()) {
Row nextRow = iterator.next();
for (int colIndex = 0; colIndex < 7; colIndex++) {
if (colIndex == 0) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
firstName = cell.getStringCellValue();
System.out.println("First Name : "+firstName);
}
}
if (colIndex == 1) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
middleName = cell.getStringCellValue();
System.out.println("Middle Name : "+middleName);
}
}
if (colIndex == 2) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
lastName = cell.getStringCellValue();
System.out.println("Last Name : "+lastName);
}
}
if (colIndex == 3) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
email = cell.getStringCellValue();
System.out.println("Email : "+email);
}
}
if (colIndex == 4) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
password = cell.getStringCellValue();
System.out.println("Password : "+password);
}
}
if (colIndex == 5) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
role = cell.getStringCellValue();
System.out.println("Role : "+role);
}
}
if (colIndex == 6) {
Cell cell = nextRow.getCell(colIndex);
if (cell != null) {
status = cell.getStringCellValue();
System.out.println("Status : "+status);
}
}
}
System.out.println();
}
Aucun commentaire:
Enregistrer un commentaire