summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/Golfer.java
diff options
context:
space:
mode:
authorMichael Lizzio <mjl2396@rit.edu>2025-11-10 14:19:24 -0500
committerMichael Lizzio <mjl2396@rit.edu>2025-11-10 14:19:24 -0500
commit873c9c81fab807127fb70e5abb88c8f96c9d8934 (patch)
treedb4ed2daff21e5f3f0d4c5b90b52dbc2caa689a0 /src/main/java/design/model/Golfer.java
parentc8306a0794c470c282dd0c52e8cc06d68781dbc8 (diff)
downloaddesignproject-design-6-873c9c81fab807127fb70e5abb88c8f96c9d8934.tar.gz
designproject-design-6-873c9c81fab807127fb70e5abb88c8f96c9d8934.tar.bz2
designproject-design-6-873c9c81fab807127fb70e5abb88c8f96c9d8934.zip
Added GolferMememto, updated Golfer
Diffstat (limited to 'src/main/java/design/model/Golfer.java')
-rw-r--r--src/main/java/design/model/Golfer.java51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java
index 48daae8..0f4c914 100644
--- a/src/main/java/design/model/Golfer.java
+++ b/src/main/java/design/model/Golfer.java
@@ -6,8 +6,11 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
import java.util.List;
+import design.model.undo.Memento;
+import design.model.undo.Originator;
+
@JsonPropertyOrder({ "clubs", "nextClubId" })
-public class Golfer {
+public class Golfer implements Originator {
private String username;
private int passwordHash;
private String fullName;
@@ -112,4 +115,50 @@ public class Golfer {
public void removeClub(Club c) {
clubs.remove(c);
}
+
+ // Takes a snapshot of the golfer
+ private static class GolferMemento implements Memento {
+ private final String username;
+ private final int passwordHash;
+ private final String fullName;
+ private final List<Course> courses;
+ private final List<Round> rounds;
+ private final List<Club> clubs;
+ private final int nextClubId;
+
+ GolferMemento(Golfer g) {
+ this.username = g.username;
+ this.passwordHash = g.passwordHash;
+ this.fullName = g.fullName;
+ this.courses = new ArrayList<>(g.courses);
+ this.rounds = new ArrayList<>(g.rounds);
+ this.clubs = new ArrayList<>(g.clubs);
+ this.nextClubId = g.nextClubId;
+ }
+ }
+
+ @Override
+ public Memento createMemento() {
+ return new GolferMemento(this);
+ }
+
+ @Override
+ public void restore(Memento memento) {
+ GolferMemento gm = (GolferMemento) memento;
+
+ this.username = gm.username;
+ this.passwordHash = gm.passwordHash;
+ this.fullName = gm.fullName;
+
+ this.courses.clear();
+ this.courses.addAll(gm.courses);
+
+ this.rounds.clear();
+ this.rounds.addAll(gm.rounds);
+
+ this.clubs.clear();
+ this.clubs.addAll(gm.clubs);
+
+ this.nextClubId = gm.nextClubId;
+ }
}