diff --git a/src/main/java/seedu/address/model/game/Game.java b/src/main/java/seedu/address/model/game/Game.java index dfac6d0e043..3f236eb5f1b 100644 --- a/src/main/java/seedu/address/model/game/Game.java +++ b/src/main/java/seedu/address/model/game/Game.java @@ -20,6 +20,7 @@ public class Game { public final String gameName; public final Username username; + public final SkillLevel skillLevel; /** * Constructs a {@code Game} without a username. @@ -31,6 +32,7 @@ public Game(String gameName) { checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS); this.gameName = gameName; this.username = null; + this.skillLevel = null; } /** @@ -43,6 +45,20 @@ public Game(String gameName, String username) { checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS); this.gameName = gameName; this.username = new Username(username); + this.skillLevel = 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); } /** diff --git a/src/main/java/seedu/address/model/game/SkillLevel.java b/src/main/java/seedu/address/model/game/SkillLevel.java new file mode 100644 index 00000000000..ee899199552 --- /dev/null +++ b/src/main/java/seedu/address/model/game/SkillLevel.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 SkillLevel { + + 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 skillLevel; + + /** + * Constructs a {@code SkillLevel}. + * + * @param skillLevel a valid skill level or rank. + */ + public SkillLevel(String skillLevel) { + requireNonNull(skillLevel); + checkArgument(isValidSkillLevel(skillLevel), MESSAGE_CONSTRAINTS); + this.skillLevel = skillLevel; + } + + /** + * Returns true if a given string is a valid SkillLevel. + */ + public static boolean isValidSkillLevel(String test) { + return test.matches(VALIDATION_REGEX); + } + + /** + * Getter for skillLevel field. + */ + public String getSkillLevel() { + return skillLevel; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof SkillLevel)) { + return false; + } + + SkillLevel otherName = (SkillLevel) other; + return skillLevel.equals(otherName.skillLevel); + } + + @Override + public int hashCode() { + return skillLevel.hashCode(); + } + + /** + * Format state as text for viewing. + */ + public String toString() { + return skillLevel; + } + +}