summaryrefslogtreecommitdiff
path: root/src/main/java/design/model/ScrambleLeague.java
blob: d3722641cbcd54effe8cb0c853da5dd4189b43d1 (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
package design.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@JsonTypeName("scramble")
public class ScrambleLeague extends League {
    private final List<Team> participants;

    @JsonCreator
    private ScrambleLeague(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner, List<Team> participants, List<Match> schedule) {
        super(id, name, registrationDate, startDate, endDate, owner, schedule);
        this.participants = participants;
    }

    public ScrambleLeague(String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) {
        super(name, registrationDate, startDate, endDate, owner);
        this.participants = new ArrayList<>();
    }

    public boolean addParticipants(Team e) {
        return participants.add(e);
    }

    public boolean removeParticipants(Team o) {
        return participants.remove(o);
    }

    public Team[] getParticipants() {
        return participants.toArray(Team[]::new);
    }

    public Team locateTeam(Golfer golfer) {
        for (Team participant : participants) {
            if (List.of(participant.getMembers()).contains(golfer)) {
                return participant;
            }
        }
        return null;
    }
}