HorseDto.java 3.09 KB
Newer Older
1 2
package at.ac.tuwien.sepm.assignment.individual.endpoint.dto;

3 4
import at.ac.tuwien.sepm.assignment.individual.enums.ERace;

5 6 7 8 9 10 11 12 13 14
import java.time.LocalDateTime;
import java.util.Objects;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class HorseDto extends BaseDto {
    private String name;
    private String description;
    private short score;
15
    private ERace race;
16
    private Date birthday;
17
    private Long owner;
18 19 20

    public HorseDto() {}

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

30
    public HorseDto(Long id, String name, String description, short score, Date birthday, ERace race, LocalDateTime created, LocalDateTime updated, Long owner) {
31 32 33 34 35
        super(id, created, updated);
        this.name = name;
        this.description = description;
        this.score = score;
        this.birthday = birthday;
36
        this.race = race;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        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;
    }

72 73 74 75 76 77 78 79
    public ERace getRace() {
        return race;
    }

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

80 81 82 83 84 85 86 87 88 89 90 91 92
    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 HorseDto)) return false;
        if (!super.equals(o)) return false;
93 94 95 96 97 98 99
        HorseDto h = (HorseDto) 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) &&
            Objects.equals(owner, h.owner);
100 101 102 103 104 105 106 107 108 109 110 111
    }

    @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 + '\'' +
112 113 114
            ", description='" + description + '\'' +
            ", score='" + score + '\'' +
            ", birthday='" + df.format(birthday) + '\'' +
115
            ", race='" + race + '\'' +
116
            ", owner_id='" + owner + '\'';
117 118 119 120 121 122 123
    }

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