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 * Individual restriction. A restriction 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 - 2020 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 IndividualRestriction extends Restriction {
038    private Set<Long> iStudentIds = new HashSet<Long>();
039    
040    /**
041     * Constructor
042     * @param id restriction unique id
043     * @param offering instructional offering on which the restriction is set
044     * @param studentIds one or more students
045     */
046    public IndividualRestriction(long id, Offering offering, Long... studentIds) {
047        super(id, offering);
048        for (Long studentId: studentIds) {
049            iStudentIds.add(studentId);
050        }
051    }
052
053    /**
054     * Constructor
055     * @param id restriction unique id
056     * @param offering instructional offering on which the restriction is set
057     * @param studentIds one or more students
058     */
059    public IndividualRestriction(long id, Offering offering, Collection<Long> studentIds) {
060        super(id, offering);
061        iStudentIds.addAll(studentIds);
062    }
063
064    /**
065     * Restriction is applicable for all students in the restriction
066     */
067    @Override
068    public boolean isApplicable(Student student, Course course) {
069        return iStudentIds.contains(student.getId());
070    }
071    
072    /**
073     * Students in the restriction
074     * @return set of student ids associated with this restriction
075     */
076    public Set<Long> getStudentIds() {
077        return iStudentIds;
078    }
079}