001package org.cpsolver.studentsct.reservation;
002
003import java.util.Collection;
004import java.util.HashSet;
005import java.util.Set;
006
007import org.cpsolver.studentsct.model.Offering;
008import org.cpsolver.studentsct.model.Student;
009
010
011/**
012 * Individual reservation. A reservation for a particular student (or students).
013 * 
014 * <br>
015 * <br>
016 * 
017 * @version StudentSct 1.3 (Student Sectioning)<br>
018 *          Copyright (C) 2007 - 2014 Tomáš Müller<br>
019 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
020 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
021 * <br>
022 *          This library is free software; you can redistribute it and/or modify
023 *          it under the terms of the GNU Lesser General Public License as
024 *          published by the Free Software Foundation; either version 3 of the
025 *          License, or (at your option) any later version. <br>
026 * <br>
027 *          This library is distributed in the hope that it will be useful, but
028 *          WITHOUT ANY WARRANTY; without even the implied warranty of
029 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
030 *          Lesser General Public License for more details. <br>
031 * <br>
032 *          You should have received a copy of the GNU Lesser General Public
033 *          License along with this library; if not see
034 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
035 */
036public class IndividualReservation extends Reservation {
037    private Set<Long> iStudentIds = new HashSet<Long>();
038    
039    /**
040     * Individual reservations are of the top priority
041     */
042    public static final int DEFAULT_PRIORITY = 100;
043    /**
044     * Individual or group reservation must be used (unless it is expired)
045     */
046    public static final boolean DEFAULT_MUST_BE_USED = true;
047    /**
048     * Individual reservations are the only reservations that can be assigned over the limit.
049     */
050    public static final boolean DEFAULT_CAN_ASSIGN_OVER_LIMIT = true;
051    /**
052     * Overlaps are allowed for individual reservations. 
053     */
054    public static final boolean DEFAULT_ALLOW_OVERLAP = true;
055    
056    /**
057     * Constructor
058     * @param id reservation unique id
059     * @param offering instructional offering on which the reservation is set
060     * @param priority reservation priority
061     * @param mustBeUsed must this reservation be used
062     * @param canAssignOverLimit can assign over class / configuration / course limit
063     * @param allowOverlap does this reservation allow for overlaps
064     * @param studentIds one or more students
065     */
066    protected IndividualReservation(long id, Offering offering, int priority, boolean mustBeUsed, boolean canAssignOverLimit, boolean allowOverlap, Long... studentIds) {
067        super(id, offering, priority, mustBeUsed, canAssignOverLimit, allowOverlap);
068        for (Long studentId: studentIds) {
069            iStudentIds.add(studentId);
070        }
071    }
072
073    /**
074     * Constructor
075     * @param id unique id
076     * @param offering offering for which the reservation is
077     * @param studentIds one or more students
078     */
079    public IndividualReservation(long id, Offering offering, Long... studentIds) {
080        this(id, offering, DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds);
081    }
082    
083    /**
084     * Constructor
085     * @param id reservation unique id
086     * @param offering instructional offering on which the reservation is set
087     * @param priority reservation priority
088     * @param mustBeUsed must this reservation be used
089     * @param canAssignOverLimit can assign over class / configuration / course limit
090     * @param allowOverlap does this reservation allow for overlaps
091     * @param studentIds one or more students
092     */
093    protected IndividualReservation(long id, Offering offering, int priority, boolean mustBeUsed, boolean canAssignOverLimit, boolean allowOverlap, Collection<Long> studentIds) {
094        super(id, offering, priority, mustBeUsed, canAssignOverLimit, allowOverlap);
095        iStudentIds.addAll(studentIds);
096    }
097
098
099    /**
100     * Constructor
101     * @param id unique id
102     * @param offering offering for which the reservation is
103     * @param studentIds one or more students
104     */
105    public IndividualReservation(long id, Offering offering, Collection<Long> studentIds) {
106        this(id, offering, DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP, studentIds);
107    }
108
109    /**
110     * Reservation is applicable for all students in the reservation
111     */
112    @Override
113    public boolean isApplicable(Student student) {
114        return iStudentIds.contains(student.getId());
115    }
116    
117    /**
118     * Students in the reservation
119     * @return set of student ids associated with this reservation
120     */
121    public Set<Long> getStudentIds() {
122        return iStudentIds;
123    }
124
125    /**
126     * Reservation limit == number of students in the reservation
127     */
128    @Override
129    public double getReservationLimit() {
130        return iStudentIds.size();
131    }
132    
133}