001package org.woehlke.javaee7.petclinic.entities;
002
003import org.hibernate.validator.constraints.NotEmpty;
004
005import javax.persistence.*;
006
007/**
008 * Created with IntelliJ IDEA.
009 * User: tw
010 * Date: 01.01.14
011 * Time: 21:11
012 * To change this template use File | Settings | File Templates.
013 */
014@Entity
015@Table(name = "specialties")
016public class Specialty implements Comparable<Specialty> {
017
018    @Id
019    @GeneratedValue(strategy = GenerationType.AUTO)
020    private Long id;
021
022    @NotEmpty
023    @Column(name = "name")
024    private String name;
025
026    public Long getId() {
027        return id;
028    }
029
030    public void setId(Long id) {
031        this.id = id;
032    }
033
034    public String getName() {
035        return name;
036    }
037
038    public void setName(String name) {
039        this.name = name;
040    }
041
042    @Override
043        public int compareTo(Specialty other) {
044                return this.name.compareTo(other.getName());
045        }
046
047
048    @Override
049    public boolean equals(Object o) {
050        if (this == o) return true;
051        if (!(o instanceof Specialty)) return false;
052
053        Specialty specialty = (Specialty) o;
054
055        if (id != null ? !id.equals(specialty.id) : specialty.id != null) return false;
056        if (name != null ? !name.equals(specialty.name) : specialty.name != null) return false;
057
058        return true;
059    }
060
061    @Override
062    public int hashCode() {
063        int result = id != null ? id.hashCode() : 0;
064        result = 31 * result + (name != null ? name.hashCode() : 0);
065        return result;
066    }
067
068    @Override
069    public String toString() {
070        return "Specialty{" +
071                "id=" + id +
072                ", name='" + name + '\'' +
073                '}';
074    }
075
076        
077}