001package org.cpsolver.studentsct.reservation;
002
003import java.util.Collection;
004import java.util.HashSet;
005import java.util.Set;
006
007import org.cpsolver.studentsct.model.AcademicAreaCode;
008import org.cpsolver.studentsct.model.Offering;
009import org.cpsolver.studentsct.model.Student;
010
011
012/**
013 * Curriculum reservation. Students are matched based on their academic area.
014 * If classifications and/or majors are included, student must match on them as well.  
015 * 
016 * <br>
017 * <br>
018 * 
019 * @version StudentSct 1.3 (Student Sectioning)<br>
020 *          Copyright (C) 2007 - 2014 Tomas Muller<br>
021 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
022 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
023 * <br>
024 *          This library is free software; you can redistribute it and/or modify
025 *          it under the terms of the GNU Lesser General Public License as
026 *          published by the Free Software Foundation; either version 3 of the
027 *          License, or (at your option) any later version. <br>
028 * <br>
029 *          This library is distributed in the hope that it will be useful, but
030 *          WITHOUT ANY WARRANTY; without even the implied warranty of
031 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
032 *          Lesser General Public License for more details. <br>
033 * <br>
034 *          You should have received a copy of the GNU Lesser General Public
035 *          License along with this library; if not see
036 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
037 */
038public class CurriculumReservation extends Reservation {
039    private double iLimit;
040    private String iAcadArea;
041    private Set<String> iClassifications = new HashSet<String>();
042    private Set<String> iMajors = new HashSet<String>();
043    
044    /**
045     * Reservation priority (lower than individual and group reservations)
046     */
047    public static final int DEFAULT_PRIORITY = 500;
048    /**
049     * Curriculum reservation does not need to be used
050     */
051    public static final boolean DEFAULT_MUST_BE_USED = false;
052    /**
053     * Curriculum reservations can not assign over the limit.
054     */
055    public static final boolean DEFAULT_CAN_ASSIGN_OVER_LIMIT = false;
056    /**
057     * Overlaps are not allowed for curriculum reservations. 
058     */
059    public static final boolean DEFAULT_ALLOW_OVERLAP = false;
060    
061    /**
062     * Constructor
063     * @param id unique id
064     * @param limit reservation limit (-1 for unlimited)
065     * @param offering instructional offering on which the reservation is set
066     * @param acadArea academic area
067     * @param classifications zero or more classifications (classifications must match if not empty)
068     * @param majors zero or more majors (majors must match if not empty)
069     */
070    public CurriculumReservation(long id, double limit, Offering offering, String acadArea, Collection<String> classifications, Collection<String> majors) {
071        super(id, offering, DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP);
072        iLimit = limit;
073        iAcadArea = acadArea;
074        if (classifications != null)
075            iClassifications.addAll(classifications);
076        if (majors != null)
077            iMajors.addAll(majors);
078    }
079
080    /**
081     * Reservation limit (-1 for unlimited)
082     */
083    @Override
084    public double getReservationLimit() {
085        return iLimit;
086    }
087
088    /**
089     * Set reservation limit (-1 for unlimited)
090     * @param limit reservation limit, -1 for unlimited
091     */
092    public void setReservationLimit(double limit) {
093        iLimit = limit;
094    }
095
096    
097    /**
098     * Academic area
099     * @return selected academic area
100     */
101    public String getAcademicArea() {
102        return iAcadArea;
103    }
104    
105    /**
106     * Majors
107     * @return selected majors
108     */
109    public Set<String> getMajors() {
110        return iMajors;
111    }
112    
113    /**
114     * Academic classifications
115     * @return selected academic classifications
116     */
117    public Set<String> getClassifications() {
118        return iClassifications;
119    }
120
121    /**
122     * Check the area, classifications and majors
123     */
124    @Override
125    public boolean isApplicable(Student student) {
126        boolean match = false;
127        if (student.getAcademicAreaClasiffications() == null) return false;
128        for (AcademicAreaCode aac: student.getAcademicAreaClasiffications()) {
129            if (getAcademicArea().equals(aac.getArea())) {
130                if (getClassifications().isEmpty() || getClassifications().contains(aac.getCode())) {
131                    match = true; break;
132                }
133            }
134        }
135        if (!match) return false;
136        for (AcademicAreaCode aac: student.getMajors()) {
137            if (getAcademicArea().equals(aac.getArea())) {
138                if (getMajors().isEmpty() || getMajors().contains(aac.getCode()))
139                    return true;
140            }
141        }
142        return getMajors().isEmpty();
143    }
144    
145
146}