Commit f1d30570 authored by NewbieOrange's avatar NewbieOrange
Browse files

Add equals and hashcode function to DTOs

parent 15369ed7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -10,9 +10,13 @@ public class Course {
    //A courseId is valid if it has been added to the system with addCourse()
    // do not check whether it is 'CS307' or '307CS'
    public String id;

    public String name;

    public int credit;

    public int classHour;

    public CourseGrading grading;

    @Override
+23 −0
Original line number Diff line number Diff line
package cn.edu.sustech.cs307.dto;

import java.util.List;
import java.util.Objects;
import java.util.Set;

public class CourseSearchEntry {
@@ -8,14 +9,17 @@ public class CourseSearchEntry {
     * The course of the searched section
     */
    public Course course;

    /**
     * The searched course section
     */
    public CourseSection section;

    /**
     * All classes of the section
     */
    public Set<CourseSectionClass> sectionClasses;

    /**
     * List all course or time conflicting courses' full name, sorted alphabetically.
     * Course full name: String.format("%s[%s]", course.name, section.name)
@@ -25,4 +29,23 @@ public class CourseSearchEntry {
     * Note that a section is both course and time conflicting with itself!
     */
    public List<String> conflictCourseNames;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CourseSearchEntry entry = (CourseSearchEntry) o;
        return course.equals(entry.course) && section.equals(entry.section) && sectionClasses
                .equals(entry.sectionClasses)
                && conflictCourseNames.equals(entry.conflictCourseNames);
    }

    @Override
    public int hashCode() {
        return Objects.hash(course, section, sectionClasses, conflictCourseNames);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ public class CourseSection {
     * if the course name is "database principle", the name here could be "No.1 Chinese class", "No.1 English class" ...
     */
    public String name;

    public int totalCapacity, leftCapacity;

    @Override
+20 −0
Original line number Diff line number Diff line
package cn.edu.sustech.cs307.dto;

import java.util.Objects;

public class Department {
    public int id;

    public String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Department that = (Department) o;
        return id == that.id && name.equals(that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}
+21 −0
Original line number Diff line number Diff line
package cn.edu.sustech.cs307.dto;

import java.sql.Date;
import java.util.Objects;

/**
 * In our benchmark, there won't be overlapped semesters.
 */
public class Semester {
    public int id;

    public String name;

    /**
     * If the end date is before the start date, you need give an illegal Argument Error
     * If the date is ridiculous, such as 1900-1-1 or 3000-1-1, it should not give error.
     */
    public Date begin, end;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Semester semester = (Semester) o;
        return id == semester.id && name.equals(semester.name) && begin.equals(semester.begin) && end
                .equals(semester.end);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, begin, end);
    }
}