From c9dbbbf82277036d15a180b0e8609b6dfccb50bd Mon Sep 17 00:00:00 2001 From: WillemDalton Date: Mon, 29 Sep 2025 18:26:42 -0400 Subject: progress on implementing strategy pattern --- src/main/java/design/model/Golfer.java | 66 ---------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/main/java/design/model/Golfer.java (limited to 'src/main/java/design/model/Golfer.java') diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java deleted file mode 100644 index 8f09067..0000000 --- a/src/main/java/design/model/Golfer.java +++ /dev/null @@ -1,66 +0,0 @@ -package design.model; - -import java.util.ArrayList; -import java.util.List; - -public class Golfer { - private String username; - private int passwordHash; - private String fullName; - private final transient List courses; // might be better to make this like a courseID or something - private final List rounds; - - public Golfer(String fullName, String username, String password) { - this.courses = new ArrayList<>(); - this.rounds = new ArrayList<>(); - this.fullName = fullName; - this.username = username; - this.passwordHash = password.hashCode(); - } - - 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); - } - - -} -- cgit v1.2.3 From e218e35f333f8a30d213c7d3eebeb6f5f6bbcea3 Mon Sep 17 00:00:00 2001 From: WillemDalton Date: Thu, 2 Oct 2025 08:55:33 -0400 Subject: more progress on the strategy, unit testing --- src/main/java/design/model/Golfer.java | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/design/model/Golfer.java (limited to 'src/main/java/design/model/Golfer.java') diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java new file mode 100644 index 0000000..8f09067 --- /dev/null +++ b/src/main/java/design/model/Golfer.java @@ -0,0 +1,66 @@ +package design.model; + +import java.util.ArrayList; +import java.util.List; + +public class Golfer { + private String username; + private int passwordHash; + private String fullName; + private final transient List courses; // might be better to make this like a courseID or something + private final List rounds; + + public Golfer(String fullName, String username, String password) { + this.courses = new ArrayList<>(); + this.rounds = new ArrayList<>(); + this.fullName = fullName; + this.username = username; + this.passwordHash = password.hashCode(); + } + + 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); + } + + +} -- cgit v1.2.3 From d982cfe8a22ec7eb89186fed875a483a51c3505f Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 3 Oct 2025 00:31:02 -0400 Subject: Add code to handle id serialization --- src/main/java/design/model/Golfer.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/design/model/Golfer.java') diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index 8f09067..1a6c7b6 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -7,15 +7,24 @@ public class Golfer { private String username; private int passwordHash; private String fullName; - private final transient List courses; // might be better to make this like a courseID or something + private final List courses; private final List rounds; + // for deserialization + public Golfer(String username, int passwordHash, String fullName, List courses, List 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.courses = new ArrayList<>(); - this.rounds = new ArrayList<>(); this.fullName = fullName; this.username = username; this.passwordHash = password.hashCode(); + this.courses = new ArrayList<>(); + this.rounds = new ArrayList<>(); } public String getUsername() { @@ -61,6 +70,4 @@ public class Golfer { public void addRound(Round round) { rounds.add(round); } - - } -- cgit v1.2.3 From 29c4a7caffea3957b8ac5f6be13d640c1a798989 Mon Sep 17 00:00:00 2001 From: sowgro Date: Fri, 3 Oct 2025 20:37:43 -0400 Subject: Serialization fully working --- src/main/java/design/model/Golfer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main/java/design/model/Golfer.java') diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index 1a6c7b6..04ad8bc 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -1,5 +1,7 @@ package design.model; +import com.fasterxml.jackson.annotation.JsonCreator; + import java.util.ArrayList; import java.util.List; @@ -10,8 +12,8 @@ public class Golfer { private final List courses; private final List rounds; - // for deserialization - public Golfer(String username, int passwordHash, String fullName, List courses, List rounds) { + @JsonCreator + private Golfer(String username, int passwordHash, String fullName, List courses, List rounds) { this.username = username; this.passwordHash = passwordHash; this.fullName = fullName; -- cgit v1.2.3