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