001    package net.sf.cpsolver.studentsct.constraint;
002    
003    import net.sf.cpsolver.studentsct.model.Course;
004    import net.sf.cpsolver.studentsct.model.Enrollment;
005    
006    /**
007     * Abstract course reservation. 
008     * 
009     * <br><br>
010     * 
011     * @version
012     * StudentSct 1.1 (Student Sectioning)<br>
013     * Copyright (C) 2007 Tomáš Müller<br>
014     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
015     * Lazenska 391, 76314 Zlin, Czech Republic<br>
016     * <br>
017     * This library is free software; you can redistribute it and/or
018     * modify it under the terms of the GNU Lesser General Public
019     * License as published by the Free Software Foundation; either
020     * version 2.1 of the License, or (at your option) any later version.
021     * <br><br>
022     * This library is distributed in the hope that it will be useful,
023     * but WITHOUT ANY WARRANTY; without even the implied warranty of
024     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
025     * Lesser General Public License for more details.
026     * <br><br>
027     * You should have received a copy of the GNU Lesser General Public
028     * License along with this library; if not, write to the Free Software
029     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
030     */
031    public abstract class ReservationOnCourse extends Reservation {
032        private Course iCourse = null;
033        
034        /** 
035         * Constructor
036         * @param course course on which the reservation is set
037         */
038        public ReservationOnCourse(Course course) {
039            super();
040            iCourse = course;
041        }
042        
043        /** Return course, on which the reservation is set */
044        public Course getCourse() {
045            return iCourse;
046        }
047        
048        /** 
049         * True, if the enrollment contains the course on which this reservation is set.
050         * See {@link Reservation#isApplicable(Enrollment)} for details.
051         */
052        public boolean isApplicable(Enrollment enrollment) {
053            if (enrollment.getConfig()==null) return false;
054            
055            // Course check -- is it needed?
056            Course courseThisEnrollment = enrollment.getConfig().getOffering().getCourse(enrollment.getStudent());
057            if (courseThisEnrollment==null || !courseThisEnrollment.equals(iCourse)) return false;
058            
059            return true;
060        }
061        
062        public String toString() {
063            return "Reservation on "+iCourse.getName();
064        }
065    }