private void createExamList(Examination examination) {
List<Topic> topicList = examination.getTopicList();
List<Exam> examList = new ArrayList<Exam>(topicList.size());
Map<Topic, Exam> topicToExamMap = new HashMap<Topic, Exam>(topicList.size());
for (Topic topic : topicList) {
Exam exam = new Exam();
exam.setId(topic.getId());
exam.setTopic(topic);
// Notice that we leave the PlanningVariable properties on null
examList.add(exam);
topicToExamMap.put(topic, exam);
}
for (PeriodPenalty periodPenalty : examination.getPeriodPenaltyList()) {
if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.EXAM_COINCIDENCE) {
Exam leftExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
Exam rightExam = topicToExamMap.get(periodPenalty.getRightSideTopic());
Set<Exam> newCoincidenceExamSet = new LinkedHashSet<Exam>(4);
ExamCoincidence leftExamCoincidence = leftExam.getExamCoincidence();
if (leftExamCoincidence != null) {
newCoincidenceExamSet.addAll(leftExamCoincidence.getCoincidenceExamSet());
} else {
newCoincidenceExamSet.add(leftExam);
}
ExamCoincidence rightExamCoincidence = rightExam.getExamCoincidence();
if (rightExamCoincidence != null) {
newCoincidenceExamSet.addAll(rightExamCoincidence.getCoincidenceExamSet());
} else {
newCoincidenceExamSet.add(rightExam);
}
ExamCoincidence newExamCoincidence = new ExamCoincidence(newCoincidenceExamSet);
for (Exam exam : newCoincidenceExamSet) {
exam.setExamCoincidence(newExamCoincidence);
}
} else if (periodPenalty.getPeriodPenaltyType() == PeriodPenaltyType.AFTER) {
Exam afterExam = topicToExamMap.get(periodPenalty.getLeftSideTopic());
Exam beforeExam = topicToExamMap.get(periodPenalty.getRightSideTopic());
ExamBefore examBefore = beforeExam.getExamBefore();
if (examBefore == null) {
examBefore = new ExamBefore(new LinkedHashSet<Exam>(2));
beforeExam.setExamBefore(examBefore);
}
examBefore.getAfterExamSet().add(afterExam);
}
}
examination.setExamList(examList);