diff options
Diffstat (limited to 'src/main/java/design/model')
| -rw-r--r-- | src/main/java/design/model/Club.java | 18 | ||||
| -rw-r--r-- | src/main/java/design/model/Golfer.java | 21 | ||||
| -rw-r--r-- | src/main/java/design/model/Invite.java | 25 | ||||
| -rw-r--r-- | src/main/java/design/model/League.java | 62 | ||||
| -rw-r--r-- | src/main/java/design/model/Match.java | 57 | ||||
| -rw-r--r-- | src/main/java/design/model/ScrambleLeague.java | 34 | ||||
| -rw-r--r-- | src/main/java/design/model/StrokeLeague.java | 34 | ||||
| -rw-r--r-- | src/main/java/design/model/Team.java | 40 |
8 files changed, 286 insertions, 5 deletions
diff --git a/src/main/java/design/model/Club.java b/src/main/java/design/model/Club.java index b12fd99..c19811c 100644 --- a/src/main/java/design/model/Club.java +++ b/src/main/java/design/model/Club.java @@ -1,5 +1,6 @@ package design.model; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.ObjectIdGenerators; @@ -21,18 +22,26 @@ public class Club { PUTTER } - private final int id; + private int id; private final String manufacture; private final String nickname; private final ClubType clubType; - public Club(int id, String manufacture, String nickname, ClubType clubType) { + @JsonCreator + private Club(int id, String manufacture, String nickname, ClubType clubType) { this.id = id; this.manufacture = manufacture; this.nickname = nickname; this.clubType = clubType; } + public Club(String manufacture, String nickname, ClubType clubType) { + this.id = -1; + this.manufacture = manufacture; + this.nickname = nickname; + this.clubType = clubType; + } + public int getId() { return id; } @@ -49,6 +58,11 @@ public class Club { return clubType; } + public void setId(int id) { + assert this.id == -1; + this.id = id; + } + @Override public String toString() { return String.format("#%d %s - %s (%s)", id, nickname, manufacture, clubType); diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index 48daae8..960568f 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -15,16 +15,18 @@ public class Golfer { private final List<Round> rounds; private final List<Club> clubs; // Keep track of golfer's clubs private int nextClubId; + private final List<Invite> invites; @JsonCreator private Golfer(String username, int passwordHash, String fullName, List<Course> courses, List<Round> rounds, - List<Club> clubs) { + List<Club> clubs, List<Invite> invites) { this.username = username; this.passwordHash = passwordHash; this.fullName = fullName; this.courses = courses; this.rounds = rounds; this.clubs = clubs; + this.invites = invites != null ? invites : new ArrayList<>(); this.nextClubId = this.clubs.stream().mapToInt(Club::getId).max().orElse(0) + 1; } @@ -35,6 +37,7 @@ public class Golfer { this.courses = new ArrayList<>(); this.rounds = new ArrayList<>(); this.clubs = new ArrayList<>(); + this.invites = new ArrayList<>(); this.nextClubId = 1; } @@ -86,8 +89,8 @@ public class Golfer { rounds.add(round); } - public Club addClub(String manufacture, String nickname, Club.ClubType type) { - Club c = new Club(nextClubId++, manufacture, nickname, type); + public Club addClub(Club c) { + c.setId(nextClubId++); clubs.add(c); return c; } @@ -112,4 +115,16 @@ public class Golfer { public void removeClub(Club c) { clubs.remove(c); } + + public boolean addInvite(Invite invite) { + return invites.add(invite); + } + + public boolean removeInvite(Invite o) { + return invites.remove(o); + } + + public Invite[] getInvites() { + return invites.toArray(Invite[]::new); + } } diff --git a/src/main/java/design/model/Invite.java b/src/main/java/design/model/Invite.java new file mode 100644 index 0000000..479f520 --- /dev/null +++ b/src/main/java/design/model/Invite.java @@ -0,0 +1,25 @@ +package design.model; + +import java.util.Date; + +public class Invite { + private final Team team; + private final Date sendDate; + + public Invite(Team team, Date sendDate) { + this.team = team; + this.sendDate = sendDate; + } + + public Team getTeam() { + return team; + } + + public Date getSendDate() { + return sendDate; + } + + public void accept(Golfer g) { + team.addMember(g); + } +} diff --git a/src/main/java/design/model/League.java b/src/main/java/design/model/League.java new file mode 100644 index 0000000..0252f89 --- /dev/null +++ b/src/main/java/design/model/League.java @@ -0,0 +1,62 @@ +package design.model; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.Date; + +public abstract class League { + private int id; + private final String name; + private final Date registrationDate; + private final Date startDate; + private final Date endDate; + private final Golfer owner; + + @JsonCreator + protected League(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { + this.id = id; + this.name = name; + this.registrationDate = registrationDate; + this.startDate = startDate; + this.endDate = endDate; + this.owner = owner; + } + + public League(String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { + this.id = -1; + this.name = name; + this.registrationDate = registrationDate; + this.startDate = startDate; + this.endDate = endDate; + this.owner = owner; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public Date getRegistrationDate() { + return registrationDate; + } + + public Date getStartDate() { + return startDate; + } + + public Date getEndDate() { + return endDate; + } + + public Golfer getOwner() { + return owner; + } + + public void setId(int id) { + assert this.id == -1; + this.id = id; + } +} diff --git a/src/main/java/design/model/Match.java b/src/main/java/design/model/Match.java new file mode 100644 index 0000000..4f01c98 --- /dev/null +++ b/src/main/java/design/model/Match.java @@ -0,0 +1,57 @@ +package design.model; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Match { + private final Course course; + private final Date dateScheduled; + private final LocalDateTime start; + private final int holeCount; + private final List<Round> rounds; + + @JsonCreator + private Match(Course course, Date dateScheduled, LocalDateTime start, int holeCount, List<Round> rounds) { + this.course = course; + this.dateScheduled = dateScheduled; + this.start = start; + this.holeCount = holeCount; + this.rounds = rounds; + } + + public Match(Course course, Date dateScheduled, LocalDateTime start, int holeCount) { + this.course = course; + this.dateScheduled = dateScheduled; + this.start = start; + this.holeCount = holeCount; + this.rounds = new ArrayList<>(); + } + + public Course getCourse() { + return course; + } + + public Date getDateScheduled() { + return dateScheduled; + } + + public LocalDateTime getStart() { + return start; + } + + public int getHoleCount() { + return holeCount; + } + + public boolean addRound(Round round) { + return rounds.add(round); + } + + public Round[] getRounds() { + return rounds.toArray(Round[]::new); + } +} diff --git a/src/main/java/design/model/ScrambleLeague.java b/src/main/java/design/model/ScrambleLeague.java new file mode 100644 index 0000000..7ff966e --- /dev/null +++ b/src/main/java/design/model/ScrambleLeague.java @@ -0,0 +1,34 @@ +package design.model; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +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) { + super(id, name, registrationDate, startDate, endDate, owner); + this.participants = participants; + } + + public ScrambleLeague(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { + super(id, 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); + } +} diff --git a/src/main/java/design/model/StrokeLeague.java b/src/main/java/design/model/StrokeLeague.java new file mode 100644 index 0000000..6bdde0a --- /dev/null +++ b/src/main/java/design/model/StrokeLeague.java @@ -0,0 +1,34 @@ +package design.model; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class StrokeLeague extends League { + private final List<Golfer> participants; + + @JsonCreator + private StrokeLeague(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner, List<Golfer> participants) { + super(id, name, registrationDate, startDate, endDate, owner); + this.participants = participants; + } + + public StrokeLeague(int id, String name, Date registrationDate, Date startDate, Date endDate, Golfer owner) { + super(id, name, registrationDate, startDate, endDate, owner); + this.participants = new ArrayList<>(); + } + + public boolean addParticipants(Golfer e) { + return participants.add(e); + } + + public boolean removeParticipants(Golfer o) { + return participants.remove(o); + } + + public Golfer[] getParticipants() { + return participants.toArray(Golfer[]::new); + } +} diff --git a/src/main/java/design/model/Team.java b/src/main/java/design/model/Team.java new file mode 100644 index 0000000..53b276e --- /dev/null +++ b/src/main/java/design/model/Team.java @@ -0,0 +1,40 @@ +package design.model; + +import java.util.ArrayList; +import java.util.List; + +public class Team { + private String name; + private final List<Golfer> members; + private final Golfer owner; + + public Team(String name, Golfer owner) { + this.name = name; + this.owner = owner; + this.members = new ArrayList<>(); + } + + public String getName() { + return name; + } + + public Golfer[] getMembers() { + return members.toArray(Golfer[]::new); + } + + public void setName(String name) { + this.name = name; + } + + public boolean addMember(Golfer golfer) { + return members.add(golfer); + } + + public boolean removeMember(Golfer g) { + return members.remove(g); + } + + public Golfer getOwner() { + return owner; + } +} |
