001package org.cpsolver.studentsct.reservation; 002 003import java.util.Collection; 004 005import org.cpsolver.studentsct.model.Course; 006import org.cpsolver.studentsct.model.CourseRequest; 007import org.cpsolver.studentsct.model.Request; 008import org.cpsolver.studentsct.model.Student; 009 010/** 011 * Learning Community reservation. This is a combination of {@link GroupReservation} 012 * and {@link CourseReservation}. Space is reserved for students of a group but only when 013 * they enroll into the offering through the given course. 014 * 015 * <br> 016 * <br> 017 * 018 * @author Tomáš Müller 019 * @version StudentSct 1.3 (Student Sectioning)<br> 020 * Copyright (C) 2007 - 2014 Tomáš Müller<br> 021 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 022 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 023 * <br> 024 * This library is free software; you can redistribute it and/or modify 025 * it under the terms of the GNU Lesser General Public License as 026 * published by the Free Software Foundation; either version 3 of the 027 * License, or (at your option) any later version. <br> 028 * <br> 029 * This library is distributed in the hope that it will be useful, but 030 * WITHOUT ANY WARRANTY; without even the implied warranty of 031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 032 * Lesser General Public License for more details. <br> 033 * <br> 034 * You should have received a copy of the GNU Lesser General Public 035 * License along with this library; if not see 036 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 037 */ 038public class LearningCommunityReservation extends GroupReservation { 039 private Course iCourse; 040 041 /** 042 * Learning Community reservations are just a below student group reservations. 043 */ 044 public static final int DEFAULT_PRIORITY = 250; 045 /** 046 * Learning Community reservation must be used (unless it is expired) 047 */ 048 public static final boolean DEFAULT_MUST_BE_USED = true; 049 /** 050 * Learning Community reservations cannot be assigned over the limit. 051 */ 052 public static final boolean DEFAULT_CAN_ASSIGN_OVER_LIMIT = false; 053 /** 054 * Overlaps are not allowed for Learning Community reservations. 055 */ 056 public static final boolean DEFAULT_ALLOW_OVERLAP = false; 057 058 /** 059 * Constructor 060 * @param id unique id 061 * @param limit reservation limit (-1 for unlimited) 062 * @param course course offering for which the reservation is 063 * @param studentIds one or more students 064 */ 065 public LearningCommunityReservation(long id, double limit, Course course, Long... studentIds) { 066 super(id, limit, course.getOffering(), DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds); 067 iCourse = course; 068 } 069 070 /** 071 * Constructor 072 * @param id unique id 073 * @param limit reservation limit (-1 for unlimited) 074 * @param course course offering for which the reservation is 075 * @param studentIds one or more students 076 */ 077 public LearningCommunityReservation(long id, double limit, Course course, Collection<Long> studentIds) { 078 super(id, limit, course.getOffering(), DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds); 079 iCourse = course; 080 } 081 082 /** 083 * Reservation limit (-1 for unlimited) 084 */ 085 @Override 086 public double getReservationLimit() { 087 if (super.getReservationLimit() < 0.0) 088 return iCourse.getLimit(); // no group limit >> return course limit 089 else if (iCourse.getLimit() < 0.0) 090 return super.getReservationLimit(); // course unlimited >> return group limit 091 else 092 return Math.min(super.getReservationLimit(), iCourse.getLimit()); // return smaller of the two limits 093 } 094 095 /** 096 * Course offering 097 * @return course offering 098 */ 099 public Course getCourse() { 100 return iCourse; 101 } 102 103 /** 104 * Check the student group and the course 105 */ 106 @Override 107 public boolean isApplicable(Student student) { 108 if (!super.isApplicable(student)) return false; 109 for (Request r: student.getRequests()) { 110 if (r instanceof CourseRequest) { 111 for (Course course: ((CourseRequest) r).getCourses()) { 112 if (course.equals(getCourse())) return true; 113 } 114 } 115 } 116 return false; 117 } 118}