    001package org.cpsolver.instructor.model;
    002
    003import org.cpsolver.coursett.Constants;
    004
    005/**
    006 * A preference. This class encapsulates a time, course, instructor, or attribute preference.
    007 *
    008 * @version IFS 1.3 (Instructor Sectioning)<br>
    009 *          Copyright (C) 2016 Tomáš Müller<br>
    010 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    011 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    012 * <br>
    013 *          This library is free software; you can redistribute it and/or modify
    014 *          it under the terms of the GNU Lesser General Public License as
    015 *          published by the Free Software Foundation; either version 3 of the
    016 *          License, or (at your option) any later version. <br>
    017 * <br>
    018 *          This library is distributed in the hope that it will be useful, but
    019 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    020 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    021 *          Lesser General Public License for more details. <br>
    022 * <br>
    023 *          You should have received a copy of the GNU Lesser General Public
    024 *          License along with this library; if not see
    025 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    026 */
    027public class Preference<T> {
    028    protected T iTarget;
    029    protected int iPreference;
    030
    031    /**
    032     * Constructor
    033     * @param target object for which the preference is given
    034     * @param preference preference value
    035     */
    036    public Preference(T target, int preference) {
    037        iTarget = target;
    038        iPreference = preference;
    039    }
    040
    041    /**
    042     * Is required?
    043     * @return true if the preference is required
    044     */
    045    public boolean isRequired() { return iPreference < Constants.sPreferenceLevelRequired / 2; }
    046
    047    /**
    048     * Is prohibited?
    049     * @return true if the preference is prohibited
    050     */
    051    public boolean isProhibited() { return iPreference > Constants.sPreferenceLevelProhibited / 2; }
    052
    053    /**
    054     * Preference value
    055     * @return preference value
    056     */
    057    public int getPreference() { return iPreference; }
    058
    059    /**
    060     * Target object for which the preference is given
    061     * @return target
    062     */
    063    public T getTarget() { return iTarget; }
    064
    065    @Override
    066    public String toString() { return getTarget() + ": " + (isRequired() ? "R" : isProhibited() ? "P" : getPreference()); }
    067}