/*
 * This file is part of ReqTracker.
 *
 * Copyright (C) 2015 Taleh Didover, Florian Gerdes, Dmitry Gorelenkov,
 *     Rajab Hassan Kaoneka, Katsiaryna Krauchanka, Tobias Polzer,
 *     Gayathery Sathya, Lukas Tajak
 *
 * ReqTracker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ReqTracker is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with ReqTracker.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.fau.osr.core.db.domain;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Gayathery
 * Requirement entity
 */

@Entity
@Table(name="requirement")
public class Requirement {

    @Id
    @Column(name="id", nullable = false)
    private String id;

    @Column(name="title")
    private String title;

    @Column(name="description")
    private String description;

    @Column(name="story_point")
    private Integer storyPoint;


    @ManyToMany(cascade = {CascadeType.PERSIST}, fetch = FetchType.EAGER)
    @JoinTable(name="requirements_commits",
            joinColumns={@JoinColumn(name="req_id")},
            inverseJoinColumns={@JoinColumn(name="commit_id")})
    private Set<Commit> commits = new HashSet<>();

    public Set<Commit> getCommits() {return commits;}
    public void setCommits(Set<Commit> commits) {this.commits = commits;}
    

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getStoryPoint() {
        return (storyPoint != null) ? storyPoint : -1;
    }

    public void setStoryPoint(Integer storyPoint) {
        this.storyPoint = storyPoint;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Requirement)) return false;

        Requirement that = (Requirement) o;

        if (storyPoint != that.storyPoint) return false;
        if (!id.equals(that.id)) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;
        return !(description != null ? !description.equals(that.description) : that.description != null);

    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + storyPoint;
        return result;
    }


}

@@ -943,16 +943,17 @@
 ence.*;%0A
+%0A
 import j
@@ -1112,16 +1112,659 @@
  %7B%0A%0A    
+/* (non-Javadoc)%0A%09 * @see java.lang.Object#hashCode()%0A%09 */%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09final int prime = 31;%0A%09%09int result = 1;%0A%09%09result = prime * result + ((id == null) ? 0 : id.hashCode());%0A%09%09return result;%0A%09%7D%0A%09/* (non-Javadoc)%0A%09 * @see java.lang.Object#equals(java.lang.Object)%0A%09 */%0A%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09if (this == obj)%0A%09%09%09return true;%0A%09%09if (obj == null)%0A%09%09%09return false;%0A%09%09if (getClass() != obj.getClass())%0A%09%09%09return false;%0A%09%09Requirement other = (Requirement) obj;%0A%09%09if (id == null) %7B%0A%09%09%09if (other.id != null)%0A%09%09%09%09return false;%0A%09%09%7D else if (!id.equals(other.id))%0A%09%09%09return false;%0A%09%09return true;%0A%09%7D%0A%0A%09
 @Id%0A    
@@ -3056,809 +3056,8 @@
  %7D%0A%0A
-    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (!(o instanceof Requirement)) return false;%0A%0A        Requirement that = (Requirement) o;%0A%0A        if (storyPoint != that.storyPoint) return false;%0A        if (!id.equals(that.id)) return false;%0A        if (title != null ? !title.equals(that.title) : that.title != null) return false;%0A        return !(description != null ? !description.equals(that.description) : that.description != null);%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = id.hashCode();%0A        result = 31 * result + (title != null ? title.hashCode() : 0);%0A        result = 31 * result + (description != null ? description.hashCode() : 0);%0A        result = 31 * result + storyPoint;%0A        return result;%0A    %7D%0A
 %0A%0A%7D%0A

Fix #157:Proper hashCode and equals in Requirement