001package org.cpsolver.studentsct.reservation;
002
003import org.cpsolver.studentsct.model.Course;
004import org.cpsolver.studentsct.model.CourseRequest;
005import org.cpsolver.studentsct.model.Request;
006import org.cpsolver.studentsct.model.Student;
007
008/**
009 * Group restriction. Students are matched based on their course requests.  
010 * <br>
011 * <br>
012 * 
013 * @version StudentSct 1.3 (Student Sectioning)<br>
014 *          Copyright (C) 2007 - 2020 Tomáš Müller<br>
015 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
016 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
017 * <br>
018 *          This library is free software; you can redistribute it and/or modify
019 *          it under the terms of the GNU Lesser General Public License as
020 *          published by the Free Software Foundation; either version 3 of the
021 *          License, or (at your option) any later version. <br>
022 * <br>
023 *          This library is distributed in the hope that it will be useful, but
024 *          WITHOUT ANY WARRANTY; without even the implied warranty of
025 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
026 *          Lesser General Public License for more details. <br>
027 * <br>
028 *          You should have received a copy of the GNU Lesser General Public
029 *          License along with this library; if not see
030 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
031 */
032public class CourseRestriction extends Restriction {
033    private Course iCourse;
034    
035    /**
036     * Constructor
037     * @param id restriction unique id
038     * @param course course offering on which the restriction is set
039     */
040    public CourseRestriction(long id, Course course) {
041        super(id, course.getOffering());
042        iCourse = course;
043    }
044
045    /**
046     * Course offering
047     * @return course offering
048     */
049    public Course getCourse() {
050        return iCourse;
051    }
052    
053    /**
054     * Check the area, classifications and majors
055     */
056    @Override
057    public boolean isApplicable(Student student) {
058        for (Request r: student.getRequests()) {
059            if (r instanceof CourseRequest) {
060                for (Course course: ((CourseRequest) r).getCourses()) {
061                    if (course.equals(getCourse())) return true;
062                }
063            }
064        }
065        return false;
066    }
067}