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 Tomas Muller<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     * Constructor
041     * @param id unique id
042     * @param offering offering for which the reservation is
043     * @param studentIds one or more students
044     */
045    public IndividualReservation(long id, Offering offering, Long... studentIds) {
046        super(id, offering);
047        for (Long studentId: studentIds) {
048            iStudentIds.add(studentId);
049        }
050    }
051
052    /**
053     * Constructor
054     * @param id unique id
055     * @param offering offering for which the reservation is
056     * @param studentIds one or more students
057     */
058    public IndividualReservation(long id, Offering offering, Collection<Long> studentIds) {
059        super(id, offering);
060        iStudentIds.addAll(studentIds);
061    }
062
063    /**
064     * Individual reservations are the only reservations that can be assigned over the limit.
065     */
066    @Override
067    public boolean canAssignOverLimit() {
068        return true;
069    }
070    
071    /**
072     * Individual or group reservation must be used (unless it is expired)
073     * @return true if not expired, false if expired
074     */
075    @Override
076    public boolean mustBeUsed() {
077        return !isExpired();
078    }
079
080    /**
081     * Individual reservations are of the top priority
082     */
083    @Override
084    public int getPriority() {
085        return 100;
086    }
087
088    /**
089     * Reservation is applicable for all students in the reservation
090     */
091    @Override
092    public boolean isApplicable(Student student) {
093        return iStudentIds.contains(student.getId());
094    }
095    
096    /**
097     * Students in the reservation
098     * @return set of student ids associated with this reservation
099     */
100    public Set<Long> getStudentIds() {
101        return iStudentIds;
102    }
103
104    /**
105     * Reservation limit == number of students in the reservation
106     */
107    @Override
108    public double getReservationLimit() {
109        return iStudentIds.size();
110    }
111    
112    /**
113     * Overlaps are allowed for individual reservations. 
114     */
115    @Override
116    public boolean isAllowOverlap() {
117        return true;
118    }
119
120
121}