001package net.sf.cpsolver.exam.reports; 002 003import java.util.Comparator; 004 005import net.sf.cpsolver.exam.model.Exam; 006import net.sf.cpsolver.exam.model.ExamRoomPlacement; 007 008/** 009 * Compare two rooms by size. Either normal seating size or alternative sating 010 * size is used, based on the given exam (see {@link Exam#hasAltSeating()}. <br> 011 * <br> 012 * 013 * @version ExamTT 1.2 (Examination Timetabling)<br> 014 * Copyright (C) 2008 - 2010 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 ExamRoomComparator implements Comparator<ExamRoomPlacement> { 033 private boolean iAsc; 034 private Exam iExam; 035 036 /** 037 * Constructor 038 * 039 * @param exam 040 * exam for which rooms are to be compared 041 */ 042 public ExamRoomComparator(Exam exam, boolean asc) { 043 iExam = exam; 044 iAsc = asc; 045 } 046 047 /** 048 * Compare two rooms based on their normal/alternative seating size 049 */ 050 @Override 051 public int compare(ExamRoomPlacement r1, ExamRoomPlacement r2) { 052 int cmp = (iAsc ? 1 : -1) 053 * Double.compare(r1.getSize(iExam.hasAltSeating()), r2.getSize(iExam.hasAltSeating())); 054 if (cmp != 0) 055 return cmp; 056 return r1.getRoom().compareTo(r2.getRoom()); 057 } 058}