    001package org.cpsolver.studentsct.report;
    002
    003import org.cpsolver.studentsct.model.Course;
    004import org.cpsolver.studentsct.model.Section;
    005
    006/**
    007 * A simple class containing reference to a (course, class) pair. Used in some of the reports.
    008 * Provides sorting capabilities.
    009 *
    010 * <br>
    011 * <br>
    012 *
    013 * @version StudentSct 1.3 (Student Sectioning)<br>
    014 *          Copyright (C) 2013 - 2014 Tomáš Müller<br>
    015 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    016 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    017 * <br>
    018 *          This library is free software; you can redistribute it and/or modify
    019 *          it under the terms of the GNU Lesser General Public License as
    020 *          published by the Free Software Foundation; either version 3 of the
    021 *          License, or (at your option) any later version. <br>
    022 * <br>
    023 *          This library is distributed in the hope that it will be useful, but
    024 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    025 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    026 *          Lesser General Public License for more details. <br>
    027 * <br>
    028 *          You should have received a copy of the GNU Lesser General Public
    029 *          License along with this library; if not see
    030 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    031 */
    032public class CourseSection implements Comparable<CourseSection> {
    033    private Course iCourse;
    034    private Section iSection;
    035
    036    /**
    037     * Constructor
    038     * @param course selected course offering
    039     * @param section selected class
    040     */
    041    public CourseSection(Course course, Section section) {
    042        iCourse = course;
    043        iSection = section;
    044    }
    045
    046    /**
    047     * Course
    048     * @return selected course offering
    049     */
    050    public Course getCourse() { return iCourse; }
    051
    052    /**
    053     * Class
    054     * @return selected class
    055     */
    056    public Section getSection() { return iSection; }
    057
    058    @Override
    059    public boolean equals(Object o) {
    060        if (o == null || !(o instanceof CourseSection)) return false;
    061        CourseSection cs = (CourseSection)o;
    062        return getCourse().equals(cs.getCourse()) && getSection().equals(cs.getSection());
    063    }
    064
    065    @Override
    066    public int hashCode() {
    067        long h1 = getCourse().hashCode();
    068        long h2 = getSection().hashCode();
    069        return (int)(h1 ^ (h2 >>> 32));
    070    }
    071
    072    @Override
    073    public int compareTo(CourseSection other) {
    074        int cmp = getCourse().getName().compareTo(other.getCourse().getName());
    075        if (cmp != 0) return cmp;
    076        cmp = getSection().getSubpart().getInstructionalType().compareTo(other.getSection().getSubpart().getInstructionalType());
    077        if (cmp != 0) return cmp;
    078        // cmp = getSection().getName().compareTo(other.getSection().getName());
    079        // if (cmp != 0) return cmp;
    080        return getSection().getId() < other.getSection().getId() ? -1 : getSection().getId() == other.getSection().getId() ? 0 : 1;
    081    }
    082}