vendredi 28 mai 2021

To refactor multiple If statements in java

How can I avoid multiple if statements for the below code?

for (Student students : studentList) {

    if ((Constants.CODE1.equals(students.getactivities().getCode())
            && ValidationRepository.validateStudentId1(department.getId()))
            || ((Constants.CODE2).equals(students.getactivities().getCode())
                    && ValidationRepository.validateStudentId2(department.getId())
                    && ValidationRepository.validateStudentId3(department.getId()))
            || ((Constants.CODE3
                    .equals(students.getactivities().getCode())
                    || Constants.CODE4
                            .equals(students.getactivities().getCode()))
                    && (ValidationRepository.validateStudentId4(
                            department.getId(),
                            students.getactivities().getCode())))
            || ((Constants.CODE5.equals(students.getactivities().getCode())
                    || Constants.CODE6
                            .equals(students.getactivities().getCode())

                    || Constants.CODE7
                            .equals(students.getactivities().getCode())
                    || Constants.CODE15
                            .equals(students.getactivities().getCode())

                    || Constants.CODE8
                            .equals(students.getactivities().getCode())
                    || Constants.CODE9
                            .equals(students.getactivities().getCode())

                    || Constants.CODE10
                            .equals(students.getactivities().getCode())
                    || Constants.CODE11
                            .equals(students.getactivities().getCode()))

                    && (ValidationRepository.validateStudentId4(
                            department.getId(),
                            students.getactivities().getCode())))

    )
    { 
        some statements
    }

Aucun commentaire:

Enregistrer un commentaire