001package net.sf.cpsolver.studentsct.report; 002 003import net.sf.cpsolver.studentsct.model.Course; 004import net.sf.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.2 (Student Sectioning)<br> 014 * Copyright (C) 2013 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 */ 039 public CourseSection(Course course, Section section) { 040 iCourse = course; 041 iSection = section; 042 } 043 044 /** 045 * Course 046 */ 047 public Course getCourse() { return iCourse; } 048 049 /** 050 * Class 051 */ 052 public Section getSection() { return iSection; } 053 054 @Override 055 public boolean equals(Object o) { 056 if (o == null || !(o instanceof CourseSection)) return false; 057 CourseSection cs = (CourseSection)o; 058 return getCourse().equals(cs.getCourse()) && getSection().equals(cs.getSection()); 059 } 060 061 @Override 062 public int hashCode() { 063 long h1 = getCourse().hashCode(); 064 long h2 = getSection().hashCode(); 065 return (int)(h1 ^ (h2 >>> 32)); 066 } 067 068 @Override 069 public int compareTo(CourseSection other) { 070 int cmp = getCourse().getName().compareTo(other.getCourse().getName()); 071 if (cmp != 0) return cmp; 072 cmp = getSection().getSubpart().getInstructionalType().compareTo(other.getSection().getSubpart().getInstructionalType()); 073 if (cmp != 0) return cmp; 074 // cmp = getSection().getName().compareTo(other.getSection().getName()); 075 // if (cmp != 0) return cmp; 076 return getSection().getId() < other.getSection().getId() ? -1 : getSection().getId() == other.getSection().getId() ? 0 : 1; 077 } 078}