diff options
| author | Michael Lizzio <142752852+Michael-Lizzio@users.noreply.github.com> | 2025-11-11 08:17:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-11 08:17:00 -0500 |
| commit | f438bcc00e442ec18f6a0bc8715398b981b1b189 (patch) | |
| tree | df3e18485e9a4781236f3b6c5dd8fd79ecc564e3 /src/main/java/design/model/Golfer.java | |
| parent | 868e0b1e55763f2de686332b0887398839e1fe73 (diff) | |
| parent | b58b98704f6b2d2b4a5938f5a8b87eda268ad88b (diff) | |
| download | designproject-design-6-f438bcc00e442ec18f6a0bc8715398b981b1b189.tar.gz designproject-design-6-f438bcc00e442ec18f6a0bc8715398b981b1b189.tar.bz2 designproject-design-6-f438bcc00e442ec18f6a0bc8715398b981b1b189.zip | |
Merge pull request #15 from RIT-SWEN-262/lizzio-UndoRedoSubsystem
Lizzio undo redo subsystem
Diffstat (limited to '')
| -rw-r--r-- | src/main/java/design/model/Golfer.java | 51 |
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; + } } |
