001package org.cpsolver.exam.reports;
002
003import java.util.Comparator;
004
005import org.cpsolver.exam.model.Exam;
006import org.cpsolver.exam.model.ExamRoomPlacement;
007
008
009/**
010 * Compare two rooms by size. Either normal seating size or alternative sating
011 * size is used, based on the given exam (see {@link Exam#hasAltSeating()}. <br>
012 * <br>
013 * 
014 * @author  Tomáš Müller
015 * @version ExamTT 1.3 (Examination Timetabling)<br>
016 *          Copyright (C) 2008 - 2014 Tomáš Müller<br>
017 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
018 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
019 * <br>
020 *          This library is free software; you can redistribute it and/or modify
021 *          it under the terms of the GNU Lesser General Public License as
022 *          published by the Free Software Foundation; either version 3 of the
023 *          License, or (at your option) any later version. <br>
024 * <br>
025 *          This library is distributed in the hope that it will be useful, but
026 *          WITHOUT ANY WARRANTY; without even the implied warranty of
027 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
028 *          Lesser General Public License for more details. <br>
029 * <br>
030 *          You should have received a copy of the GNU Lesser General Public
031 *          License along with this library; if not see
032 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
033 */
034public class ExamRoomComparator implements Comparator<ExamRoomPlacement> {
035    private boolean iAsc;
036    private Exam iExam;
037
038    /**
039     * Constructor
040     * 
041     * @param exam
042     *            exam for which rooms are to be compared
043     * @param asc room order
044     */
045    public ExamRoomComparator(Exam exam, boolean asc) {
046        iExam = exam;
047        iAsc = asc;
048    }
049
050    /**
051     * Compare two rooms based on their normal/alternative seating size
052     */
053    @Override
054    public int compare(ExamRoomPlacement r1, ExamRoomPlacement r2) {
055        int cmp = (iAsc ? 1 : -1)
056                * Double.compare(r1.getSize(iExam.hasAltSeating()), r2.getSize(iExam.hasAltSeating()));
057        if (cmp != 0)
058            return cmp;
059        return r1.getRoom().compareTo(r2.getRoom());
060    }
061}