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