mardi 20 juin 2017

Java: How to reduce the number of if-else statements where not possilbe to merge them

Although my code is working perfectly as I want, but there are many if-else statements in my code so I want to ask is it possible to reduce if-else statements in this code

if ( posteNuit(timePicker1.getValue().toString(), timePicker4.getValue().toString()) ) {
    if ( !teToTime.isAfter(LocalTime.parse("08:30",format)) ) {
        textField4.setStyle("");
        if(getDifference(timeKA, timeKB)<121 && getDifference(timeKA, timeKB)>59) {
        timePicker3.setStyle("");
            if ( coupureRange(timePicker1.getValue().toString(), timePicker2.getValue().toString(),
                timePicker3.getValue().toString(), timePicker4.getValue().toString())) {
                timePicker2.setStyle("");
                timePicker3.setStyle("");
                if( increaseTxt.isBefore(LocalTime.parse("11:01",format)) )
                {
                    textField5.setStyle("");
                    return true;
                } else {
                    textField5.setStyle("-fx-border-color: red");
                    return false;
                }

            } else {
                timePicker2.setStyle("-fx-border-color: orange");
                return false;
                }                               
        }
        else {
            timePicker3.setStyle("-fx-border-color: red");
            return false;
            }
    } else {
        textField4.setStyle("-fx-border-color: red");
        return false;
        }

}
return false;

Aucun commentaire:

Enregistrer un commentaire