001 package net.sf.cpsolver.exam.model; 002 003 /** 004 * Representation of a period placement of an exam. It contains a period 005 * {@link ExamPeriod} and a penalty associated with a placement of an exam into 006 * the given period. <br> 007 * <br> 008 * 009 * @version ExamTT 1.2 (Examination Timetabling)<br> 010 * Copyright (C) 2008 - 2010 Tomas Muller<br> 011 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 012 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 013 * <br> 014 * This library is free software; you can redistribute it and/or modify 015 * it under the terms of the GNU Lesser General Public License as 016 * published by the Free Software Foundation; either version 3 of the 017 * License, or (at your option) any later version. <br> 018 * <br> 019 * This library is distributed in the hope that it will be useful, but 020 * 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. <br> 023 * <br> 024 * You should have received a copy of the GNU Lesser General Public 025 * License along with this library; if not see 026 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 027 */ 028 public class ExamPeriodPlacement implements Comparable<ExamPeriodPlacement> { 029 private ExamPeriod iPeriod; 030 private int iPenalty; 031 032 /** 033 * Constructor 034 * 035 * @param period 036 * examination period that is available for an exam and that is 037 * of enough length 038 * @param penalty 039 * period penalty for given exam 040 */ 041 public ExamPeriodPlacement(ExamPeriod period, int penalty) { 042 iPeriod = period; 043 iPenalty = penalty; 044 } 045 046 /** Examination period */ 047 public ExamPeriod getPeriod() { 048 return iPeriod; 049 } 050 051 /** Examination period id */ 052 public Long getId() { 053 return getPeriod().getId(); 054 } 055 056 /** Examination period index */ 057 public int getIndex() { 058 return getPeriod().getIndex(); 059 } 060 061 /** 062 * Examination period penalty (for an assignment of this period to the given 063 * exam {@link Exam#getPeriodPlacements()}) 064 * 065 * @return given penalty plus global period penalty 066 * {@link ExamPeriod#getPenalty()} 067 */ 068 public int getPenalty() { 069 return iPenalty + iPeriod.getPenalty(); 070 } 071 072 /** 073 * Hash code 074 */ 075 @Override 076 public int hashCode() { 077 return getPeriod().hashCode(); 078 } 079 080 @Override 081 public String toString() { 082 return getPeriod().toString() + (getPenalty() == 0 ? "" : "/" + getPenalty()); 083 } 084 085 /** Compare two room placements for equality */ 086 @Override 087 public boolean equals(Object o) { 088 if (o == null) 089 return false; 090 if (o instanceof ExamPeriodPlacement) { 091 return getPeriod().equals(((ExamPeriodPlacement) o).getPeriod()); 092 } else if (o instanceof ExamPeriod) { 093 return getPeriod().equals(o); 094 } 095 return false; 096 } 097 098 /** Compare two period placements */ 099 @Override 100 public int compareTo(ExamPeriodPlacement o) { 101 return getPeriod().compareTo(o.getPeriod()); 102 } 103 }