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 courses; private final List rounds; private final List clubs; // Keep track of golfer's clubs private int nextClubId; @JsonCreator private Golfer(String username, int passwordHash, String fullName, List courses, List rounds, List clubs) { this.username = username; this.passwordHash = passwordHash; this.fullName = fullName; this.courses = courses; this.rounds = rounds; this.clubs = clubs; this.nextClubId = this.clubs.stream().mapToInt(Club::getId).max().orElse(0) + 1; } 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<>(); this.clubs = new ArrayList<>(); this.nextClubId = 1; } 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); } public Club addClub(String manufacture, String nickname, Club.ClubType type) { Club c = new Club(nextClubId++, manufacture, nickname, type); clubs.add(c); return c; } public boolean hasClub(Club c) { return clubs.contains(c); } public Club[] getClubs() { return clubs.toArray(Club[]::new); } @Override public String toString() { return String.format("%s (@%s)", fullName, username); } public void removeClub(Club c) { clubs.remove(c); } }