001package org.cpsolver.studentsct.reservation;
002
003import java.util.Collection;
004import java.util.HashSet;
005import java.util.Set;
006
007import org.cpsolver.studentsct.model.Course;
008import org.cpsolver.studentsct.model.Offering;
009import org.cpsolver.studentsct.model.Student;
010
011
012/**
013 * Individual reservation. A reservation for a particular student (or students).
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 IndividualReservation extends Reservation {
039    private Set<Long> iStudentIds = new HashSet<Long>();
040    
041    /**
042     * Individual reservations are of the top priority
043     */
044    public static final int DEFAULT_PRIORITY = 100;
045    /**
046     * Individual or group reservation must be used (unless it is expired)
047     */
048    public static final boolean DEFAULT_MUST_BE_USED = true;
049    /**
050     * Individual reservations are the only reservations that can be assigned over the limit.
051     */
052    public static final boolean DEFAULT_CAN_ASSIGN_OVER_LIMIT = true;
053    /**
054     * Overlaps are allowed for individual reservations. 
055     */
056    public static final boolean DEFAULT_ALLOW_OVERLAP = true;
057    
058    /**
059     * Constructor
060     * @param id reservation unique id
061     * @param offering instructional offering on which the reservation is set
062     * @param priority reservation priority
063     * @param mustBeUsed must this reservation be used
064     * @param canAssignOverLimit can assign over class / configuration / course limit
065     * @param allowOverlap does this reservation allow for overlaps
066     * @param studentIds one or more students
067     */
068    protected IndividualReservation(long id, Offering offering, int priority, boolean mustBeUsed, boolean canAssignOverLimit, boolean allowOverlap, Long... studentIds) {
069        super(id, offering, priority, mustBeUsed, canAssignOverLimit, allowOverlap);
070        for (Long studentId: studentIds) {
071            iStudentIds.add(studentId);
072        }
073    }
074
075    /**
076     * Constructor
077     * @param id unique id
078     * @param offering offering for which the reservation is
079     * @param studentIds one or more students
080     */
081    public IndividualReservation(long id, Offering offering, Long... studentIds) {
082        this(id, offering, DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds);
083    }
084    
085    /**
086     * Constructor
087     * @param id reservation unique id
088     * @param offering instructional offering on which the reservation is set
089     * @param priority reservation priority
090     * @param mustBeUsed must this reservation be used
091     * @param canAssignOverLimit can assign over class / configuration / course limit
092     * @param allowOverlap does this reservation allow for overlaps
093     * @param studentIds one or more students
094     */
095    protected IndividualReservation(long id, Offering offering, int priority, boolean mustBeUsed, boolean canAssignOverLimit, boolean allowOverlap, Collection<Long> studentIds) {
096        super(id, offering, priority, mustBeUsed, canAssignOverLimit, allowOverlap);
097        iStudentIds.addAll(studentIds);
098    }
099
100
101    /**
102     * Constructor
103     * @param id unique id
104     * @param offering offering for which the reservation is
105     * @param studentIds one or more students
106     */
107    public IndividualReservation(long id, Offering offering, Collection<Long> studentIds) {
108        this(id, offering, DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds);
109    }
110
111    /**
112     * Reservation is applicable for all students in the reservation
113     */
114    @Override
115    public boolean isApplicable(Student student, Course course) {
116        return iStudentIds.contains(student.getId());
117    }
118    
119    /**
120     * Students in the reservation
121     * @return set of student ids associated with this reservation
122     */
123    public Set<Long> getStudentIds() {
124        return iStudentIds;
125    }
126
127    /**
128     * Reservation limit == number of students in the reservation
129     */
130    @Override
131    public double getReservationLimit() {
132        return iStudentIds.size();
133    }
134    
135}