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.AreaClassificationMajor;
009import org.cpsolver.studentsct.model.Offering;
010import org.cpsolver.studentsct.model.Student;
011
012/**
013 * Group restriction. Students are matched based on their academic area.
014 * If classifications and/or majors are included, student must match on them as well.  
015 * <br>
016 * <br>
017 * 
018 * @version StudentSct 1.3 (Student Sectioning)<br>
019 *          Copyright (C) 2007 - 2020 Tomas Muller<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 CurriculumRestriction extends Restriction {
038    private String iAcadArea;
039    private Set<String> iClassifications = new HashSet<String>();
040    private Set<String> iMajors = new HashSet<String>();
041    
042    /**
043     * Constructor
044     * @param id restriction unique id
045     * @param offering instructional offering on which the restriction is set
046     * @param acadArea academic area
047     * @param classifications zero or more classifications (classifications must match if not empty)
048     * @param majors zero or more majors (majors must match if not empty)
049     */
050    public CurriculumRestriction(long id, Offering offering, String acadArea, Collection<String> classifications, Collection<String> majors) {
051        super(id, offering);
052        iAcadArea = acadArea;
053        if (classifications != null)
054            iClassifications.addAll(classifications);
055        if (majors != null)
056            iMajors.addAll(majors);
057    }
058
059    /**
060     * Academic area
061     * @return selected academic area
062     */
063    public String getAcademicArea() {
064        return iAcadArea;
065    }
066    
067    /**
068     * Majors
069     * @return selected majors
070     */
071    public Set<String> getMajors() {
072        return iMajors;
073    }
074    
075    /**
076     * Academic classifications
077     * @return selected academic classifications
078     */
079    public Set<String> getClassifications() {
080        return iClassifications;
081    }
082
083    /**
084     * Check the area, classifications and majors
085     */
086    @Override
087    public boolean isApplicable(Student student) {
088        boolean match = false;
089        for (AreaClassificationMajor acm: student.getAreaClassificationMajors())
090            if (getAcademicArea().equals(acm.getArea()) &&
091                (getClassifications().isEmpty() || getClassifications().contains(acm.getClassification())) &&
092                (getMajors().isEmpty() || getMajors().contains(acm.getMajor())))
093                    return true;
094        if (student.getAcademicAreaClasiffications() == null) return false;
095        for (AcademicAreaCode aac: student.getAcademicAreaClasiffications()) {
096            if (getAcademicArea().equals(aac.getArea())) {
097                if (getClassifications().isEmpty() || getClassifications().contains(aac.getCode())) {
098                    match = true; break;
099                }
100            }
101        }
102        if (!match) return false;
103        for (AcademicAreaCode aac: student.getMajors()) {
104            if (getAcademicArea().equals(aac.getArea())) {
105                if (getMajors().isEmpty() || getMajors().contains(aac.getCode()))
106                    return true;
107            }
108        }
109        return getMajors().isEmpty();
110    }
111}