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;
}
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;
}
Aggregations