summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/statistics/HoleStats.java
blob: 6f6104afcd1949cdfe4d3034d9c23c02db612c5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
    }
}