Search in sources :

Example 1 with Restriction

use of org.cpsolver.studentsct.reservation.Restriction in project cpsolver by UniTime.

the class CourseRequest method getRestrictions.

/**
 * Get restrictions for this course requests
 * @param course given course
 * @return restrictions for this course requests and the given course
 */
public synchronized List<Restriction> getRestrictions(Course course) {
    if (iRestrictions == null)
        iRestrictions = new HashMap<Course, List<Restriction>>();
    List<Restriction> restrictions = iRestrictions.get(course);
    if (restrictions == null) {
        restrictions = new ArrayList<Restriction>();
        for (Restriction r : course.getOffering().getRestrictions()) {
            if (r.isApplicable(getStudent()))
                restrictions.add(r);
        }
        iRestrictions.put(course, restrictions);
    }
    return restrictions;
}
Also used : Restriction(org.cpsolver.studentsct.reservation.Restriction) HashMap(java.util.HashMap)

Example 2 with Restriction

use of org.cpsolver.studentsct.reservation.Restriction in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadRestriction.

/**
 * Load restriction
 * @param restrictionEl restriction element
 * @param offering parent offering
 * @param configTable config table (of the offering)
 * @param sectionTable section table (of the offering)
 * @return loaded restriction
 */
protected Restriction loadRestriction(Element restrictionEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
    Restriction r = null;
    if ("individual".equals(restrictionEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = restrictionEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new IndividualRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, studentIds);
    } else if ("curriculum".equals(restrictionEl.attributeValue("type"))) {
        List<String> acadAreas = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("area"); k.hasNext(); ) {
            Element areaEl = (Element) k.next();
            acadAreas.add(areaEl.attributeValue("code"));
        }
        if (acadAreas.isEmpty() && restrictionEl.attributeValue("area") != null)
            acadAreas.add(restrictionEl.attributeValue("area"));
        List<String> classifications = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("classification"); k.hasNext(); ) {
            Element clasfEl = (Element) k.next();
            classifications.add(clasfEl.attributeValue("code"));
        }
        List<String> majors = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            majors.add(majorEl.attributeValue("code"));
        }
        List<String> minors = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("minor"); k.hasNext(); ) {
            Element minorEl = (Element) k.next();
            minors.add(minorEl.attributeValue("code"));
        }
        r = new CurriculumRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, acadAreas, classifications, majors, minors);
        for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            for (Iterator<?> l = majorEl.elementIterator("concentration"); l.hasNext(); ) {
                Element concentrationEl = (Element) l.next();
                ((CurriculumRestriction) r).addConcentration(majorEl.attributeValue("code"), concentrationEl.attributeValue("code"));
            }
        }
    } else if ("course".equals(restrictionEl.attributeValue("type"))) {
        long courseId = Long.parseLong(restrictionEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new CourseRestriction(Long.valueOf(restrictionEl.attributeValue("id")), course);
        }
    }
    if (r == null) {
        sLogger.error("Unknown reservation type " + restrictionEl.attributeValue("type"));
        return null;
    }
    for (Iterator<?> k = restrictionEl.elementIterator("config"); k.hasNext(); ) {
        Element configEl = (Element) k.next();
        r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
    }
    for (Iterator<?> k = restrictionEl.elementIterator("section"); k.hasNext(); ) {
        Element sectionEl = (Element) k.next();
        r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))));
    }
    return r;
}
Also used : IndividualRestriction(org.cpsolver.studentsct.reservation.IndividualRestriction) Element(org.dom4j.Element) CurriculumRestriction(org.cpsolver.studentsct.reservation.CurriculumRestriction) Restriction(org.cpsolver.studentsct.reservation.Restriction) IndividualRestriction(org.cpsolver.studentsct.reservation.IndividualRestriction) CourseRestriction(org.cpsolver.studentsct.reservation.CourseRestriction) CurriculumRestriction(org.cpsolver.studentsct.reservation.CurriculumRestriction) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Course(org.cpsolver.studentsct.model.Course) CourseRestriction(org.cpsolver.studentsct.reservation.CourseRestriction) HashSet(java.util.HashSet)

Aggregations

Restriction (org.cpsolver.studentsct.reservation.Restriction)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Course (org.cpsolver.studentsct.model.Course)1 CourseRestriction (org.cpsolver.studentsct.reservation.CourseRestriction)1 CurriculumRestriction (org.cpsolver.studentsct.reservation.CurriculumRestriction)1 IndividualRestriction (org.cpsolver.studentsct.reservation.IndividualRestriction)1 Element (org.dom4j.Element)1