001 package net.sf.cpsolver.exam.model; 002 003 import java.util.HashSet; 004 import java.util.Set; 005 006 /** 007 * Representation of a course or a section (or any other group of students that is 008 * associated with an exam). This entity is not used 009 * for examination timetabling, but it may be important for reports since 010 * students are usually enrolled to sections and/or courses and an exam 011 * can be offered for a set of courses/sections. 012 * <br><br> 013 * The relations between course/section and exams, students and instructors are 014 * bidirectional, see {@link Exam#getOwners()}, 015 * {@link ExamStudent#getOwners()}, and 016 * {@link ExamInstructor#getOwners()}. 017 * <br><br> 018 * 019 * @version 020 * ExamTT 1.1 (Examination Timetabling)<br> 021 * Copyright (C) 2008 Tomáš Müller<br> 022 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 023 * Lazenska 391, 76314 Zlin, Czech Republic<br> 024 * <br> 025 * This library is free software; you can redistribute it and/or 026 * modify it under the terms of the GNU Lesser General Public 027 * License as published by the Free Software Foundation; either 028 * version 2.1 of the License, or (at your option) any later version. 029 * <br><br> 030 * This library is distributed in the hope that it will be useful, 031 * but WITHOUT ANY WARRANTY; without even the implied warranty of 032 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 033 * Lesser General Public License for more details. 034 * <br><br> 035 * You should have received a copy of the GNU Lesser General Public 036 * License along with this library; if not, write to the Free Software 037 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 038 */ 039 public class ExamOwner implements Comparable { 040 private long iId; 041 private String iName; 042 private Exam iExam; 043 private HashSet iStudents = new HashSet(); 044 private HashSet iInstructors = new HashSet(); 045 046 /** 047 * Constructor. 048 * @param exam an exam for this course/section 049 * @param id unique id 050 * @param name course/section name 051 */ 052 public ExamOwner(Exam exam, long id, String name) { 053 iExam = exam; 054 iId = id; 055 iName = name; 056 } 057 058 /** 059 * Unique identifier 060 */ 061 public long getId() { 062 return iId; 063 } 064 065 /** 066 * Course/section name 067 */ 068 public String getName() { 069 return iName; 070 } 071 072 /** 073 * An exam for this course/section 074 */ 075 public Exam getExam() { 076 return iExam; 077 } 078 079 /** 080 * List of students that are enrolled into this section/course 081 * @return set of {@link ExamStudent} 082 */ 083 public Set getStudents() { 084 return iStudents; 085 } 086 087 /** 088 * List of instructors that are enrolled into this section/course 089 * @return set of {@link ExamInstructor} 090 */ 091 public Set getIntructors() { 092 return iInstructors; 093 } 094 095 /** 096 * String representation -- course/section name 097 */ 098 public String toString() { 099 return iName; 100 } 101 102 /** Hash code */ 103 public int hashCode() { 104 return (int)(iId ^ (iId >>> 32)); 105 } 106 107 /** Compare two exam owners for equality */ 108 public boolean equals(Object o) { 109 if (o==null || !(o instanceof ExamOwner)) return false; 110 return getId() == ((ExamOwner)o).getId(); 111 } 112 113 /** Compare two exam owners by name */ 114 public int compareTo(Object o) { 115 ExamOwner owner = (ExamOwner)o; 116 if (!getName().equals(owner.getName())) return getName().compareTo(owner.getName()); 117 return Double.compare(getId(),owner.getId()); 118 } 119 }