diff options
Diffstat (limited to 'src/main/java/design/model/Golfer.java')
| -rw-r--r-- | src/main/java/design/model/Golfer.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/main/java/design/model/Golfer.java b/src/main/java/design/model/Golfer.java index d34073f..48daae8 100644 --- a/src/main/java/design/model/Golfer.java +++ b/src/main/java/design/model/Golfer.java @@ -1,10 +1,12 @@ package design.model; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.util.ArrayList; import java.util.List; +@JsonPropertyOrder({ "clubs", "nextClubId" }) public class Golfer { private String username; private int passwordHash; @@ -12,7 +14,7 @@ public class Golfer { private final List<Course> courses; private final List<Round> rounds; private final List<Club> clubs; // Keep track of golfer's clubs - private int nextClubId = 1; + private int nextClubId; @JsonCreator private Golfer(String username, int passwordHash, String fullName, List<Course> courses, List<Round> rounds, @@ -72,6 +74,10 @@ public class Golfer { courses.remove(course); } + public boolean hasCourses() { + return !courses.isEmpty(); + } + public Round[] getRounds() { return rounds.toArray(Round[]::new); } @@ -86,6 +92,10 @@ public class Golfer { return c; } + public boolean hasClubs() { + return !clubs.isEmpty(); + } + public boolean hasClub(Club c) { return clubs.contains(c); } @@ -93,4 +103,13 @@ public class Golfer { public Club[] getClubs() { return clubs.toArray(Club[]::new); } + + @Override + public String toString() { + return String.format("%s (@%s)", fullName, username); + } + + public void removeClub(Club c) { + clubs.remove(c); + } } |
