summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/Golfer.java
blob: 19d6ac6150c8909bc843da22c21ba7faf8d14dd2 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package design.model;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.ArrayList;
import java.util.List;

public class Golfer {
    private String username;
    private int passwordHash;
    private String fullName;
    private final List<Course> courses;
    private final List<Round> rounds;
    private final List<Club> clubs = new ArrayList<>(); // Keep track of golfer's clubs

    @JsonCreator
    private Golfer(String username, int passwordHash, String fullName, List<Course> courses, List<Round> rounds) {
        this.username = username;
        this.passwordHash = passwordHash;
        this.fullName = fullName;
        this.courses = courses;
        this.rounds = rounds;
    }

    public Golfer(String fullName, String username, String password) {
        this.fullName = fullName;
        this.username = username;
        this.passwordHash = password.hashCode();
        this.courses = new ArrayList<>();
        this.rounds = new ArrayList<>();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public void setPassword(String password) {
        this.passwordHash = password.hashCode();
    }

    public boolean checkPassword(String password) {
        return passwordHash == password.hashCode();
    }

    public Course[] getCourses() {
        return courses.toArray(Course[]::new);
    }

    public void addCourse(Course course) {
        courses.add(course);
    }

    public void removeCourse(Course course) {
        courses.remove(course);
    }

    public Round[] getRounds() {
        return rounds.toArray(Round[]::new);
    }

    public void addRound(Round round) {
        rounds.add(round);
    }

    // Helpers dealing with clubs
    public void addClub(Club c) {
        clubs.add(c);
    }

    public boolean hasClub(Club c) {
        return clubs.contains(c);
    }
}