public boolean uploadResult(Lecturer lecturer, Student student, String result) throws NullPointerException {
Schedule currentSchedule = scheduleService.findCurrentSchedule();
if (currentSchedule.getWeek() != 12) {
throw new IllegalArgumentException("Cannot upload result until the end of the semester.");
}
Student stu = studentService.findOne(student);
List<Enrolment> enrolments = stu.getPerformance();
Enrolment enrolment = null;
for (Enrolment e : enrolments) {
CourseOffering offering = e.getOffering();
if (offering.getLecturer().equals(lecturer) && offering.getSchedule().equals(currentSchedule)) {
enrolment = e;
break;
}
}
if (enrolment == null) {
throw new NullPointerException("There is no such student in the lecturer's course");
}
enrolment.setResult(result);
studentService.save(student);
return true;
}
我试图理解上面的代码,以便在序列图中说明它,但我在理解其中一些方面遇到了一些麻烦,特别是这部分:
List<Enrolment> enrolments = stu.getPerformance();
Enrolment enrolment = null;
for (Enrolment e : enrolments) {
CourseOffering offering = e.getOffering();
if (offering.getLecturer().equals(lecturer) &&
offering.getSchedule().equals(currentSchedule)) {
enrolment = e;
break;