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