public Comparable createSorterWeight(Examination examination, Exam exam) { int studentSizeTotal = exam.getTopicStudentSize(); int maximumDuration = exam.getTopicDuration(); for (PeriodPenalty periodPenalty : examination.getPeriodPenaltyList()) { if (periodPenalty.getLeftTopic().equals(exam.getTopic())) { switch (periodPenalty.getPeriodPenaltyType()) { case EXAM_COINCIDENCE: studentSizeTotal += periodPenalty.getRightTopic().getStudentSize(); maximumDuration = Math.max(maximumDuration, periodPenalty.getRightTopic().getDuration()); break; case EXCLUSION: // Do nothing break; case AFTER: // Do nothing break; default: throw new IllegalStateException( "The periodPenaltyType (" + periodPenalty.getPeriodPenaltyType() + ") is not implemented."); } } else if (periodPenalty.getRightTopic().equals(exam.getTopic())) { switch (periodPenalty.getPeriodPenaltyType()) { case EXAM_COINCIDENCE: studentSizeTotal += periodPenalty.getLeftTopic().getStudentSize(); maximumDuration = Math.max(maximumDuration, periodPenalty.getLeftTopic().getDuration()); break; case EXCLUSION: // Do nothing break; case AFTER: studentSizeTotal += periodPenalty.getLeftTopic().getStudentSize(); maximumDuration = Math.max(maximumDuration, periodPenalty.getLeftTopic().getDuration()); break; default: throw new IllegalStateException( "The periodPenaltyType (" + periodPenalty.getPeriodPenaltyType() + ") is not implemented."); } } } return new ExamDifficultyWeight(exam, studentSizeTotal, maximumDuration); }