...
Method Factoring
Kicking The Can
Here’s an example of an attempt to replace a GradeSystem for a Course using the kick-the-can method:
Code Block |
---|
public class CourseLookupSession
implements org.osid.course.CourseLookupSession {
private org.osid.course.CourseLookupSession courseLookupSession;
@OSID
public org.osid.course.CourseList getCourses()
throws org.osid.OperationFailedException,
org.osid.PermissionDeniedException {
return (processCourses(this.courseLookupSession.getCourses()));
}
private org.osid.course.CourseList processCourses(org.osid.course.CourseList courses)
throws org.osid.OperationFailedException,
org.osid.PermissionDeniedException {
MutableCourseList ret = new MutableCourseList();
while (courses.hasNext()) {
ret.add(processCourse(courses.getNextCourse()));
}
ret.done();
return (ret);
}
private org.osid.course.Course processCourse(org.osid.course.Course course)
throws org.osid.OperationFailedException,
org.osid.PermissionDeniedException {
if (course.isGraded()) {
return (processGradingOptions(course));
} else {
return (course);
}
}
private org.osid.course.Course processGradingOptions(org.osid.course.Courss course)
throws org.osid.OperationFailedException,
org.osid.PermissionDeniedException {
Collection<org.osid.grading.GradeSystem> mappedGradeSystems = new ArrayList<>();
try (org.osid.grading.GradeSystemList gradeSystems = course.getGradingOptions()) {
while (ids.hasNext()) {
org.osid.grading.GradeSystem gradeSystem = gradeSystems.getNextGradeSystem();
try {
mappedGradeSystems.add(getNewGradingOption(gradeSystem.getId()));
} catch (org.osid.NotFoundException nfe) {
mappedGradeSystems.add(gradeSystem);
}
}
}
return (mapCourseToNewGradeSystems(course, mappedGradeSystems);
}
private org.osid.grading.GradeSystem getNewGradingOption(org.osid.id.Id gradeSystemid)
throws org.osid.NotFoundException,
org.osid.OperationFailedException,
org.osid.PermissionDeniedException {
try (
} |
See Also
...