diff options
| author | Jacob Shimp <jrs9538@g.rit.edu> | 2025-11-13 08:51:31 -0500 |
|---|---|---|
| committer | Jacob Shimp <jrs9538@g.rit.edu> | 2025-11-13 08:51:31 -0500 |
| commit | f79ab927050250c4b7e63a4fbd37034d4eeae8cd (patch) | |
| tree | 2e86ca8a13453baff59c2ca01df58be8ee18226b /src/main/java/design/model/StrokeLeague.java | |
| parent | 0294bd3a3121d6166788594f7249bf293cb00896 (diff) | |
| parent | 4d1ac032652e857a6d6bd63cadad0727ddb3a345 (diff) | |
| download | designproject-design-6-f79ab927050250c4b7e63a4fbd37034d4eeae8cd.tar.gz designproject-design-6-f79ab927050250c4b7e63a4fbd37034d4eeae8cd.tar.bz2 designproject-design-6-f79ab927050250c4b7e63a4fbd37034d4eeae8cd.zip | |
merge league-play into league-model
Diffstat (limited to 'src/main/java/design/model/StrokeLeague.java')
| -rw-r--r-- | src/main/java/design/model/StrokeLeague.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/main/java/design/model/StrokeLeague.java b/src/main/java/design/model/StrokeLeague.java index 508198e..d051fd0 100644 --- a/src/main/java/design/model/StrokeLeague.java +++ b/src/main/java/design/model/StrokeLeague.java @@ -4,30 +4,41 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonTypeName; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; @JsonTypeName("stroke") public class StrokeLeague extends League { - private final List<Golfer> participants; + private List<Golfer> participants; + private Map<Golfer, Integer> totalStrokes; @JsonCreator private StrokeLeague(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner, List<Golfer> participants, List<Match> schedule) { super(id, name, registrationDate, startDate, endDate, owner, schedule); this.participants = participants; + this.totalStrokes = new HashMap<>(); + participants.forEach(p -> totalStrokes.putIfAbsent(p, 0)); } public StrokeLeague(String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { super(name, registrationDate, startDate, endDate, owner); this.participants = new ArrayList<>(); + this.totalStrokes = new HashMap<>(); } - public boolean addParticipants(Golfer e) { - return participants.add(e); + public boolean addParticipants(Golfer g) { + boolean added = participants.add(g); + if(added) totalStrokes.putIfAbsent(g, 0); + return added; } - public boolean removeParticipants(Golfer o) { - return participants.remove(o); + public boolean removeParticipants(Golfer g) { + totalStrokes.remove(g); + return participants.remove(g); } public Golfer[] getParticipants() { @@ -38,4 +49,20 @@ public class StrokeLeague extends League { public String getType() { return "stroke"; } + public void recordPlay(Golfer player, Match match, Round round){ + if(!isPlayable() || !participants.contains(player)) return; + int strokes = round.getTotalSwings(); + totalStrokes.merge(player, strokes, Integer::sum); + match.addRound(round); + } + + @Override + public void finalizeLeague(){ + markCompleted(); + participants.sort(Comparator.comparingInt(totalStrokes::get)); + } + + public Map<Golfer, Integer> getTotalStrokes(){ + return Collections.unmodifiableMap(totalStrokes); + } } |
