summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/Club.java
blob: c19811c40c87929e9d495eff7e95e49b6bd8a1aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
package design.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@JsonIdentityInfo(
        generator = ObjectIdGenerators.PropertyGenerator.class,
        property = "id",
        scope = Club.class
)
public class Club {

    public enum ClubType {
        DRIVER,
        WOOD,
        IRON,
        HYBRID,
        PITCHING_WEDGE,
        SAND_WEDGE,
        LOB_WEDGE,
        PUTTER
    }

    private int id;
    private final String manufacture;
    private final String nickname;
    private final ClubType clubType;

    @JsonCreator
    private Club(int id, String manufacture, String nickname, ClubType clubType) {
        this.id = id;
        this.manufacture = manufacture;
        this.nickname = nickname;
        this.clubType = clubType;
    }

    public Club(String manufacture, String nickname, ClubType clubType) {
        this.id = -1;
        this.manufacture = manufacture;
        this.nickname = nickname;
        this.clubType = clubType;
    }

    public int getId() {
        return id;
    }

    public String getManufacture() {
        return manufacture;
    }

    public String getNickname() {
        return nickname;
    }

    public ClubType getClubType() {
        return clubType;
    }

    public void setId(int id) {
        assert this.id == -1;
        this.id = id;
    }

    @Override
    public String toString() {
        return String.format("#%d %s - %s (%s)", id, nickname, manufacture, clubType);
    }
}