From f37699b2a08c2c352bf55e0e9c311498179c7a6c Mon Sep 17 00:00:00 2001 From: JJtan <95962077+JJtan2002@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:10:24 +0800 Subject: [PATCH 1/2] Add Role field to Game --- .../java/seedu/address/model/game/Game.java | 41 +++++------ .../java/seedu/address/model/game/Role.java | 73 +++++++++++++++++++ 2 files changed, 90 insertions(+), 24 deletions(-) create mode 100644 src/main/java/seedu/address/model/game/Role.java diff --git a/src/main/java/seedu/address/model/game/Game.java b/src/main/java/seedu/address/model/game/Game.java index 3f236eb5f1b..e7c1fd5dc8b 100644 --- a/src/main/java/seedu/address/model/game/Game.java +++ b/src/main/java/seedu/address/model/game/Game.java @@ -21,44 +21,37 @@ public class Game { public final String gameName; public final Username username; public final SkillLevel skillLevel; + public final Role role; + /** - * Constructs a {@code Game} without a username. + * Constructs a {@code Game}. * * @param gameName A valid Game name. + * @param username (Optional) A username. + * @param skillLevel (Optional) A skill level. + * @param role (Optional) A role. */ - public Game(String gameName) { + public Game(String gameName, String username, String skillLevel, String role) { requireNonNull(gameName); checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS); this.gameName = gameName; - this.username = null; - this.skillLevel = null; + this.username = username != null ? new Username(username) : null; + this.skillLevel = skillLevel != null ? new SkillLevel(skillLevel) : null; + this.role = role != null ? new Role(role) : null; + } + + // Overloaded constructors for convenience + public Game(String gameName) { + this(gameName, null, null, null); } - /** - * Constructs a {@code Game} with a username. - * - * @param gameName A valid Game name. - */ public Game(String gameName, String username) { - requireNonNull(gameName); - checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS); - this.gameName = gameName; - this.username = new Username(username); - this.skillLevel = null; + this(gameName, username, null, null); } - /** - * Constructs a {@code Game} with a username. - * - * @param gameName A valid Game name. - */ public Game(String gameName, String username, String skillLevel) { - requireNonNull(gameName); - checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS); - this.gameName = gameName; - this.username = new Username(username); - this.skillLevel = new SkillLevel(skillLevel); + this(gameName, username, skillLevel, null); } /** diff --git a/src/main/java/seedu/address/model/game/Role.java b/src/main/java/seedu/address/model/game/Role.java new file mode 100644 index 00000000000..e1f77439c54 --- /dev/null +++ b/src/main/java/seedu/address/model/game/Role.java @@ -0,0 +1,73 @@ +package seedu.address.model.game; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Describes the Person's skill level in a Game. + */ +public class Role { + + private static final String MESSAGE_CONSTRAINTS = + "Skill Level should not be blank"; + + /* + * Regex expression matches Strings that contain at least one non-whitespace character. + */ + private static final String VALIDATION_REGEX = "^(?!\\s*$).+"; + + private final String role; + + /** + * Constructs a {@code Role}. + * + * @param role a valid skill level or rank. + */ + public Role(String role) { + requireNonNull(role); + checkArgument(isValidRole(role), MESSAGE_CONSTRAINTS); + this.role = role; + } + + /** + * Returns true if a given string is a valid Role. + */ + public static boolean isValidRole(String test) { + return test.matches(VALIDATION_REGEX); + } + + /** + * Getter for role field. + */ + public String getRole() { + return role; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Role)) { + return false; + } + + Role otherRole = (Role) other; + return role.equals(otherRole.role); + } + + @Override + public int hashCode() { + return role.hashCode(); + } + + /** + * Format state as text for viewing. + */ + public String toString() { + return role; + } + +} From b9b81c145cea36637b9fd2081b5622fa9608df23 Mon Sep 17 00:00:00 2001 From: JJtan <95962077+JJtan2002@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:30:41 +0800 Subject: [PATCH 2/2] Update Role.java --- src/main/java/seedu/address/model/game/Role.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/game/Role.java b/src/main/java/seedu/address/model/game/Role.java index e1f77439c54..c2513cbc099 100644 --- a/src/main/java/seedu/address/model/game/Role.java +++ b/src/main/java/seedu/address/model/game/Role.java @@ -9,7 +9,7 @@ public class Role { private static final String MESSAGE_CONSTRAINTS = - "Skill Level should not be blank"; + "Role should not be blank"; /* * Regex expression matches Strings that contain at least one non-whitespace character.