package at.ac.tuwien.inso.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;

@Entity
public class Course {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(optional = false)
    private Subject subject;

    @ManyToOne(optional = false)
    private Semester semester;

    @Column(nullable = false)
    private String description;

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private List<Tag> tags = new ArrayList<>();

    @ManyToMany
    private List<Student> students = new ArrayList<>();

    protected Course() {}

    public Course(Subject subject, Semester semester) {
        this(subject, semester, "");
    }

    public Course(Subject subject, Semester semester, String description) {
        this.subject = subject;
        this.semester = semester;
        this.description = description;
    }

    public Long getId() {
        return id;
    }

    public Subject getSubject() {
        return subject;
    }

    public Semester getSemester() {
        return semester;
    }

    public String getDescription() {
        return description;
    }

    public List<Tag> getTags() {
        return unmodifiableList(tags);
    }

    public List<Student> getStudents() {
        return students;
    }

    public void addTags(Tag... tags) {
        this.tags.addAll(asList(tags));
    }

    public void removeTags(Tag... tags) {
        this.tags.removeAll(asList(tags));
    }

    public void addStudents(Student... students) {
        this.students.addAll(asList(students));
    }

    public void removeStudents(Student... students) {
        this.students.removeAll(asList(students));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Course course = (Course) o;

        if (!id.equals(course.id)) return false;
        if (!subject.equals(course.subject)) return false;
        if (!semester.equals(course.semester)) return false;
        if (!description.equals(course.description)) return false;
        if (!tags.equals(course.tags)) return false;
        return students.equals(course.students);

    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + subject.hashCode();
        result = 31 * result + semester.hashCode();
        result = 31 * result + description.hashCode();
        result = 31 * result + tags.hashCode();
        result = 31 * result + students.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Course{" +
                "id=" + id +
                ", subject=" + subject +
                ", semester=" + semester +
                ", description='" + description + '\'' +
                ", tags=" + tags +
                ", students=" + students +
                '}';
    }
}
@@ -52,24 +52,25 @@
 sistence.*;%0A
+%0A
 import java.
@@ -666,16 +666,21 @@
 urse() %7B
+%0A    
 %7D%0A%0A    p
@@ -955,32 +955,369 @@
 ription;%0A    %7D%0A%0A
+    public void setId(Long id) %7B%0A        this.id = id;%0A    %7D%0A%0A    public void setSubject(Subject subject) %7B%0A        this.subject = subject;%0A    %7D%0A%0A    public void setSemester(Semester semester) %7B%0A        this.semester = semester;%0A    %7D%0A%0A    public void setDescription(String description) %7B%0A        this.description = description;%0A    %7D%0A%0A
     public Long 
@@ -2706,16 +2706,29 @@
 result =
+ id != null ?
  id.hash
@@ -2725,32 +2725,36 @@
  ? id.hashCode()
+ : 0
 ;%0A        result
@@ -2872,16 +2872,39 @@
 result +
+ (description != null ?
  descrip
@@ -2910,32 +2910,37 @@
 ption.hashCode()
+ : 0)
 ;%0A        result
@@ -2955,16 +2955,32 @@
 result +
+ (tags != null ?
  tags.ha
@@ -2979,32 +2979,37 @@
  tags.hashCode()
+ : 0)
 ;%0A        result
@@ -3024,16 +3024,36 @@
 result +
+ (students != null ?
  student
@@ -3056,32 +3056,37 @@
 dents.hashCode()
+ : 0)
 ;%0A        return

Add setters to course entity