    001package org.cpsolver.studentsct.model;
    002
    003import org.cpsolver.ifs.util.ToolBox;
    004
    005/**
    006 * Academic area, classification, and major code. This class is used for
    007 * {@link Student#getAreaClassificationMajors()}. <br>
    008 * <br>
    009 *
    010 * @author  Tomáš Müller
    011 * @version StudentSct 1.3 (Student Sectioning)<br>
    012 *          Copyright (C) 2007 - 2014 Tomáš Müller<br>
    013 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    014 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    015 * <br>
    016 *          This library is free software; you can redistribute it and/or modify
    017 *          it under the terms of the GNU Lesser General Public License as
    018 *          published by the Free Software Foundation; either version 3 of the
    019 *          License, or (at your option) any later version. <br>
    020 * <br>
    021 *          This library is distributed in the hope that it will be useful, but
    022 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    023 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    024 *          Lesser General Public License for more details. <br>
    025 * <br>
    026 *          You should have received a copy of the GNU Lesser General Public
    027 *          License along with this library; if not see
    028 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    029 */
    030public class AreaClassificationMajor implements Comparable<AreaClassificationMajor>{
    031    private String iArea, iClassification, iMajor, iConcentration;
    032    private String iAreaName, iClassificationName, iMajorName, iConcentrationName;
    033    private Double iWeight;
    034    private String iDegree, iDegreeName;
    035    private String iProgram, iProgramName;
    036    private String iCampus, iCampusName;
    037
    038    /**
    039     * Constructor
    040     *
    041     * @param area academic area
    042     * @param classification academic classification
    043     * @param major major
    044     */
    045    public AreaClassificationMajor(String area, String classification, String major) {
    046        iArea = area;
    047        iClassification = classification;
    048        iMajor = major;
    049    }
    050
    051    /**
    052     * Constructor
    053     *
    054     * @param area academic area
    055     * @param classification academic classification
    056     * @param major major
    057     * @param concentration concentration (optional)
    058     */
    059    public AreaClassificationMajor(String area, String classification, String major, String concentration) {
    060        iArea = area;
    061        iClassification = classification;
    062        iMajor = major;
    063        iConcentration = concentration;
    064    }
    065
    066    /**
    067     * Constructor
    068     *
    069     * @param area academic area
    070     * @param classification academic classification
    071     * @param major major
    072     * @param concentration concentration (optional)
    073     * @param weight weight (optional)
    074     */
    075    public AreaClassificationMajor(String area, String classification, String major, String concentration, Double weight) {
    076        iArea = area;
    077        iClassification = classification;
    078        iMajor = major;
    079        iConcentration = concentration;
    080        iWeight = weight;
    081    }
    082
    083    /**
    084     * Constructor
    085     *
    086     * @param areaCode academic area abbreviation
    087     * @param areaName academic area name
    088     * @param classificationCode academic classificationCode
    089     * @param classificationName academic classificationName
    090     * @param majorCode major code
    091     * @param majorName major name
    092     */
    093    public AreaClassificationMajor(String areaCode, String areaName, String classificationCode, String classificationName, String majorCode, String majorName) {
    094        iArea = areaCode;
    095        iAreaName = areaName;
    096        iClassification = classificationCode;
    097        iClassificationName = classificationName;
    098        iMajor = majorCode;
    099        iMajorName = majorName;
    100    }
    101
    102    /**
    103     * Constructor
    104     *
    105     * @param areaCode academic area abbreviation
    106     * @param areaName academic area name
    107     * @param classificationCode academic classificationCode
    108     * @param classificationName academic classificationName
    109     * @param majorCode major code
    110     * @param majorName major name
    111     * @param concentrationCode concentration (optional)
    112     * @param concentrationName concentration (optional)
    113     */
    114    public AreaClassificationMajor(String areaCode, String areaName, String classificationCode, String classificationName, String majorCode, String majorName, String concentrationCode, String concentrationName) {
    115        iArea = areaCode;
    116        iAreaName = areaName;
    117        iClassification = classificationCode;
    118        iClassificationName = classificationName;
    119        iMajor = majorCode;
    120        iMajorName = majorName;
    121        iConcentration = concentrationCode;
    122        iConcentrationName = concentrationName;
    123    }
    124
    125    /**
    126     * Constructor
    127     *
    128     * @param areaCode academic area abbreviation
    129     * @param areaName academic area name
    130     * @param classificationCode academic classificationCode
    131     * @param classificationName academic classificationName
    132     * @param majorCode major code
    133     * @param majorName major name
    134     * @param concentrationCode concentration (optional)
    135     * @param concentrationName concentration (optional)
    136     * @param weight weight (optional)
    137     */
    138    public AreaClassificationMajor(String areaCode, String areaName, String classificationCode, String classificationName, String majorCode, String majorName, String concentrationCode, String concentrationName, Double weight) {
    139        iArea = areaCode;
    140        iAreaName = areaName;
    141        iClassification = classificationCode;
    142        iClassificationName = classificationName;
    143        iMajor = majorCode;
    144        iMajorName = majorName;
    145        iConcentration = concentrationCode;
    146        iConcentrationName = concentrationName;
    147        iWeight = weight;
    148    }
    149
    150    /**
    151     * Constructor
    152     *
    153     * @param areaCode academic area abbreviation
    154     * @param areaName academic area name
    155     * @param classificationCode academic classificationCode
    156     * @param classificationName academic classificationName
    157     * @param majorCode major code
    158     * @param majorName major name
    159     * @param concentrationCode concentration (optional)
    160     * @param concentrationName concentration (optional)
    161     * @param degreeCode degree (optional)
    162     * @param degreeName degree (optional)
    163     * @param weight weight (optional)
    164     */
    165    public AreaClassificationMajor(
    166            String areaCode, String areaName,
    167            String classificationCode, String classificationName,
    168            String majorCode, String majorName,
    169            String concentrationCode, String concentrationName,
    170            String degreeCode, String degreeName,
    171            Double weight) {
    172        iArea = areaCode;
    173        iAreaName = areaName;
    174        iClassification = classificationCode;
    175        iClassificationName = classificationName;
    176        iMajor = majorCode;
    177        iMajorName = majorName;
    178        iConcentration = concentrationCode;
    179        iConcentrationName = concentrationName;
    180        iDegree = degreeCode;
    181        iDegreeName = degreeName;
    182        iWeight = weight;
    183    }
    184
    185    /**
    186     * Constructor
    187     *
    188     * @param areaCode academic area abbreviation
    189     * @param areaName academic area name
    190     * @param classificationCode academic classificationCode
    191     * @param classificationName academic classificationName
    192     * @param majorCode major code
    193     * @param majorName major name
    194     * @param concentrationCode concentration (optional)
    195     * @param concentrationName concentration (optional)
    196     * @param degreeCode degree (optional)
    197     * @param degreeName degree (optional)
    198     * @param programCode program (optional)
    199     * @param programName program (optional)
    200     * @param weight weight (optional)
    201     */
    202    public AreaClassificationMajor(
    203            String areaCode, String areaName,
    204            String classificationCode, String classificationName,
    205            String majorCode, String majorName,
    206            String concentrationCode, String concentrationName,
    207            String degreeCode, String degreeName,
    208            String programCode, String programName,
    209            Double weight) {
    210        iArea = areaCode;
    211        iAreaName = areaName;
    212        iClassification = classificationCode;
    213        iClassificationName = classificationName;
    214        iMajor = majorCode;
    215        iMajorName = majorName;
    216        iConcentration = concentrationCode;
    217        iConcentrationName = concentrationName;
    218        iDegree = degreeCode;
    219        iDegreeName = degreeName;
    220        iProgram = programCode;
    221        iProgramName = programName;
    222        iWeight = weight;
    223    }
    224
    225    /**
    226     * Constructor
    227     *
    228     * @param areaCode academic area abbreviation
    229     * @param areaName academic area name
    230     * @param classificationCode academic classificationCode
    231     * @param classificationName academic classificationName
    232     * @param majorCode major code
    233     * @param majorName major name
    234     * @param concentrationCode concentration (optional)
    235     * @param concentrationName concentration (optional)
    236     * @param degreeCode degree (optional)
    237     * @param degreeName degree (optional)
    238     * @param programCode program (optional)
    239     * @param programName program (optional)
    240     * @param weight weight (optional)
    241     */
    242    public AreaClassificationMajor(
    243            String areaCode, String areaName,
    244            String classificationCode, String classificationName,
    245            String majorCode, String majorName,
    246            String concentrationCode, String concentrationName,
    247            String degreeCode, String degreeName,
    248            String programCode, String programName,
    249            String campus, String campusName,
    250            Double weight) {
    251        iArea = areaCode;
    252        iAreaName = areaName;
    253        iClassification = classificationCode;
    254        iClassificationName = classificationName;
    255        iMajor = majorCode;
    256        iMajorName = majorName;
    257        iConcentration = concentrationCode;
    258        iConcentrationName = concentrationName;
    259        iDegree = degreeCode;
    260        iDegreeName = degreeName;
    261        iProgram = programCode;
    262        iProgramName = programName;
    263        iCampus = campus;
    264        iCampusName = campusName;
    265        iWeight = weight;
    266    }
    267
    268    /** Academic area
    269     * @return academic area abbreviation
    270     **/
    271    public String getArea() {
    272        return iArea;
    273    }
    274
    275    /** Academic classification
    276     * @return classification code
    277     **/
    278    public String getClassification() {
    279        return iClassification;
    280    }
    281
    282    /** Major
    283     * @return major code
    284     **/
    285    public String getMajor() {
    286        return iMajor;
    287    }
    288
    289    /** Concentration (optional)
    290     * @return concentration code
    291     **/
    292    public String getConcentration() {
    293        return iConcentration;
    294    }
    295
    296    /** Degree (optional)
    297     * @return degree code
    298     **/
    299    public String getDegree() {
    300        return iDegree;
    301    }
    302
    303    /** Program (optional)
    304     * @return program code
    305     **/
    306    public String getProgram() {
    307        return iProgram;
    308    }
    309
    310    /** Academic area  name
    311     * @return academic area name
    312     **/
    313    public String getAreaName() {
    314        return iAreaName;
    315    }
    316
    317    /** Academic classification name
    318     * @return classification name
    319     **/
    320    public String getClassificationName() {
    321        return iClassificationName;
    322    }
    323
    324    /** Major name
    325     * @return major name
    326     **/
    327    public String getMajorName() {
    328        return iMajorName;
    329    }
    330
    331    /** Concentration (optional)
    332     * @return concentration name
    333     **/
    334    public String getConcentrationName() {
    335        return iConcentrationName;
    336    }
    337
    338    /** Degree (optional)
    339     * @return degree name
    340     **/
    341    public String getDegreeName() {
    342        return iDegreeName;
    343    }
    344
    345    /** Program (optional)
    346     * @return program name
    347     **/
    348    public String getProgramName() {
    349        return iProgramName;
    350    }
    351
    352    /** Campus (optional)
    353     * @return campus name
    354     **/
    355    public String getCampus() {
    356        return iCampus;
    357    }
    358
    359    /** Campus (optional)
    360     * @return campus name
    361     **/
    362    public String getCampusName() {
    363        return iCampusName;
    364    }
    365
    366    /** Weight (optional, defaults to 1.0)
    367     */
    368    public double getWeight() { return iWeight == null ? 1.0 : iWeight.doubleValue(); }
    369
    370    @Override
    371    public int hashCode() {
    372        return toString().hashCode();
    373    }
    374
    375    @Override
    376    public boolean equals(Object o) {
    377        if (o == null || !(o instanceof AreaClassificationMajor))
    378            return false;
    379        AreaClassificationMajor acm = (AreaClassificationMajor) o;
    380        return ToolBox.equals(acm.getArea(), getArea()) && ToolBox.equals(acm.getClassification(), getClassification()) && ToolBox.equals(acm.getMajor(), getMajor());
    381    }
    382
    383    @Override
    384    public String toString() {
    385        return getArea() + "/" + getMajor() + (getConcentration() == null || getConcentration().isEmpty()? "" : "-" + getConcentration()) + " " + getClassification();
    386    }
    387
    388    private String getDegreeNotNull() { return (iDegree == null ? "" : iDegree); }
    389    private String getProgramNotNull() { return (iProgram == null ? "" : iProgram); }
    390    private String getCampusNotNull() { return (iCampus == null ? "" : iCampus); }
    391    private String getConcentrationNotNull() { return (iConcentration == null ? "" : iConcentration); }
    392
    393    @Override
    394    public int compareTo(AreaClassificationMajor acm) {
    395            if (getWeight() != acm.getWeight())
    396                    return getWeight() > acm.getWeight() ? -1 : 1;
    397            if (!getArea().equals(acm.getArea()))
    398                    return getArea().compareTo(acm.getArea());
    399            if (!getClassification().equals(acm.getClassification()))
    400                    return getClassification().compareTo(acm.getClassification());
    401            if (!getDegreeNotNull().equals(acm.getDegreeNotNull()))
    402                    return getDegreeNotNull().compareTo(acm.getDegreeNotNull());
    403            if (!getProgramNotNull().equals(acm.getProgramNotNull()))
    404                    return getProgramNotNull().compareTo(acm.getProgramNotNull());
    405            if (!getMajor().equals(acm.getMajor()))
    406                    return getMajor().compareTo(acm.getMajor());
    407            if (!getCampusNotNull().equals(acm.getCampusNotNull()))
    408                    return getCampusNotNull().compareTo(acm.getCampusNotNull());
    409            return getConcentrationNotNull().compareTo(acm.getConcentrationNotNull());
    410    }
    411}