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 * Individual restriction. A restriction for a particular student (or students). 012 * 013 * <br> 014 * <br> 015 * 016 * @version StudentSct 1.3 (Student Sectioning)<br> 017 * Copyright (C) 2007 - 2020 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 IndividualRestriction extends Restriction { 036 private Set<Long> iStudentIds = new HashSet<Long>(); 037 038 /** 039 * Constructor 040 * @param id restriction unique id 041 * @param offering instructional offering on which the restriction is set 042 * @param studentIds one or more students 043 */ 044 public IndividualRestriction(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 restriction unique id 054 * @param offering instructional offering on which the restriction is set 055 * @param studentIds one or more students 056 */ 057 public IndividualRestriction(long id, Offering offering, Collection<Long> studentIds) { 058 super(id, offering); 059 iStudentIds.addAll(studentIds); 060 } 061 062 /** 063 * Restriction is applicable for all students in the restriction 064 */ 065 @Override 066 public boolean isApplicable(Student student) { 067 return iStudentIds.contains(student.getId()); 068 } 069 070 /** 071 * Students in the restriction 072 * @return set of student ids associated with this restriction 073 */ 074 public Set<Long> getStudentIds() { 075 return iStudentIds; 076 } 077}