    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 * @author  Tomáš Müller
    009 * @version IFS 1.3 (Instructor Sectioning)<br>
    010 *          Copyright (C) 2016 Tomáš Müller<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 */
    028public class Preference<T> {
    029    protected T iTarget;
    030    protected int iPreference;
    031
    032    /**
    033     * Constructor
    034     * @param target object for which the preference is given
    035     * @param preference preference value
    036     */
    037    public Preference(T target, int preference) {
    038        iTarget = target;
    039        iPreference = preference;
    040    }
    041
    042    /**
    043     * Is required?
    044     * @return true if the preference is required
    045     */
    046    public boolean isRequired() { return iPreference < Constants.sPreferenceLevelRequired / 2; }
    047
    048    /**
    049     * Is prohibited?
    050     * @return true if the preference is prohibited
    051     */
    052    public boolean isProhibited() { return iPreference > Constants.sPreferenceLevelProhibited / 2; }
    053
    054    /**
    055     * Preference value
    056     * @return preference value
    057     */
    058    public int getPreference() { return iPreference; }
    059
    060    /**
    061     * Target object for which the preference is given
    062     * @return target
    063     */
    064    public T getTarget() { return iTarget; }
    065
    066    @Override
    067    public String toString() { return getTarget() + ": " + (isRequired() ? "R" : isProhibited() ? "P" : getPreference()); }
    068}