package design.model.statistics; import java.util.Arrays; import design.model.Hole; import design.model.Play; import design.model.Round; public class HoleStats extends StatisticsDecorator{ private Hole target_hole; public HoleStats(Statistics wrapped_statistics, Hole target_hole){ super(wrapped_statistics); this.target_hole = target_hole; } @Override public Round[] getRounds(){ return Arrays.stream(super.getRounds()) .filter(round -> round.getCourse().getHoles().contains(target_hole)) .toArray(Round[]::new); } @Override public int get_score() { // Sum swings only on the target hole int totalSwings = 0; for (Round round : super.getRounds()) { for (Play play : round.getPlays()) { if (play.getHoleNumber() == target_hole.getNumber()) { totalSwings += play.getSwingCount(); } } } return totalSwings; } @Override public double get_distance() { // Sum distances only on the target hole double totalDistance = 0; for (Round round : super.getRounds()) { for (Play play : round.getPlays()) { if (play.getHoleNumber() == target_hole.getNumber()) { totalDistance += play.getDistance(); } } } return totalDistance; } }