diff options
Diffstat (limited to 'src/main/java/design/model/League.java')
| -rw-r--r-- | src/main/java/design/model/League.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main/java/design/model/League.java b/src/main/java/design/model/League.java index 0252f89..881e25f 100644 --- a/src/main/java/design/model/League.java +++ b/src/main/java/design/model/League.java @@ -1,9 +1,22 @@ package design.model; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import java.util.ArrayList; import java.util.Date; +import java.util.List; +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ScrambleLeague.class, name = "scramble"), + @JsonSubTypes.Type(value = StrokeLeague.class, name = "stroke") +}) public abstract class League { private int id; private final String name; @@ -11,15 +24,17 @@ public abstract class League { private final Date startDate; private final Date endDate; private final Golfer owner; + private final List<Match> schedule; @JsonCreator - protected League(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { + protected League(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner, List<Match> schedule) { this.id = id; this.name = name; this.registrationDate = registrationDate; this.startDate = startDate; this.endDate = endDate; this.owner = owner; + this.schedule = schedule != null ? schedule : new ArrayList<>(); } public League(String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { @@ -29,6 +44,7 @@ public abstract class League { this.startDate = startDate; this.endDate = endDate; this.owner = owner; + this.schedule = new ArrayList<>(); } public int getId() { @@ -55,6 +71,18 @@ public abstract class League { return owner; } + public Match[] getSchedule() { + return schedule.toArray(Match[]::new); + } + + public void addMatchToSchedule(Match match) { + Date date = match.getDateScheduled(); + if(date.after(endDate)){ + throw new IllegalArgumentException("Cannot create match after league has ended"); + } + schedule.add(match); + } + public void setId(int id) { assert this.id == -1; this.id = id; |
