Horse.java 3.82 KB
Newer Older
1 2 3 4 5 6 7
package at.ac.tuwien.sepm.assignment.individual.entity;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.sql.Date;
import java.util.Objects;
8
import at.ac.tuwien.sepm.assignment.individual.enums.ERace;
9 10 11 12 13

public class Horse extends BaseEntity {
    private String name;
    private String description;
    private short score;
14
    private ERace race;
15
    private Date birthday;
16
    private String imagePath;
17 18 19 20
    private Long owner;

    public Horse() {}

21
    public Horse(String name, String description, short score, Date birthday, ERace race, String imagePath, Long owner) {
22 23 24 25
        this.name = name;
        this.description = description;
        this.score = score;
        this.birthday = birthday;
26
        this.race = race;
27
        this.imagePath = imagePath;
28 29 30
        this.owner = owner;
    }

31
    public Horse(Long id, String name, String description, short score, Date birthday, ERace race, String imagePath, Long owner) {
32 33 34 35 36
        super(id);
        this.name = name;
        this.description = description;
        this.score = score;
        this.birthday = birthday;
37
        this.race = race;
38
        this.imagePath = imagePath;
39 40 41
        this.owner = owner;
    }

42
    public Horse(Long id, String name, String description, short score, Date birthday, ERace race, String imagePath, Long owner, LocalDateTime created, LocalDateTime updated) {
43 44 45 46 47
        super(id, created, updated);
        this.name = name;
        this.description = description;
        this.score = score;
        this.birthday = birthday;
48
        this.race = race;
49
        this.imagePath = imagePath;
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        this.owner = owner;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

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

    public short getScore() {
        return score;
    }

    public void setScore(short score) {
        this.score = score;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

85 86 87 88 89 90 91 92
    public ERace getRace() {
        return race;
    }

    public void setRace(ERace race) {
        this.race = race;
    }

93 94 95 96 97 98 99 100
    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

101 102 103 104 105 106 107 108 109 110 111 112 113
    public Long getOwner() {
        return owner;
    }

    public void setOwner(Long owner) {
        this.owner = owner;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Horse)) return false;
        if (!super.equals(o)) return false;
114 115 116 117 118 119
        Horse h = (Horse) o;
        return Objects.equals(name, h.name) &&
            Objects.equals(description, h.description) &&
            Objects.equals(score, h.score) &&
            Objects.equals(birthday, h.birthday) &&
            Objects.equals(race, h.race) &&
120
            Objects.equals(imagePath, h.imagePath) &&
121
            Objects.equals(owner, h.owner);
122 123 124 125 126 127 128 129 130 131 132 133 134
    }

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

    @Override
    protected String fieldsString() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

        return super.fieldsString() + ", name='" + name + '\'' +
            "description='" + description + '\'' +
135 136
            ", score='" + score + '\'' +
            ", birthday='" + df.format(birthday) + '\'' +
137
            ", race='"  + race + '\'' +
138
            ", imagePath='" + imagePath + '\'' +
139
            ", owner='" + owner + '\'';
140 141 142 143 144 145 146
    }

    @Override
    public String toString() {
        return "Horse{ " + fieldsString() + " }";
    }
}