001 package net.sf.cpsolver.exam.model; 002 003 /** 004 * Representation of a period placement of an exam. It contains a period {@link ExamPeriod} and a penalty 005 * associated with a placement of an exam into the given period. 006 * <br><br> 007 * 008 * @version 009 * ExamTT 1.1 (Examination Timetabling)<br> 010 * Copyright (C) 2008 Tomáš Müller<br> 011 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 012 * Lazenska 391, 76314 Zlin, Czech Republic<br> 013 * <br> 014 * This library is free software; you can redistribute it and/or 015 * modify it under the terms of the GNU Lesser General Public 016 * License as published by the Free Software Foundation; either 017 * version 2.1 of the License, or (at your option) any later version. 018 * <br><br> 019 * This library is distributed in the hope that it will be useful, 020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 022 * Lesser General Public License for more details. 023 * <br><br> 024 * You should have received a copy of the GNU Lesser General Public 025 * License along with this library; if not, write to the Free Software 026 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 027 */ 028 public class ExamPeriodPlacement implements Comparable { 029 private ExamPeriod iPeriod; 030 private int iPenalty; 031 032 /** 033 * Constructor 034 * @param period examination period that is available for an exam and that is of enough length 035 * @param penalty period penalty for given exam 036 */ 037 public ExamPeriodPlacement(ExamPeriod period, int penalty) { 038 iPeriod = period; 039 iPenalty = penalty; 040 } 041 042 /** Examination period */ 043 public ExamPeriod getPeriod() { return iPeriod; } 044 045 /** Examination period id */ 046 public Long getId() { return getPeriod().getId(); } 047 048 /** Examination period index */ 049 public int getIndex() { return getPeriod().getIndex(); } 050 051 /** Examination period penalty (for an assignment of this period to the given exam {@link Exam#getPeriodPlacements()}) 052 * @return given penalty plus global period penalty {@link ExamPeriod#getPenalty()} 053 */ 054 public int getPenalty() { return iPenalty + iPeriod.getPenalty(); } 055 056 /** 057 * Hash code 058 */ 059 public int hashCode() { 060 return getPeriod().hashCode(); 061 } 062 063 public String toString() { 064 return getPeriod().toString()+(getPenalty()==0?"":"/"+getPenalty()); 065 } 066 067 /** Compare two room placements for equality */ 068 public boolean equals(Object o) { 069 if (o==null) return false; 070 if (o instanceof ExamPeriodPlacement) { 071 return getPeriod().equals(((ExamPeriodPlacement)o).getPeriod()); 072 } else if (o instanceof ExamPeriod) { 073 return getPeriod().equals(o); 074 } 075 return false; 076 } 077 078 /** Compare two period placements */ 079 public int compareTo(Object o) { 080 if (o==null || !(o instanceof ExamPeriodPlacement)) return -1; 081 return getPeriod().compareTo(((ExamPeriodPlacement)o).getPeriod()); 082 } 083 }