diff --git a/league_tracker.txt b/league_tracker.txt new file mode 100644 index 000000000..cdfb4b4f5 --- /dev/null +++ b/league_tracker.txt @@ -0,0 +1,29 @@ + + + + Lionel Messi + RW + 30 + 200 + 30 + 20 + FC Barcelona + Argentina + 10 + 54 + Healthy + + + Luis Suarez + Striker + 32 + 200 + 30 + 20 + FC Barcelona + Uruguay + 9 + 54 + Healthy + + diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index 296e3d027..83203792a 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -14,7 +14,7 @@ public class Main extends Application implements Stoppable { /** Version info of the program. */ - public static final String VERSION = "League Tracker - Version 1.2"; + public static final String VERSION = "League Tracker - Version 1.3 (first official release)"; private Gui gui; diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java deleted file mode 100644 index 563645bd7..000000000 --- a/src/seedu/addressbook/commands/AddCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -package seedu.addressbook.commands; - -import java.util.HashSet; -import java.util.Set; - -import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.player.Address; -import seedu.addressbook.data.player.Email; -import seedu.addressbook.data.player.Name; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.Phone; -import seedu.addressbook.data.player.ReadOnlyPerson; -import seedu.addressbook.data.player.UniquePersonList; -import seedu.addressbook.data.tag.Tag; - -/** - * Adds a player to the address book. - */ -public class AddCommand extends Command { - - public static final String COMMAND_WORD = "add"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Adds a player to the address book. " - + "Contact details can be marked private by prepending 'p' to the prefix.\n\t" - + "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n\t" - + "Example: " + COMMAND_WORD - + " John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; - - public static final String MESSAGE_SUCCESS = "New player added: %1$s"; - public static final String MESSAGE_DUPLICATE_PERSON = "This player already exists in the address book"; - - private final Person toAdd; - - /** - * Convenience constructor using raw values. - * - * @throws IllegalValueException if any of the raw values are invalid - */ - public AddCommand(String name, - String phone, boolean isPhonePrivate, - String email, boolean isEmailPrivate, - String address, boolean isAddressPrivate, - Set tags) throws IllegalValueException { - final Set tagSet = new HashSet<>(); - for (String tagName : tags) { - tagSet.add(new Tag(tagName)); - } - this.toAdd = new Person( - new Name(name), - new Phone(phone, isPhonePrivate), - new Email(email, isEmailPrivate), - new Address(address, isAddressPrivate), - tagSet - ); - } - - public AddCommand(Person toAdd) { - this.toAdd = toAdd; - } - - public ReadOnlyPerson getPerson() { - return toAdd; - } - - @Override - public CommandResult execute() { - try { - addressBook.addPerson(toAdd); - return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); - } catch (UniquePersonList.DuplicatePersonException dpe) { - return new CommandResult(MESSAGE_DUPLICATE_PERSON); - } - } - -} diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java deleted file mode 100644 index a54294be6..000000000 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package seedu.addressbook.commands; - -/** - * Clears the player list in address book. - */ -public class ClearCommand extends Command { - - public static final String COMMAND_WORD = "clear"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Clear persons in address book permanently.\n\t" - + "Example: " + COMMAND_WORD; - - public static final String MESSAGE_SUCCESS = "Person list has been cleared!"; - - @Override - public CommandResult execute() { - addressBook.clearPerson(); - return new CommandResult(MESSAGE_SUCCESS); - } -} diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index 9e8c12fe9..c77cdaa5c 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -8,15 +8,16 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.finance.ReadOnlyFinance; import seedu.addressbook.data.match.ReadOnlyMatch; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; import seedu.addressbook.data.team.ReadOnlyTeam; + /** * Represents an executable command. */ public abstract class Command { protected AddressBook addressBook; - protected List relevantPersons; + protected List relevantPlayers; protected List relevantMatches; protected List relevantTeams; protected List relevantFinances; @@ -34,13 +35,13 @@ protected Command() { } /** - * Constructs a feedback message to summarise an operation that displayed a listing of persons. + * Constructs a feedback message to summarise an operation that displayed a listing of players. * - * @param personsDisplayed used to generate summary + * @param playersDisplayed used to generate summary * @return summary message for persons displayed */ - public static String getMessageForPersonListShownSummary(List personsDisplayed) { - return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size()); + public static String getMessageForPlayerListShownSummary(List playersDisplayed) { + return String.format(Messages.MESSAGE_PLAYERS_LISTED_OVERVIEW, playersDisplayed.size()); } /** @@ -76,12 +77,12 @@ public CommandResult execute() { */ public void setData(AddressBook addressBook, - List relevantPersons, + List relevantPlayers, List relevantTeams, List relevantMatches, List relevantFinances) { this.addressBook = addressBook; - this.relevantPersons = relevantPersons; + this.relevantPlayers = relevantPlayers; this.relevantTeams = relevantTeams; this.relevantMatches = relevantMatches; this.relevantFinances = relevantFinances; @@ -92,8 +93,9 @@ public void setData(AddressBook addressBook, * * @throws IndexOutOfBoundsException if the target index is out of bounds of the last viewed listing */ - protected ReadOnlyPerson getTargetPerson() throws IndexOutOfBoundsException { - return relevantPersons.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET); + + protected ReadOnlyPlayer getTargetPlayer() throws IndexOutOfBoundsException { + return relevantPlayers.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET); } protected ReadOnlyMatch getTargetMatch() throws IndexOutOfBoundsException { diff --git a/src/seedu/addressbook/commands/CommandResult.java b/src/seedu/addressbook/commands/CommandResult.java index 0d357c8b3..f96342341 100644 --- a/src/seedu/addressbook/commands/CommandResult.java +++ b/src/seedu/addressbook/commands/CommandResult.java @@ -5,7 +5,7 @@ import seedu.addressbook.data.finance.ReadOnlyFinance; import seedu.addressbook.data.match.ReadOnlyMatch; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; import seedu.addressbook.data.team.ReadOnlyTeam; /** @@ -16,8 +16,8 @@ public class CommandResult { /** The feedback message to be shown to the user. Contains a description of the execution result */ public final String feedbackToUser; - /** The list of persons that was produced by the command */ - private final List relevantPersons; + /** The list of players that was produced by the command */ + private final List relevantPlayers; /** The list of teams that was produced by the command */ private final List relevantTeams; @@ -31,19 +31,19 @@ public class CommandResult { /** Constructor for result which do not return any list*/ public CommandResult(String feedbackToUser) { this.feedbackToUser = feedbackToUser; - relevantPersons = null; + relevantPlayers = null; relevantTeams = null; relevantMatches = null; relevantFinances = null; } public CommandResult(String feedbackToUser, - List relevantPersons, + List relevantPlayers, List relevantTeams, List relevantMatches, List relevantFinances) { this.feedbackToUser = feedbackToUser; - this.relevantPersons = relevantPersons; + this.relevantPlayers = relevantPlayers; this.relevantTeams = relevantTeams; this.relevantMatches = relevantMatches; this.relevantFinances = relevantFinances; @@ -53,8 +53,8 @@ public CommandResult(String feedbackToUser, /** * Returns list of persons relevant to the command command result, if any. */ - public Optional> getRelevantPersons() { - return Optional.ofNullable(relevantPersons); + public Optional> getRelevantPlayers() { + return Optional.ofNullable(relevantPlayers); } /** diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 599245313..a929215bf 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -7,6 +7,13 @@ import seedu.addressbook.commands.match.DeleteMatchCommand; import seedu.addressbook.commands.match.FindMatchCommand; import seedu.addressbook.commands.match.ListMatchCommand; +import seedu.addressbook.commands.player.AddCommand; +import seedu.addressbook.commands.player.ClearCommand; +import seedu.addressbook.commands.player.DeleteCommand; +import seedu.addressbook.commands.player.FindCommand; +import seedu.addressbook.commands.player.ListCommand; +import seedu.addressbook.commands.player.SortCommand; +import seedu.addressbook.commands.player.ViewAllCommand; import seedu.addressbook.commands.team.AddTeam; import seedu.addressbook.commands.team.ClearTeam; import seedu.addressbook.commands.team.DeleteTeam; @@ -36,7 +43,6 @@ public class HelpCommand extends Command { + "\n" + ClearTeam.MESSAGE_USAGE + "\n" + FindTeam.MESSAGE_USAGE + "\n" + ListTeam.MESSAGE_USAGE - + "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + FinanceCommand.MESSAGE_USAGE + "\n" + ListFinanceCommand.MESSAGE_USAGE diff --git a/src/seedu/addressbook/commands/ListCommand.java b/src/seedu/addressbook/commands/ListCommand.java deleted file mode 100644 index d07c95b94..000000000 --- a/src/seedu/addressbook/commands/ListCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package seedu.addressbook.commands; - -import java.util.List; - -import seedu.addressbook.data.player.ReadOnlyPerson; - -/** - * Lists all persons in the address book to the user. - */ -public class ListCommand extends Command { - - public static final String COMMAND_WORD = "list"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" - + "Displays all persons in the address book as a list with index numbers.\n\t" - + "Example: " + COMMAND_WORD; - - - @Override - public CommandResult execute() { - List allPersons = addressBook.getAllPersons().immutableListView(); - return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons, null, null, null); - } -} diff --git a/src/seedu/addressbook/commands/SortCommand.java b/src/seedu/addressbook/commands/SortCommand.java deleted file mode 100644 index 9c666ba28..000000000 --- a/src/seedu/addressbook/commands/SortCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package seedu.addressbook.commands; - -/** - * Sorts all persons in the address book to the user. - */ - -public class SortCommand extends Command { - - public static final String COMMAND_WORD = "sort"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" - + "Sorts all persons in the address book in ascending alphabetical order.\n\t" - + "Example: " + COMMAND_WORD; - - public static final String MESSAGE_SUCCESS = "Address book has been sorted!"; - - @Override - public CommandResult execute() { - addressBook.sort(); - return new CommandResult(MESSAGE_SUCCESS); - } -} - diff --git a/src/seedu/addressbook/commands/ViewCommand.java b/src/seedu/addressbook/commands/ViewCommand.java deleted file mode 100644 index 9014e437a..000000000 --- a/src/seedu/addressbook/commands/ViewCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package seedu.addressbook.commands; - -import seedu.addressbook.common.Messages; -import seedu.addressbook.data.player.ReadOnlyPerson; - - -/** - * Shows details of the player identified using the last displayed index. - * Private contact details are not shown. - */ -public class ViewCommand extends Command { - - public static final String COMMAND_WORD = "view"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Shows the non-private details of the player " - + "identified by the index number in the last shown player listing.\n\t" - + "Parameters: INDEX\n\t" - + "Example: " + COMMAND_WORD + " 1"; - - public static final String MESSAGE_VIEW_PERSON_DETAILS = "Viewing player: %1$s"; - - - public ViewCommand(int targetVisibleIndex) { - super(targetVisibleIndex); - } - - - @Override - public CommandResult execute() { - try { - final ReadOnlyPerson target = getTargetPerson(); - if (!addressBook.containsPerson(target)) { - return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); - } - return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextHidePrivate())); - } catch (IndexOutOfBoundsException ie) { - return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - } - } - -} diff --git a/src/seedu/addressbook/commands/match/DeleteMatchCommand.java b/src/seedu/addressbook/commands/match/DeleteMatchCommand.java index 417aaa194..e0300e224 100644 --- a/src/seedu/addressbook/commands/match/DeleteMatchCommand.java +++ b/src/seedu/addressbook/commands/match/DeleteMatchCommand.java @@ -37,7 +37,7 @@ public CommandResult execute() { } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_MATCH_DISPLAYED_INDEX); } catch (MatchNotFoundException mnfe) { - return new CommandResult(Messages.MESSAGE_MATCH_NOT_IN_ADDRESSBOOK); + return new CommandResult(Messages.MESSAGE_MATCH_NOT_IN_LEAGUE_TRACKER); } } diff --git a/src/seedu/addressbook/commands/player/AddCommand.java b/src/seedu/addressbook/commands/player/AddCommand.java new file mode 100644 index 000000000..9bb107fb1 --- /dev/null +++ b/src/seedu/addressbook/commands/player/AddCommand.java @@ -0,0 +1,105 @@ +package seedu.addressbook.commands.player; + +import java.util.HashSet; +import java.util.Set; + +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Appearance; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.GoalsAssisted; +import seedu.addressbook.data.player.GoalsScored; +import seedu.addressbook.data.player.HealthStatus; +import seedu.addressbook.data.player.JerseyNumber; +import seedu.addressbook.data.player.Name; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; +import seedu.addressbook.data.player.UniquePlayerList; +import seedu.addressbook.data.tag.Tag; + +/** + * Adds a player to the address book. + */ +public class AddCommand extends Command { + + public static final String COMMAND_WORD = "addPlayer"; + + public static final String MESSAGE_USAGE = + COMMAND_WORD + ":\n" + + "Adds a player to the League Tracker. " + + "\n" + + "Parameters:\n" + + "NAME p/POSITION \n" + + "a/AGE \n" + + "sal/SALARY \n" + + "gs/GOALS_SCORED \n" + + "ga/GOALS_ASSISTED \n" + + "tm/TEAM \n" + + "ctry/COUNTRY \n" + + "jn/JERSEY_NUMBER \n" + + "app/APPEARANCE \n" + + "hs/ HEALTH_STATUS \n" + + "[t/TAG]...\n\t" + + "Example: " + + COMMAND_WORD + + " Lionel Messi p/RW a/31 sal/20000000 gs/30 ga/25 tm/FC_BARCELONA ctry/Argentina jn/10" + + " app/40 hs/HEALTHY t/friends t/GREATEST_OF_ALL_TIME"; + + public static final String MESSAGE_SUCCESS = "New player added: %1$s"; + public static final String MESSAGE_DUPLICATE_PLAYER = "This player already exists in the address book"; + + private final Player toAdd; + + /** + * Convenience constructor using raw values. + * + * @throws IllegalValueException if any of the raw values are invalid + */ + + public AddCommand(String name, String position, String age, String salary, String goalsScored, String goalsAssisted, + String team, String country, String jerseyNumber, String appearance, String healthStatus, + Set tags) throws IllegalValueException { + final Set tagSet = new HashSet<>(); + for (String tagName : tags) { + tagSet.add(new Tag(tagName)); + } + this.toAdd = new Player( + new Name(name), + new PositionPlayed(position), + new Age(age), + new Salary(salary), + new GoalsScored(goalsScored), + new GoalsAssisted(goalsAssisted), + new Team(team), + new Country(country), + new JerseyNumber(jerseyNumber), + new Appearance(appearance), + new HealthStatus(healthStatus), + tagSet + ); + } + + public AddCommand(Player toAdd) { + this.toAdd = toAdd; + } + + public ReadOnlyPlayer getPlayer() { + return toAdd; + } + + @Override + public CommandResult execute() { + try { + addressBook.addPlayer(toAdd); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); + } catch (UniquePlayerList.DuplicatePlayerException dpe) { + return new CommandResult(MESSAGE_DUPLICATE_PLAYER); + } + } + +} diff --git a/src/seedu/addressbook/commands/player/AddFastCommand.java b/src/seedu/addressbook/commands/player/AddFastCommand.java new file mode 100644 index 000000000..1ec124cec --- /dev/null +++ b/src/seedu/addressbook/commands/player/AddFastCommand.java @@ -0,0 +1,90 @@ +package seedu.addressbook.commands.player; + +import java.util.HashSet; +import java.util.Set; + +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.JerseyNumber; +import seedu.addressbook.data.player.Name; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; +import seedu.addressbook.data.player.UniquePlayerList; +import seedu.addressbook.data.tag.Tag; + +/** + * Adds a player to the address book. + * With some fields set as default to make adding more user friendly + */ +public class AddFastCommand extends Command { + + public static final String COMMAND_WORD = "addFast"; + + public static final String MESSAGE_USAGE = + COMMAND_WORD + ":\n" + "Adds a player to the League Tracker. " + "\n" + + "Parameters:\n" + + "NAME p/POSITION \n" + + "a/AGE \n" + + "sal/SALARY \n" + + "tm/TEAM \n" + + "ctry/COUNTRY \n" + + "jn/JERSEY_NUMBER \n" + + "[t/TAG]...\n\t" + + "Example: " + + COMMAND_WORD + + " Lionel Messi p/RW a/31 sal/20000000 tm/FC_BARCELONA ctry/Argentina jn/10" + + " t/friends t/GREATEST_OF_ALL_TIME"; + + public static final String MESSAGE_SUCCESS = "New player added: %1$s"; + public static final String MESSAGE_DUPLICATE_PLAYER = "This player already exists in the address book"; + + private final Player toAdd; + + /** + * Convenience constructor using raw values. + * + * @throws IllegalValueException if any of the raw values are invalid + */ + public AddFastCommand(String name, String position, String age, String salary, + String team, String country, String jerseyNumber, + Set tags) throws IllegalValueException { + final Set tagSet = new HashSet<>(); + for (String tagName : tags) { + tagSet.add(new Tag(tagName)); + } + this.toAdd = new Player( + new Name(name), + new PositionPlayed(position), + new Age(age), + new Salary(salary), + new Team(team), + new Country(country), + new JerseyNumber(jerseyNumber), + tagSet + ); + } + + public AddFastCommand(Player toAdd) { + this.toAdd = toAdd; + } + + public ReadOnlyPlayer getPlayer() { + return toAdd; + } + + @Override + public CommandResult execute() { + try { + addressBook.addPlayer(toAdd); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); + } catch (UniquePlayerList.DuplicatePlayerException dpe) { + return new CommandResult(MESSAGE_DUPLICATE_PLAYER); + } + } +} diff --git a/src/seedu/addressbook/commands/player/ClearCommand.java b/src/seedu/addressbook/commands/player/ClearCommand.java new file mode 100644 index 000000000..1613fa633 --- /dev/null +++ b/src/seedu/addressbook/commands/player/ClearCommand.java @@ -0,0 +1,22 @@ +package seedu.addressbook.commands.player; + +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; + +/** + * Clears the player list in league tracker. + */ +public class ClearCommand extends Command { + + public static final String COMMAND_WORD = "clear"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Clear players in league tracker permanently.\n\t" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_SUCCESS = "League Tracker has been cleared!"; + + @Override + public CommandResult execute() { + addressBook.clearPlayer(); + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/player/DeleteCommand.java similarity index 53% rename from src/seedu/addressbook/commands/DeleteCommand.java rename to src/seedu/addressbook/commands/player/DeleteCommand.java index 932ed10d1..b99d23e2c 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/player/DeleteCommand.java @@ -1,8 +1,10 @@ -package seedu.addressbook.commands; +package seedu.addressbook.commands.player; +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; import seedu.addressbook.common.Messages; -import seedu.addressbook.data.player.ReadOnlyPerson; -import seedu.addressbook.data.player.UniquePersonList.PersonNotFoundException; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.UniquePlayerList; /** @@ -17,7 +19,7 @@ public class DeleteCommand extends Command { + "Parameters: INDEX\n\t" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; + public static final String MESSAGE_DELETE_PLAYER_SUCCESS = "Deleted Player: %1$s"; public DeleteCommand(int targetVisibleIndex) { @@ -28,14 +30,14 @@ public DeleteCommand(int targetVisibleIndex) { @Override public CommandResult execute() { try { - final ReadOnlyPerson target = getTargetPerson(); - addressBook.removePerson(target); - return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, target)); + final ReadOnlyPlayer target = getTargetPlayer(); + addressBook.removePlayer(target); + return new CommandResult(String.format(MESSAGE_DELETE_PLAYER_SUCCESS, target)); } catch (IndexOutOfBoundsException ie) { - return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - } catch (PersonNotFoundException pnfe) { - return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); + return new CommandResult(Messages.MESSAGE_INVALID_PLAYER_DISPLAYED_INDEX); + } catch (UniquePlayerList.PlayerNotFoundException pnfe) { + return new CommandResult(Messages.MESSAGE_PLAYER_NOT_IN_LEAGUE); } } diff --git a/src/seedu/addressbook/commands/FindCommand.java b/src/seedu/addressbook/commands/player/FindCommand.java similarity index 53% rename from src/seedu/addressbook/commands/FindCommand.java rename to src/seedu/addressbook/commands/player/FindCommand.java index 3c6d68e6e..868dfd963 100644 --- a/src/seedu/addressbook/commands/FindCommand.java +++ b/src/seedu/addressbook/commands/player/FindCommand.java @@ -1,4 +1,4 @@ -package seedu.addressbook.commands; +package seedu.addressbook.commands.player; import java.util.ArrayList; import java.util.Collections; @@ -6,20 +6,22 @@ import java.util.List; import java.util.Set; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; +import seedu.addressbook.data.player.ReadOnlyPlayer; /** - * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Finds and lists all players in the league whose name contains any of the argument keywords. * Keyword matching is case sensitive. */ public class FindCommand extends Command { public static final String COMMAND_WORD = "find"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Finds all persons whose names contain any of " + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Finds all players whose names contain any of " + "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n\t" + "Parameters: KEYWORD [MORE_KEYWORDS]...\n\t" - + "Example: " + COMMAND_WORD + " alice bob charlie"; + + "Example: " + COMMAND_WORD + " Messi Ronaldo"; private final Set keywords; @@ -36,25 +38,26 @@ public Set getKeywords() { @Override public CommandResult execute() { - final List personsFound = getPersonsWithNameContainingAnyKeyword(keywords); - return new CommandResult(getMessageForPersonListShownSummary(personsFound), personsFound, null, null, null); + final List playersFound = getPlayersWithNameContainingAnyKeyword(keywords); + return new CommandResult(getMessageForPlayerListShownSummary(playersFound), playersFound, null, null, null); } /** - * Retrieve all persons in the address book whose names contain some of the specified keywords. + * Retrieve all players in the address book whose names contain some of the specified keywords. * * @param keywords for searching - * @return list of persons found + * @return list of players found */ - private List getPersonsWithNameContainingAnyKeyword(Set keywords) { - final List matchedPersons = new ArrayList<>(); - for (ReadOnlyPerson person : addressBook.getAllPersons()) { - final Set wordsInName = new HashSet<>(person.getName().getWordsInName()); + + private List getPlayersWithNameContainingAnyKeyword(Set keywords) { + final List matchedPlayers = new ArrayList<>(); + for (ReadOnlyPlayer player : addressBook.getAllPlayers()) { + final Set wordsInName = new HashSet<>(player.getName().getWordsInName()); if (!Collections.disjoint(wordsInName, keywords)) { - matchedPersons.add(person); + matchedPlayers.add(player); } } - return matchedPersons; + return matchedPlayers; } } diff --git a/src/seedu/addressbook/commands/player/ListCommand.java b/src/seedu/addressbook/commands/player/ListCommand.java new file mode 100644 index 000000000..2f48b3057 --- /dev/null +++ b/src/seedu/addressbook/commands/player/ListCommand.java @@ -0,0 +1,27 @@ +package seedu.addressbook.commands.player; + +import java.util.List; + +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; +import seedu.addressbook.data.player.ReadOnlyPlayer; + + +/** + * Lists all players in the league to the user. + */ +public class ListCommand extends Command { + + public static final String COMMAND_WORD = "list"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + + "Displays all players in the league as a list with index numbers.\n\t" + + "Example: " + COMMAND_WORD; + + + @Override + public CommandResult execute() { + List allPlayers = addressBook.getAllPlayers().immutableListView(); + return new CommandResult(getMessageForPlayerListShownSummary(allPlayers), allPlayers, null, null, null); + } +} diff --git a/src/seedu/addressbook/commands/player/SortCommand.java b/src/seedu/addressbook/commands/player/SortCommand.java new file mode 100644 index 000000000..2dc15744a --- /dev/null +++ b/src/seedu/addressbook/commands/player/SortCommand.java @@ -0,0 +1,26 @@ +package seedu.addressbook.commands.player; + +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; + +/** + * Sorts all players in the league tracker. + */ + +public class SortCommand extends Command { + + public static final String COMMAND_WORD = "sort"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + + "Sorts all players in the league tracker in ascending alphabetical order.\n\t" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_SUCCESS = "League player list has been sorted!"; + + @Override + public CommandResult execute() { + addressBook.sort(); + return new CommandResult(MESSAGE_SUCCESS); + } +} + diff --git a/src/seedu/addressbook/commands/ViewAllCommand.java b/src/seedu/addressbook/commands/player/ViewAllCommand.java similarity index 60% rename from src/seedu/addressbook/commands/ViewAllCommand.java rename to src/seedu/addressbook/commands/player/ViewAllCommand.java index 7dbbdee19..9ae5fc948 100644 --- a/src/seedu/addressbook/commands/ViewAllCommand.java +++ b/src/seedu/addressbook/commands/player/ViewAllCommand.java @@ -1,7 +1,9 @@ -package seedu.addressbook.commands; +package seedu.addressbook.commands.player; +import seedu.addressbook.commands.Command; +import seedu.addressbook.commands.CommandResult; import seedu.addressbook.common.Messages; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; /** @@ -17,7 +19,7 @@ public class ViewAllCommand extends Command { + "Parameters: INDEX\n\t" + "Example: " + COMMAND_WORD + " 1"; - public static final String MESSAGE_VIEW_PERSON_DETAILS = "Viewing player: %1$s"; + public static final String MESSAGE_VIEW_PLAYER_DETAILS = "Viewing player: %1$s"; public ViewAllCommand(int targetVisibleIndex) { @@ -28,13 +30,13 @@ public ViewAllCommand(int targetVisibleIndex) { @Override public CommandResult execute() { try { - final ReadOnlyPerson target = getTargetPerson(); - if (!addressBook.containsPerson(target)) { - return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); + final ReadOnlyPlayer target = getTargetPlayer(); + if (!addressBook.containsPlayer(target)) { + return new CommandResult(Messages.MESSAGE_PLAYER_NOT_IN_LEAGUE); } - return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowAll())); + return new CommandResult(String.format(MESSAGE_VIEW_PLAYER_DETAILS, target.getAsTextShowAll())); } catch (IndexOutOfBoundsException ie) { - return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + return new CommandResult(Messages.MESSAGE_INVALID_PLAYER_DISPLAYED_INDEX); } } } diff --git a/src/seedu/addressbook/commands/team/DeleteTeam.java b/src/seedu/addressbook/commands/team/DeleteTeam.java index 931f6a7bc..7c1dfbf7f 100644 --- a/src/seedu/addressbook/commands/team/DeleteTeam.java +++ b/src/seedu/addressbook/commands/team/DeleteTeam.java @@ -37,7 +37,7 @@ public CommandResult execute() { } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_TEAM_DISPLAYED_INDEX); } catch (UniqueTeamList.TeamNotFoundException tnfe) { - return new CommandResult(Messages.MESSAGE_TEAM_NOT_IN_ADDRESSBOOK); + return new CommandResult(Messages.MESSAGE_TEAM_NOT_IN_LEAGUE_TRACKER); } } } diff --git a/src/seedu/addressbook/commands/team/EditTeam.java b/src/seedu/addressbook/commands/team/EditTeam.java index ef5222339..84522d1ac 100644 --- a/src/seedu/addressbook/commands/team/EditTeam.java +++ b/src/seedu/addressbook/commands/team/EditTeam.java @@ -69,7 +69,7 @@ public CommandResult execute() { } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_TEAM_DISPLAYED_INDEX); } catch (UniqueTeamList.TeamNotFoundException tnfe) { - return new CommandResult(Messages.MESSAGE_TEAM_NOT_IN_ADDRESSBOOK); + return new CommandResult(Messages.MESSAGE_TEAM_NOT_IN_LEAGUE_TRACKER); } } diff --git a/src/seedu/addressbook/common/Messages.java b/src/seedu/addressbook/common/Messages.java index 0d2dc2d6b..db23d72f2 100644 --- a/src/seedu/addressbook/common/Messages.java +++ b/src/seedu/addressbook/common/Messages.java @@ -6,18 +6,18 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; - public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The player index provided is invalid"; - public static final String MESSAGE_PERSON_NOT_IN_ADDRESSBOOK = "Person could not be found in address book"; - public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; + public static final String MESSAGE_INVALID_PLAYER_DISPLAYED_INDEX = "The player index provided is invalid"; + public static final String MESSAGE_PLAYER_NOT_IN_LEAGUE = "Player could not be found in the league record"; + public static final String MESSAGE_PLAYERS_LISTED_OVERVIEW = "%1$d players listed!"; public static final String MESSAGE_INVALID_MATCH_DISPLAYED_INDEX = "The match index provided is invalid"; - public static final String MESSAGE_MATCH_NOT_IN_ADDRESSBOOK = "match could not be found in address book"; + public static final String MESSAGE_MATCH_NOT_IN_LEAGUE_TRACKER = "match could not be found"; public static final String MESSAGE_MATCHES_LISTED_OVERVIEW = "%1$d matches listed!"; public static final String MESSAGE_INVALID_TEAM_DISPLAYED_INDEX = "The team index provided is invalid"; - public static final String MESSAGE_TEAM_NOT_IN_ADDRESSBOOK = "team could not be found in address book"; + public static final String MESSAGE_TEAM_NOT_IN_LEAGUE_TRACKER = "team could not be found in league tracker"; public static final String MESSAGE_TEAMS_LISTED_OVERVIEW = "%1$d teams listed!"; public static final String MESSAGE_FINANCES_LISTED_OVERVIEW = "%1$d finances listed!"; public static final String MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE = "Launch command format: " - + "java seedu.addressbook.Main [STORAGE_FILE_PATH]"; + + "To start, type 'help' for a detailed instruction on using League Tracker"; public static final String MESSAGE_WELCOME = "Welcome to your League Tracker!"; public static final String MESSAGE_USING_STORAGE_FILE = "Using storage file : %1$s"; } diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index c5834ccff..158c5688b 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -7,12 +7,11 @@ import seedu.addressbook.data.match.UniqueMatchList; import seedu.addressbook.data.match.UniqueMatchList.DuplicateMatchException; import seedu.addressbook.data.match.UniqueMatchList.MatchNotFoundException; - -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.ReadOnlyPerson; -import seedu.addressbook.data.player.UniquePersonList; -import seedu.addressbook.data.player.UniquePersonList.DuplicatePersonException; -import seedu.addressbook.data.player.UniquePersonList.PersonNotFoundException; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.UniquePlayerList; +import seedu.addressbook.data.player.UniquePlayerList.DuplicatePlayerException; +import seedu.addressbook.data.player.UniquePlayerList.PlayerNotFoundException; import seedu.addressbook.data.team.ReadOnlyTeam; import seedu.addressbook.data.team.Team; import seedu.addressbook.data.team.UniqueTeamList; @@ -22,7 +21,7 @@ */ public class AddressBook { - private final UniquePersonList allPersons; + private final UniquePlayerList allPlayers; private final UniqueTeamList allTeams; private final UniqueMatchList allMatches; private final UniqueFinanceList allFinances; @@ -31,7 +30,7 @@ public class AddressBook { * Creates an empty address book. */ public AddressBook() { - allPersons = new UniquePersonList(); + allPlayers = new UniquePlayerList(); allMatches = new UniqueMatchList(); allTeams = new UniqueTeamList(); allFinances = new UniqueFinanceList(); @@ -40,14 +39,14 @@ public AddressBook() { /** * Constructs an address book with the given data. * - * @param persons external changes to this will not affect this address book + * @param players external changes to this will not affect this address book * @param matches external changes to this will not affect this address book */ - public AddressBook(UniquePersonList persons, + public AddressBook(UniquePlayerList players, UniqueTeamList teams, UniqueMatchList matches, UniqueFinanceList finances) { - this.allPersons = new UniquePersonList(persons); + this.allPlayers = new UniquePlayerList(players); this.allTeams = new UniqueTeamList(teams); this.allMatches = new UniqueMatchList(matches); this.allFinances = new UniqueFinanceList(finances); @@ -60,10 +59,10 @@ public static AddressBook empty() { /** * Adds a player to the address book. * - * @throws DuplicatePersonException if an equivalent player already exists. + * @throws DuplicatePlayerException if an equivalent player already exists. */ - public void addPerson(Person toAdd) throws DuplicatePersonException { - allPersons.add(toAdd); + public void addPlayer(Player toAdd) throws DuplicatePlayerException { + allPlayers.add(toAdd); } /** @@ -85,8 +84,8 @@ public void addMatch(Match toAdd) throws DuplicateMatchException { /** * Checks if an equivalent player exists in the address book. */ - public boolean containsPerson(ReadOnlyPerson key) { - return allPersons.contains(key); + public boolean containsPlayer(ReadOnlyPlayer key) { + return allPlayers.contains(key); } /** @@ -106,10 +105,10 @@ public boolean containsMatch(ReadOnlyMatch key) { /** * Removes the equivalent player from the address book. * - * @throws PersonNotFoundException if no such Person could be found. + * @throws PlayerNotFoundException if no such Player could be found. */ - public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException { - allPersons.remove(toRemove); + public void removePlayer(ReadOnlyPlayer toRemove) throws PlayerNotFoundException { + allPlayers.remove(toRemove); } /** @@ -139,14 +138,14 @@ public void removeTeam(ReadOnlyTeam toRemove) throws UniqueTeamList.TeamNotFound * Sorts all persons from the address book. */ public void sort() { - allPersons.sort(); + allPlayers.sort(); } /** * Clears all persons from the address book. */ - public void clearPerson() { - allPersons.clear(); + public void clearPlayer() { + allPlayers.clear(); } /** @@ -164,10 +163,10 @@ public void editTeam(ReadOnlyTeam toRemove, Team toReplace) throws UniqueTeamLis } /** - * Defensively copied UniquePersonList of all persons in the address book at the time of the call. + * Defensively copied UniquePlayerList of all players in the address book at the time of the call. */ - public UniquePersonList getAllPersons() { - return new UniquePersonList(allPersons); + public UniquePlayerList getAllPlayers() { + return new UniquePlayerList(allPlayers); } /** @@ -205,11 +204,11 @@ public void refreshFinance() throws UniqueFinanceList.DuplicateFinanceException public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof AddressBook // instanceof handles nulls - && this.allPersons.equals(((AddressBook) other).allPersons)); + && this.allPlayers.equals(((AddressBook) other).allPlayers)); } @Override public int hashCode() { - return allPersons.hashCode(); + return allPlayers.hashCode(); } } diff --git a/src/seedu/addressbook/data/match/Match.java b/src/seedu/addressbook/data/match/Match.java index fade27efd..fc544849a 100644 --- a/src/seedu/addressbook/data/match/Match.java +++ b/src/seedu/addressbook/data/match/Match.java @@ -4,7 +4,8 @@ import java.util.Objects; import java.util.Set; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; + /** * Represents a match in the address book. @@ -18,14 +19,14 @@ public class Match implements ReadOnlyMatch { private TicketSales homeSales; private TicketSales awaySales; - private final Set goalScorers = new HashSet<>(); - private final Set ownGoalScorers = new HashSet<>(); + private final Set goalScorers = new HashSet<>(); + private final Set ownGoalScorers = new HashSet<>(); /** * Assumption: Every field must be present and not null. */ public Match(Date date, Home home, Away away, TicketSales homeSales, TicketSales awaySales, - Set goalScorers, Set ownGoalScorers) { + Set goalScorers, Set ownGoalScorers) { this.date = date; this.home = home; this.away = away; @@ -69,24 +70,24 @@ public TicketSales getAwaySales() { } @Override - public Set getGoalScorers() { + public Set getGoalScorers() { return new HashSet<>(goalScorers); } @Override - public Set getOwnGoalScorers() { + public Set getOwnGoalScorers() { return new HashSet<>(ownGoalScorers); } /** * Replaces this match's goalScorers with the goalScorers in {@code replacement}. */ - public void setGoalScorers(Set replacement) { + public void setGoalScorers(Set replacement) { goalScorers.clear(); goalScorers.addAll(replacement); } - public void setOwnGoalScorers(Set replacement) { + public void setOwnGoalScorers(Set replacement) { ownGoalScorers.clear(); ownGoalScorers.addAll(replacement); } diff --git a/src/seedu/addressbook/data/match/ReadOnlyMatch.java b/src/seedu/addressbook/data/match/ReadOnlyMatch.java index 34546df41..1b63a2e5a 100644 --- a/src/seedu/addressbook/data/match/ReadOnlyMatch.java +++ b/src/seedu/addressbook/data/match/ReadOnlyMatch.java @@ -2,7 +2,8 @@ import java.util.Set; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; + /** * A read-only immutable interface for a match in the addressbook. @@ -24,9 +25,9 @@ public interface ReadOnlyMatch { * The returned {@code Set} is a deep copy of the internal {@code Set}, * changes on the returned list will not affect the match's internal tags. */ - Set getGoalScorers(); + Set getGoalScorers(); - Set getOwnGoalScorers(); + Set getOwnGoalScorers(); /** * Returns true if the values inside this object is same as those of the other @@ -61,14 +62,14 @@ default String getAsTextShowAll() { if (getGoalScorers().isEmpty()) { builder.append("none"); } - for (Person goalScorer : getGoalScorers()) { + for (Player goalScorer : getGoalScorers()) { builder.append(goalScorer); } builder.append(" Own Goals: "); if (getOwnGoalScorers().isEmpty()) { builder.append("none"); } - for (Person ownGoalScorer : getOwnGoalScorers()) { + for (Player ownGoalScorer : getOwnGoalScorers()) { builder.append(ownGoalScorer); } } diff --git a/src/seedu/addressbook/data/player/Age.java b/src/seedu/addressbook/data/player/Age.java index 522e1e6c9..eb1910153 100644 --- a/src/seedu/addressbook/data/player/Age.java +++ b/src/seedu/addressbook/data/player/Age.java @@ -4,33 +4,59 @@ /** * Represents a player's age in the address book. - * Guarantees: immutable; is valid as declared in {@link #isValidAge(int)} + * Guarantees: immutable; is valid as declared in {@link #isValidAge(String)} */ public class Age { - public static final int EXAMPLE = 20; - public static final String MESSAGE_AGE_CONSTRAINTS = "Age of a player must be an integer"; + public static final String EXAMPLE = "20"; + public static final String MESSAGE_AGE_CONSTRAINTS = "Age of a player must be an integer that is between 0 and 100"; + public static final String AGE_VALIDATION_REGEX = "\\d+"; + public final String value; - public final int fullAge; /** * Validates given age. * * @throws IllegalValueException if given age integer is invalid. */ - public Age (int age) throws IllegalValueException { + public Age (String age) throws IllegalValueException { + age = age.trim(); if (!isValidAge(age)) { throw new IllegalValueException(MESSAGE_AGE_CONSTRAINTS); } - this.fullAge = age; + this.value = age; } /** * Returns true if a given string is a valid age. */ - public static boolean isValidAge(int test) { - return (test > 0 && test < 100); + public static boolean isValidAge(String test) { + + try { + int temp = Integer.parseInt(test); + return (test.matches(AGE_VALIDATION_REGEX) && temp > 0 && temp < 100); + } catch (NumberFormatException nfe) { + return false; + } } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Age// instanceof handles nulls + && this.value.equals(((Age) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } + } diff --git a/src/seedu/addressbook/data/player/Appearance.java b/src/seedu/addressbook/data/player/Appearance.java index 6792f0f63..2e6d9bb36 100644 --- a/src/seedu/addressbook/data/player/Appearance.java +++ b/src/seedu/addressbook/data/player/Appearance.java @@ -8,28 +8,54 @@ public class Appearance { - public static final int EXAMPLE = 30; - public static final String MESSAGE_APPEARANCE_CONSTRAINTS = "No. of appearance of a player must be an integer"; + public static final String EXAMPLE = "30"; + public static final String MESSAGE_APPEARANCE_CONSTRAINTS = "No.of appearance must be a non-negative integer"; + public static final String APPEARANCE_VALIDATION_REGEX = "\\d+"; - public final int fullAppearance; + public final String value; /** * Validates given appearance number. * * @throws IllegalValueException if given Number of Appearance integer is invalid. */ - public Appearance (int appearance) throws IllegalValueException { + public Appearance (String appearance) throws IllegalValueException { + appearance = appearance.trim(); if (!isValidApp(appearance)) { throw new IllegalValueException(MESSAGE_APPEARANCE_CONSTRAINTS); } - this.fullAppearance = appearance; + this.value = appearance; } /** * Returns true if a given integer is a valid jersey number. */ - public static boolean isValidApp(int test) { - return (test > 0 && test < 35); + public static boolean isValidApp(String test) { + try { + int temp = Integer.parseInt(test); + return (test.matches(APPEARANCE_VALIDATION_REGEX) && temp >= 0); + } catch (NumberFormatException nfe) { + return false; + } } + + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Appearance // instanceof handles nulls + && this.value.equals(((Appearance) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } + } diff --git a/src/seedu/addressbook/data/player/Country.java b/src/seedu/addressbook/data/player/Country.java index a1a18bbec..dce0fb766 100644 --- a/src/seedu/addressbook/data/player/Country.java +++ b/src/seedu/addressbook/data/player/Country.java @@ -1,9 +1,74 @@ package seedu.addressbook.data.player; +import java.util.Arrays; +import java.util.List; + +import seedu.addressbook.data.exception.IllegalValueException; + + /** * Represents country of a player made in the address book. */ -public class Country { +public class Country implements Comparable { + public static final String EXAMPLE = "Spain"; + public static final String MESSAGE_COUNTRY_CONSTRAINTS = "Country name should be a string"; + public static final String COUNTRY_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + + public final String fullCountry; + + /** + * Validates given country name. + * + * @throws IllegalValueException if given country string is invalid. + */ + + public Country(String name) throws IllegalValueException { + name = name.trim(); + if (!isValidName(name)) { + throw new IllegalValueException(MESSAGE_COUNTRY_CONSTRAINTS); + } + this.fullCountry = name; + } + + + /** + * Returns true if a given string is a valid country name. + */ + public static boolean isValidName(String test) { + return test.matches(COUNTRY_VALIDATION_REGEX); + } + + /** + * Retrieves a listing of every word in the name, in order. + */ + public List getWordsInCountry() { + return Arrays.asList(fullCountry.split("\\s+")); + } + + @Override + public String toString() { + return fullCountry; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Country // instanceof handles nulls + && this.fullCountry.equals(((Country) other).fullCountry)); // state check + } + + @Override + public int hashCode() { + return fullCountry.hashCode(); + } + + @Override + public int compareTo (Country country) { + return this.fullCountry.compareToIgnoreCase(country.fullCountry); + } } + + + diff --git a/src/seedu/addressbook/data/player/GoalsAssisted.java b/src/seedu/addressbook/data/player/GoalsAssisted.java index 96b6a8cd6..5411a11c2 100644 --- a/src/seedu/addressbook/data/player/GoalsAssisted.java +++ b/src/seedu/addressbook/data/player/GoalsAssisted.java @@ -7,29 +7,53 @@ */ public class GoalsAssisted { - public static final int EXAMPLE = 10; - public static final String MESSAGE_GA_CONSTRAINTS = "No.of assists for a player must be an integer"; + public static final String EXAMPLE = "1"; + public static final String MESSAGE_GA_CONSTRAINTS = "No.of assists for a player must be a non-negative integer"; + public static final String GA_VALIDATION_REGEX = "\\d+"; + + public final String value; - public final int fullGa; /** * Validates given No. of assists. * * @throws IllegalValueException if given assist number integer is invalid. */ - public GoalsAssisted (int ga) throws IllegalValueException { + public GoalsAssisted (String ga) throws IllegalValueException { + ga = ga.trim(); if (!isValidGa(ga)) { throw new IllegalValueException(MESSAGE_GA_CONSTRAINTS); } - this.fullGa = ga; + this.value = ga; } /** * Returns true if a given integer is a valid goals assisted number. */ - public static boolean isValidGa(int test) { - return (test >= 0 && test < 100); + public static boolean isValidGa(String test) { + try { + int temp = Integer.parseInt(test); + return (test.matches(GA_VALIDATION_REGEX) && temp >= 0); + } catch (NumberFormatException nfe) { + return false; + } + } + + @Override + public String toString() { + return value; } + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof GoalsAssisted // instanceof handles nulls + && this.value.equals(((GoalsAssisted) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } } diff --git a/src/seedu/addressbook/data/player/GoalsScored.java b/src/seedu/addressbook/data/player/GoalsScored.java index 3e2fd421d..34d5398c6 100644 --- a/src/seedu/addressbook/data/player/GoalsScored.java +++ b/src/seedu/addressbook/data/player/GoalsScored.java @@ -7,28 +7,52 @@ */ public class GoalsScored { - public static final int EXAMPLE = 10; - public static final String MESSAGE_GS_CONSTRAINTS = "No.of goals scored for a player must be an integer"; + public static final String EXAMPLE = "1"; + public static final String MESSAGE_GS_CONSTRAINTS = "No.of goals scored must be a non-negative integer"; + public static final String GS_VALIDATION_REGEX = "\\d+"; + public final String value; - public final int fullGs; /** * Validates given goals scored. * * @throws IllegalValueException if given goals scored integer is invalid. */ - public GoalsScored (int gs) throws IllegalValueException { + public GoalsScored (String gs) throws IllegalValueException { + gs = gs.trim(); if (!isValidGs(gs)) { throw new IllegalValueException(MESSAGE_GS_CONSTRAINTS); } - this.fullGs = gs; + this.value = gs; } /** * Returns true if a given integer is a valid goals scored number. */ - public static boolean isValidGs(int test) { - return (test >= 0 && test < 100); + public static boolean isValidGs(String test) { + try { + int temp = Integer.parseInt(test); + return (test.matches(GS_VALIDATION_REGEX) && temp >= 0); + } catch (NumberFormatException nfe) { + return false; + } + + } + + @Override + public String toString() { + return value; } + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof GoalsScored // instanceof handles nulls + && this.value.equals(((GoalsScored) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } } diff --git a/src/seedu/addressbook/data/player/JerseyNumber.java b/src/seedu/addressbook/data/player/JerseyNumber.java index c0c06e388..104f45911 100644 --- a/src/seedu/addressbook/data/player/JerseyNumber.java +++ b/src/seedu/addressbook/data/player/JerseyNumber.java @@ -7,29 +7,53 @@ */ public class JerseyNumber { - public static final int EXAMPLE = 10; - public static final String MESSAGE_JN_CONSTRAINTS = "Jersey Number of a player must be an integer"; + public static final String EXAMPLE = "10"; + public static final String MESSAGE_JN_CONSTRAINTS = "Jersey Number of a player must be an integer between 1 and 35"; + public static final String JN_VALIDATION_REGEX = "\\d+"; + public final String value; - public final int fullJn; /** * Validates given jersey number. * * @throws IllegalValueException if given Jersey Number integer is invalid. */ - public JerseyNumber (int jn) throws IllegalValueException { + public JerseyNumber (String jn) throws IllegalValueException { + jn = jn.trim(); if (!isValidJn(jn)) { throw new IllegalValueException(MESSAGE_JN_CONSTRAINTS); } - this.fullJn = jn; + this.value = jn; } /** * Returns true if a given integer is a valid jersey number. */ - public static boolean isValidJn(int test) { - return (test > 0 && test < 35); + public static boolean isValidJn(String test) { + try { + int temp = Integer.parseInt(test); + return (test.matches(JN_VALIDATION_REGEX) && temp >= 1 && temp < 35); + } catch (NumberFormatException nfe) { + return false; + } + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof JerseyNumber // instanceof handles nulls + && this.value.equals(((JerseyNumber) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); } } diff --git a/src/seedu/addressbook/data/player/Name.java b/src/seedu/addressbook/data/player/Name.java index 781d907b3..2d02e43e1 100644 --- a/src/seedu/addressbook/data/player/Name.java +++ b/src/seedu/addressbook/data/player/Name.java @@ -22,6 +22,7 @@ public class Name implements Comparable { * * @throws IllegalValueException if given name string is invalid. */ + public Name(String name) throws IllegalValueException { name = name.trim(); if (!isValidName(name)) { diff --git a/src/seedu/addressbook/data/player/Person.java b/src/seedu/addressbook/data/player/Person.java deleted file mode 100644 index a18ef2d70..000000000 --- a/src/seedu/addressbook/data/player/Person.java +++ /dev/null @@ -1,90 +0,0 @@ -package seedu.addressbook.data.player; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import seedu.addressbook.data.tag.Tag; - -/** - * Represents a Person in the address book. - * Guarantees: details are present and not null, field values are validated. - */ -public class Person implements ReadOnlyPerson { - - private Name name; - private Phone phone; - private Email email; - private Address address; - - private final Set tags = new HashSet<>(); - /** - * Assumption: Every field must be present and not null. - */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - this.tags.addAll(tags); - } - - /** - * Copy constructor. - */ - public Person(ReadOnlyPerson source) { - this(source.getName(), source.getPhone(), source.getEmail(), source.getAddress(), source.getTags()); - } - - @Override - public Name getName() { - return name; - } - - @Override - public Phone getPhone() { - return phone; - } - - @Override - public Email getEmail() { - return email; - } - - @Override - public Address getAddress() { - return address; - } - - @Override - public Set getTags() { - return new HashSet<>(tags); - } - - /** - * Replaces this player's tags with the tags in {@code replacement}. - */ - public void setTags(Set replacement) { - tags.clear(); - tags.addAll(replacement); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof ReadOnlyPerson // instanceof handles nulls - && this.isSameStateAs((ReadOnlyPerson) other)); - } - - @Override - public int hashCode() { - // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); - } - - @Override - public String toString() { - return getAsTextShowAll(); - } - -} diff --git a/src/seedu/addressbook/data/player/Player.java b/src/seedu/addressbook/data/player/Player.java new file mode 100644 index 000000000..ef4b76b3f --- /dev/null +++ b/src/seedu/addressbook/data/player/Player.java @@ -0,0 +1,163 @@ +package seedu.addressbook.data.player; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.tag.Tag; + + +/** + * Represents a Person in the address book. + * Guarantees: details are present and not null, field values are validated. + */ +public class Player implements ReadOnlyPlayer { + + private Name name; + private PositionPlayed positionPlayed; + private Salary salary; + private Age age; + private GoalsScored goalsScored; + private GoalsAssisted goalsAssisted; + private Team team; + private Country country; + private JerseyNumber jerseyNumber; + private Appearance appearance; + private HealthStatus healthStatus; + + private final Set tags = new HashSet<>(); + + /** + * Assumption: Every field must be present and not null. + */ + + public Player(Name name, PositionPlayed positionPlayed, Age age, Salary salary, GoalsScored goalsScored, + GoalsAssisted goalsAssisted, Team team, Country country, JerseyNumber jerseyNumber, + Appearance appearance, HealthStatus healthStatus, Set tags) { + this.name = name; + this.positionPlayed = positionPlayed; + this.age = age; + this.salary = salary; + this.goalsScored = goalsScored; + this.goalsAssisted = goalsAssisted; + this.team = team; + this.country = country; + this.jerseyNumber = jerseyNumber; + this.appearance = appearance; + this.healthStatus = healthStatus; + + this.tags.addAll(tags); + } + + /** + * Copy constructor. + */ + public Player(ReadOnlyPlayer source) { + this(source.getName(), source.getPositionPlayed(), source.getAge(), source.getSalary(), + source.getGoalsScored(), source.getGoalsAssisted(), source.getTeam(), + source.getCountry(), source.getJerseyNumber(), source.getAppearance(), + source.getHealthStatus(), source.getTags()); + } + + /** + * User Default Constructor + * allow user to create a player with some attributes as default value + */ + + public Player(Name name, PositionPlayed positionPlayed, Age age, Salary salary, Team team, + Country country, JerseyNumber jerseyNumber, Set tags) throws IllegalValueException { + this(name, positionPlayed, age, salary, new GoalsScored("0"), + new GoalsAssisted("0"), team, country, jerseyNumber, new Appearance("0"), + new HealthStatus("Healthy"), tags); + } + + + @Override + public Name getName() { + return name; + } + + @Override + public PositionPlayed getPositionPlayed() { + return positionPlayed; + } + + @Override + public Salary getSalary() { + return salary; + } + + @Override + public Age getAge() { + return age; + } + + @Override + public GoalsScored getGoalsScored() { + return goalsScored; + } + + @Override + public GoalsAssisted getGoalsAssisted() { + return goalsAssisted; + } + + @Override + public Team getTeam() { + return team; + } + + @Override + public Country getCountry() { + return country; + } + + @Override + public JerseyNumber getJerseyNumber() { + return jerseyNumber; + } + + @Override + public Appearance getAppearance() { + return appearance; + } + + @Override + public HealthStatus getHealthStatus() { + return healthStatus; + } + + @Override + public Set getTags() { + return new HashSet<>(tags); + } + + /** + * Replaces this player's tags with the tags in {@code replacement}. + */ + public void setTags(Set replacement) { + tags.clear(); + tags.addAll(replacement); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReadOnlyPlayer // instanceof handles nulls + && this.isSameStateAs((ReadOnlyPlayer) other)); + } + + @Override + public int hashCode() { + // use this method for custom fields hashing instead of implementing your own + return Objects.hash(name, positionPlayed, age, salary, goalsScored, goalsAssisted, team, country, jerseyNumber, + appearance, healthStatus, tags); + } + + @Override + public String toString() { + return getAsTextShowAll(); + } + +} diff --git a/src/seedu/addressbook/data/player/PositionPlayed.java b/src/seedu/addressbook/data/player/PositionPlayed.java index 365b5cb6e..339d16208 100644 --- a/src/seedu/addressbook/data/player/PositionPlayed.java +++ b/src/seedu/addressbook/data/player/PositionPlayed.java @@ -11,19 +11,18 @@ public class PositionPlayed { public static final String EXAMPLE = "Midfielder"; public static final String MESSAGE_POSITIONPLAYED_CONSTRAINTS = "Position of a player" + "must be spaces or alphanumeric characters"; - public static final String POSITIONPLAYED_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + public static final String POSITIONPLAYED_VALIDATION_REGEX = ".+"; public final String fullPosition; - private boolean isPrivate; + /** * Validates given position. * * @throws IllegalValueException if given position string is invalid. */ - public PositionPlayed (String position, boolean isPrivate) throws IllegalValueException { - this.isPrivate = isPrivate; - + public PositionPlayed (String position) throws IllegalValueException { + position = position.trim(); if (!isValidPosition(position)) { throw new IllegalValueException(MESSAGE_POSITIONPLAYED_CONSTRAINTS); } @@ -36,8 +35,21 @@ public PositionPlayed (String position, boolean isPrivate) throws IllegalValueEx public static boolean isValidPosition(String test) { return test.matches(POSITIONPLAYED_VALIDATION_REGEX); } - public boolean isPrivate() { - return isPrivate; + @Override + public String toString() { + return fullPosition; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof PositionPlayed // instanceof handles nulls + && this.fullPosition.equals(((PositionPlayed) other).fullPosition)); // state check + } + + @Override + public int hashCode() { + return fullPosition.hashCode(); } } diff --git a/src/seedu/addressbook/data/player/ReadOnlyPerson.java b/src/seedu/addressbook/data/player/ReadOnlyPerson.java deleted file mode 100644 index 170fa32d7..000000000 --- a/src/seedu/addressbook/data/player/ReadOnlyPerson.java +++ /dev/null @@ -1,87 +0,0 @@ -package seedu.addressbook.data.player; - -import java.util.Set; - -import seedu.addressbook.data.tag.Tag; - -/** - * A read-only immutable interface for a Person in the addressbook. - * Implementations should guarantee: details are present and not null, field values are validated. - */ -public interface ReadOnlyPerson { - - Name getName(); - Phone getPhone(); - Email getEmail(); - Address getAddress(); - - /** - * The returned {@code Set} is a deep copy of the internal {@code Set}, - * changes on the returned list will not affect the player's internal tags. - */ - Set getTags(); - - /** - * Returns true if the values inside this object is same as those of the other - * (Note: interfaces cannot override .equals) - */ - default boolean isSameStateAs(ReadOnlyPerson other) { - return other == this // short circuit if same object - || (other != null // this is first to avoid NPE below - && other.getName().equals(this.getName()) // state checks here onwards - && other.getPhone().equals(this.getPhone()) - && other.getEmail().equals(this.getEmail()) - && other.getAddress().equals(this.getAddress())); - } - - /** - * Formats the player as text, showing all contact details. - */ - default String getAsTextShowAll() { - final StringBuilder builder = new StringBuilder(); - final String detailIsPrivate = "(private) "; - builder.append(getName()) - .append(" Phone: "); - if (getPhone().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getPhone()) - .append(" Email: "); - if (getEmail().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getEmail()) - .append(" Address: "); - if (getAddress().isPrivate()) { - builder.append(detailIsPrivate); - } - builder.append(getAddress()) - .append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); - } - return builder.toString(); - } - - /** - * Formats a player as text, showing only non-private contact details. - */ - default String getAsTextHidePrivate() { - final StringBuilder builder = new StringBuilder(); - builder.append(getName()); - if (!getPhone().isPrivate()) { - builder.append(" Phone: ").append(getPhone()); - } - if (!getEmail().isPrivate()) { - builder.append(" Email: ").append(getEmail()); - } - if (!getAddress().isPrivate()) { - builder.append(" Address: ").append(getAddress()); - } - builder.append(" Tags: "); - for (Tag tag : getTags()) { - builder.append(tag); - } - return builder.toString(); - } -} diff --git a/src/seedu/addressbook/data/player/ReadOnlyPlayer.java b/src/seedu/addressbook/data/player/ReadOnlyPlayer.java new file mode 100644 index 000000000..544dbfd46 --- /dev/null +++ b/src/seedu/addressbook/data/player/ReadOnlyPlayer.java @@ -0,0 +1,81 @@ +package seedu.addressbook.data.player; + +import java.util.Set; + +import seedu.addressbook.data.tag.Tag; + +/** + * A read-only immutable interface for a Player in a football league. + * Implementations should guarantee: details are present and not null, field values are validated. + */ +public interface ReadOnlyPlayer { + + Name getName(); + + PositionPlayed getPositionPlayed(); + + Salary getSalary(); + + Age getAge(); + + GoalsScored getGoalsScored(); + + GoalsAssisted getGoalsAssisted(); + + Team getTeam(); + + Country getCountry(); + + JerseyNumber getJerseyNumber(); + + Appearance getAppearance(); + + HealthStatus getHealthStatus(); + + /** + * The returned {@code Set} is a deep copy of the internal {@code Set}, + * changes on the returned list will not affect the player's internal tags. + */ + + Set getTags(); + + /** + * Returns true if the values inside this object is same as those of the other + * (Note: interfaces cannot override .equals) + */ + default boolean isSameStateAs(ReadOnlyPlayer other) { + return other == this // short circuit if same object + || (other != null // this is first to avoid NPE below + && other.getName().equals(this.getName()) // state checks here onwards + && other.getPositionPlayed().equals(this.getPositionPlayed()) + && other.getAge().equals(this.getAge()) + && other.getSalary().equals(this.getSalary()) + && other.getGoalsScored().equals(this.getGoalsScored()) + && other.getGoalsAssisted().equals(this.getGoalsAssisted()) + && other.getTeam().equals(this.getTeam()) + && other.getCountry().equals(this.getCountry()) + && other.getJerseyNumber().equals(this.getJerseyNumber()) + && other.getAppearance().equals(this.getAppearance()) + && other.getHealthStatus().equals(this.getHealthStatus())); + } + + /** + * Formats the player as text, showing all contact details. + */ + default String getAsTextShowAll() { + final StringBuilder builder = new StringBuilder(); + + builder.append("\n").append("Name: ").append(getName()).append(" | Position Played: ") + .append(getPositionPlayed()).append(" | Age: ").append(getAge()).append(" | Salary: ") + .append(getSalary()).append("\n").append("Goals scored: ").append(getGoalsScored()) + .append(" | Goals assisted: ").append(getGoalsAssisted()).append(" | Team: ") + .append(getTeam()).append(" | Country: ").append(getCountry()) + .append("\n").append("Jersey Number: ").append(getJerseyNumber()) + .append(" | Appearance: ").append(getAppearance()).append(" | HealthStatus: ") + .append(getHealthStatus()).append(" | Tags: "); + for (Tag tag : getTags()) { + builder.append(tag); + } + return builder.toString(); + } +} diff --git a/src/seedu/addressbook/data/player/Salary.java b/src/seedu/addressbook/data/player/Salary.java new file mode 100644 index 000000000..c62a8a62c --- /dev/null +++ b/src/seedu/addressbook/data/player/Salary.java @@ -0,0 +1,63 @@ +package seedu.addressbook.data.player; + +import seedu.addressbook.data.exception.IllegalValueException; + +/** + * Represents a Player's salary. + * Guarantees: immutable; is valid as declared in {@link #isValidSalary(String)} + */ +public class Salary { + + public static final String EXAMPLE = "100000"; + public static final String MESSAGE_SALARY_CONSTRAINTS = "Player salary should be a positive number"; + public static final String SALARY_VALIDATION_REGEX = "\\d+"; + + public final String value; + + + /** + * Validates given player salary. + * + * @throws IllegalValueException if given salary string is invalid. + */ + public Salary(String salary) throws IllegalValueException { + salary = salary.trim(); + if (!isValidSalary(salary)) { + throw new IllegalValueException(MESSAGE_SALARY_CONSTRAINTS); + } + this.value = salary; + } + + /** + * Checks if a given string is a valid player salary. + */ + public static boolean isValidSalary(String test) { + try { + int i = Integer.parseInt(test); + return (test.matches(SALARY_VALIDATION_REGEX) && i >= 0); + } catch (NumberFormatException nfe) { + return false; + } + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Salary // instanceof handles nulls + && this.value.equals(((Salary) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + +} + + diff --git a/src/seedu/addressbook/data/player/Team.java b/src/seedu/addressbook/data/player/Team.java index df56e8dde..6628b642f 100644 --- a/src/seedu/addressbook/data/player/Team.java +++ b/src/seedu/addressbook/data/player/Team.java @@ -11,8 +11,8 @@ public class Team { public static final String EXAMPLE = "FC Barcelona"; public static final String MESSAGE_TEAM_CONSTRAINTS = "Player's team names" - + "should be spaces or alphanumeric characters"; - public static final String TEAM_VALIDATION_REGEX = "[\\p{Alnum} ]+"; + + "can be anything.+"; + public static final String TEAM_VALIDATION_REGEX = ".+"; public final String fullTeam; diff --git a/src/seedu/addressbook/data/player/UniquePersonList.java b/src/seedu/addressbook/data/player/UniquePlayerList.java similarity index 51% rename from src/seedu/addressbook/data/player/UniquePersonList.java rename to src/seedu/addressbook/data/player/UniquePlayerList.java index 9d0266de8..ca133eb33 100644 --- a/src/seedu/addressbook/data/player/UniquePersonList.java +++ b/src/seedu/addressbook/data/player/UniquePlayerList.java @@ -12,18 +12,19 @@ import seedu.addressbook.data.exception.DuplicateDataException; /** - * A list of persons. Does not allow null elements or duplicates. + * A list of players. Does not allow null elements or duplicates. * - * @see Person#equals(Object) + * @see Player#equals(Object) */ -public class UniquePersonList implements Iterable { +public class UniquePlayerList implements Iterable { /** * Signals that an operation would have violated the 'no duplicates' property of the list. */ - public static class DuplicatePersonException extends DuplicateDataException { - protected DuplicatePersonException() { - super("Operation would result in duplicate persons"); + + public static class DuplicatePlayerException extends DuplicateDataException { + protected DuplicatePlayerException() { + super("Operation would result in duplicate players"); } } @@ -31,51 +32,55 @@ protected DuplicatePersonException() { * Signals that an operation targeting a specified player in the list would fail because * there is no such matching player in the list. */ - public static class PersonNotFoundException extends Exception {} - private final List internalList = new ArrayList<>(); + public static class PlayerNotFoundException extends Exception {} + + private final List internalList = new ArrayList<>(); /** * Constructs empty player list. */ - public UniquePersonList() {} + + public UniquePlayerList() {} /** - * Constructs a player list with the given persons. + * Constructs a player list with the given players. */ - public UniquePersonList(Person... persons) throws DuplicatePersonException { - final List initialTags = Arrays.asList(persons); + public UniquePlayerList(Player... players) throws DuplicatePlayerException { + final List initialTags = Arrays.asList(players); if (!Utils.elementsAreUnique(initialTags)) { - throw new DuplicatePersonException(); + throw new DuplicatePlayerException(); } internalList.addAll(initialTags); } /** * Constructs a list from the items in the given collection. - * @param persons a collection of persons - * @throws DuplicatePersonException if the {@code persons} contains duplicate persons + * @param players a collection of players + * @throws DuplicatePlayerException if the {@code players} contains duplicate players */ - public UniquePersonList(Collection persons) throws DuplicatePersonException { - if (!Utils.elementsAreUnique(persons)) { - throw new DuplicatePersonException(); + public UniquePlayerList(Collection players) throws DuplicatePlayerException { + if (!Utils.elementsAreUnique(players)) { + throw new DuplicatePlayerException(); } - internalList.addAll(persons); + internalList.addAll(players); } /** * Constructs a shallow copy of the list. */ - public UniquePersonList(UniquePersonList source) { + + public UniquePlayerList(UniquePlayerList source) { internalList.addAll(source.internalList); } /** - * Unmodifiable java List view with elements cast as immutable {@link ReadOnlyPerson}s. + * Unmodifiable java List view with elements cast as immutable {@link ReadOnlyPlayer}s. * For use with other methods/libraries. * Any changes to the internal list/elements are immediately visible in the returned list. */ - public List immutableListView() { + + public List immutableListView() { return Collections.unmodifiableList(internalList); } @@ -83,18 +88,18 @@ public List immutableListView() { /** * Checks if the list contains an equivalent player as the given argument. */ - public boolean contains(ReadOnlyPerson toCheck) { + public boolean contains(ReadOnlyPlayer toCheck) { return internalList.contains(toCheck); } /** * Adds a player to the list. * - * @throws DuplicatePersonException if the player to add is a duplicate of an existing player in the list. + * @throws DuplicatePlayerException if the player to add is a duplicate of an existing player in the list. */ - public void add(Person toAdd) throws DuplicatePersonException { + public void add(Player toAdd) throws DuplicatePlayerException { if (contains(toAdd)) { - throw new DuplicatePersonException(); + throw new DuplicatePlayerException(); } internalList.add(toAdd); } @@ -102,40 +107,41 @@ public void add(Person toAdd) throws DuplicatePersonException { /** * Removes the equivalent player from the list. * - * @throws PersonNotFoundException if no such player could be found in the list. + * @throws PlayerNotFoundException if no such player could be found in the list. */ - public void remove(ReadOnlyPerson toRemove) throws PersonNotFoundException { - final boolean personFoundAndDeleted = internalList.remove(toRemove); - if (!personFoundAndDeleted) { - throw new PersonNotFoundException(); + + public void remove(ReadOnlyPlayer toRemove) throws PlayerNotFoundException { + final boolean playerFoundAndDeleted = internalList.remove(toRemove); + if (!playerFoundAndDeleted) { + throw new PlayerNotFoundException(); } } /** - * Clears all persons in list. + * Clears all players in list. */ public void clear() { internalList.clear(); } /** - * Sort all persons in list by ascending alphabetical order. + * Sort all players in list by ascending alphabetical order. */ public void sort() { - Comparator customPersonCompare = Comparator.comparing(Person::getName); - Collections.sort(internalList, customPersonCompare); + Comparator customPlayerCompare = Comparator.comparing(Player::getName); + Collections.sort(internalList, customPlayerCompare); } @Override - public Iterator iterator() { + public Iterator iterator() { return internalList.iterator(); } @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof UniquePersonList // instanceof handles nulls - && this.internalList.equals(((UniquePersonList) other).internalList)); + || (other instanceof UniquePlayerList // instanceof handles nulls + && this.internalList.equals(((UniquePlayerList) other).internalList)); } @Override diff --git a/src/seedu/addressbook/data/team/ReadOnlyTeam.java b/src/seedu/addressbook/data/team/ReadOnlyTeam.java index aa8c0871c..3ce932e71 100644 --- a/src/seedu/addressbook/data/team/ReadOnlyTeam.java +++ b/src/seedu/addressbook/data/team/ReadOnlyTeam.java @@ -2,9 +2,10 @@ import java.util.Set; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; import seedu.addressbook.data.tag.Tag; + /** * A read-only immutable interface for a team in the league tracker. * Implementations should guarantee: details are present and not null, field values are validated. @@ -15,7 +16,7 @@ public interface ReadOnlyTeam { Name getName(); Country getCountry(); Sponsor getSponsor(); - Set getPlayers(); + Set getPlayers(); /** * changes on the returned list will not affect the team's internal tags. diff --git a/src/seedu/addressbook/data/team/Team.java b/src/seedu/addressbook/data/team/Team.java index 11e577e7f..ba37a1c77 100644 --- a/src/seedu/addressbook/data/team/Team.java +++ b/src/seedu/addressbook/data/team/Team.java @@ -4,9 +4,10 @@ import java.util.Objects; import java.util.Set; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; import seedu.addressbook.data.tag.Tag; + /** * Represents a team in the address book. * Guarantees: details are present and not null, field values are validated. @@ -17,12 +18,12 @@ public class Team implements ReadOnlyTeam { private Name name; private Country country; private Sponsor sponsor; - private final Set playerlist = new HashSet<>(); + private final Set playerlist = new HashSet<>(); private final Set tags = new HashSet<>(); /** * Assumption: Every field must be present and not null. */ - public Team(Name name, Country country, Sponsor sponsor, Set playerlist, Set tags) { + public Team(Name name, Country country, Sponsor sponsor, Set playerlist, Set tags) { this.name = name; this.country = country; this.sponsor = sponsor; @@ -38,7 +39,7 @@ public Team(ReadOnlyTeam source) { } @Override - public Set getPlayers() { + public Set getPlayers() { return new HashSet<>(playerlist); } @@ -70,7 +71,7 @@ public void setTags(Set replacement) { tags.addAll(replacement); } - public void setPlayers(Set replacement) { + public void setPlayers(Set replacement) { playerlist.clear(); playerlist.addAll(replacement); } diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index edb979d13..68b8d4027 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -9,7 +9,7 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.finance.ReadOnlyFinance; import seedu.addressbook.data.match.ReadOnlyMatch; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; import seedu.addressbook.data.team.ReadOnlyTeam; import seedu.addressbook.parser.Parser; import seedu.addressbook.storage.StorageFile; @@ -25,7 +25,7 @@ public class Logic { /** * The list of player shown to the user most recently. */ - private List lastPersonShownList = Collections.emptyList(); + private List lastPlayerShownList = Collections.emptyList(); /** * The list of match shown to the user most recently. @@ -75,8 +75,8 @@ public String getStorageFilePath() { /** * Unmodifiable view of the current last player list. */ - public List getLastPersonShownList() { - return Collections.unmodifiableList(lastPersonShownList); + public List getLastPlayerShownList() { + return Collections.unmodifiableList(lastPlayerShownList); } /** @@ -90,8 +90,8 @@ protected void setLastMatchList(List newList) { lastMatchList = newList; } - protected void setLastPersonShownList(List newList) { - lastPersonShownList = newList; + protected void setLastPlayerShownList(List newList) { + lastPlayerShownList = newList; } /** @@ -125,7 +125,7 @@ public CommandResult execute(String userCommandText) throws Exception { */ private CommandResult execute(Command command) throws Exception { command.setData(addressBook, - lastPersonShownList, + lastPlayerShownList, lastTeamShownList, lastMatchList, lastFinanceShownList); @@ -135,16 +135,16 @@ private CommandResult execute(Command command) throws Exception { } /** - * Updates the {@link #lastPersonShownList} if the result contains a list of Persons. + * Updates the {@link #lastPlayerShownList} if the result contains a list of Persons. * Updates the {@link #lastMatchList} if the result contains a list of Matches. */ private void recordResult(CommandResult result) { - final Optional> personList = result.getRelevantPersons(); + final Optional> playerList = result.getRelevantPlayers(); final Optional> teamList = result.getRelevantTeams(); final Optional> matchList = result.getRelevantMatches(); final Optional> financeList = result.getRelevantFinances(); - if (personList.isPresent()) { - lastPersonShownList = personList.get(); + if (playerList.isPresent()) { + lastPlayerShownList = playerList.get(); } else if (teamList.isPresent()) { lastTeamShownList = teamList.get(); } else if (matchList.isPresent()) { diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 1d3d740b0..85071a1c7 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -10,18 +10,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import seedu.addressbook.commands.AddCommand; -import seedu.addressbook.commands.ClearCommand; import seedu.addressbook.commands.Command; -import seedu.addressbook.commands.DeleteCommand; import seedu.addressbook.commands.ExitCommand; -import seedu.addressbook.commands.FindCommand; import seedu.addressbook.commands.HelpCommand; import seedu.addressbook.commands.IncorrectCommand; -import seedu.addressbook.commands.ListCommand; -import seedu.addressbook.commands.SortCommand; -import seedu.addressbook.commands.ViewAllCommand; -import seedu.addressbook.commands.ViewCommand; import seedu.addressbook.commands.finance.FinanceCommand; import seedu.addressbook.commands.finance.ListFinanceCommand; import seedu.addressbook.commands.match.AddMatchCommand; @@ -29,6 +21,14 @@ import seedu.addressbook.commands.match.DeleteMatchCommand; import seedu.addressbook.commands.match.FindMatchCommand; import seedu.addressbook.commands.match.ListMatchCommand; +import seedu.addressbook.commands.player.AddCommand; +import seedu.addressbook.commands.player.AddFastCommand; +import seedu.addressbook.commands.player.ClearCommand; +import seedu.addressbook.commands.player.DeleteCommand; +import seedu.addressbook.commands.player.FindCommand; +import seedu.addressbook.commands.player.ListCommand; +import seedu.addressbook.commands.player.SortCommand; +import seedu.addressbook.commands.player.ViewAllCommand; import seedu.addressbook.commands.team.AddTeam; import seedu.addressbook.commands.team.ClearTeam; import seedu.addressbook.commands.team.DeleteTeam; @@ -47,13 +47,30 @@ public class Parser { public static final Pattern KEYWORDS_ARGS_FORMAT = Pattern.compile("(?\\S+(?:\\s+\\S+)*)"); // one or more keywords separated by whitespace - public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes + public static final Pattern PLAYER_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" - + " (?p?)p/(?[^/]+)" - + " (?p?)e/(?[^/]+)" - + " (?p?)a/(?
[^/]+)" + + "p/(?[^/]+)" + + "a/(?[^/]+)" + + "sal/(?[^/]+)" + + "gs/(?[^/]+)" + + "ga/(?[^/]+)" + + "tm/(?[^/]+)" + + "ctry/(?[^/]+)" + + "jn/(?[^/]+)" + + "app/(?[^/]+)" + + "hs/(?[^/]+)" + "(?(?: t/[^/]+)*)"); // variable number of tags + public static final Pattern PLAYERFAST_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes + Pattern.compile("(?[^/]+)" + + "p/(?[^/]+)" + + "a/(?[^/]+)" + + "sal/(?[^/]+)" + + "tm/(?[^/]+)" + + "ctry/(?[^/]+)" + + "jn/(?[^/]+)" + + "(?(?: t/[^/]+)*)"); + public static final Pattern MATCH_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" + "h/(?[^/]+)" @@ -107,13 +124,16 @@ public Command parseCommand(String userInput) { final String arguments = matcher.group("arguments"); switch (commandWord) { case AddCommand.COMMAND_WORD: - return prepareAddPerson(arguments); + return prepareAddPlayer(arguments); + + case AddFastCommand.COMMAND_WORD: + return prepareAddFastPlayer(arguments); case AddTeam.COMMAND_WORD: return addTeam(arguments); case DeleteCommand.COMMAND_WORD: - return prepareDeletePerson(arguments); + return prepareDeletePlayer(arguments); case DeleteTeam.COMMAND_WORD: return delTeam(arguments); @@ -163,9 +183,6 @@ public Command parseCommand(String userInput) { case SortCommand.COMMAND_WORD: return new SortCommand(); - case ViewCommand.COMMAND_WORD: - return prepareView(arguments); - case ViewAllCommand.COMMAND_WORD: return prepareViewAll(arguments); @@ -173,6 +190,7 @@ public Command parseCommand(String userInput) { return new ExitCommand(); case HelpCommand.COMMAND_WORD: // Fallthrough + default: return new HelpCommand(); } @@ -205,8 +223,8 @@ private Command addTeam(String args) { * @param args full command args string * @return the prepared command */ - private Command prepareAddPerson(String args) { - final Matcher matcher = PERSON_DATA_ARGS_FORMAT.matcher(args.trim()); + private Command prepareAddPlayer(String args) { + final Matcher matcher = PLAYER_DATA_ARGS_FORMAT.matcher(args.trim()); // Validate arg string format if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); @@ -214,16 +232,46 @@ private Command prepareAddPerson(String args) { try { return new AddCommand( matcher.group("name"), + matcher.group("position"), + matcher.group("age"), + matcher.group("salary"), + matcher.group("goalsScored"), + matcher.group("goalsAssisted"), + matcher.group("team"), + matcher.group("country"), + matcher.group("jerseyNumber"), + matcher.group("appearance"), + matcher.group("healthStatus"), + getTagsFromArgs(matcher.group("tagArguments")) + ); - matcher.group("phone"), - isPrivatePrefixPresent(matcher.group("isPhonePrivate")), - - matcher.group("email"), - isPrivatePrefixPresent(matcher.group("isEmailPrivate")), + } catch (IllegalValueException ive) { + return new IncorrectCommand(ive.getMessage()); + } + } - matcher.group("address"), - isPrivatePrefixPresent(matcher.group("isAddressPrivate")), + /** + * Parses arguments in the context of the addFast player command. + * + * @param args full command args string + * @return the prepared command + */ + private Command prepareAddFastPlayer(String args) { + final Matcher matcher = PLAYERFAST_DATA_ARGS_FORMAT.matcher(args.trim()); + // Validate arg string format + if (!matcher.matches()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddFastCommand.MESSAGE_USAGE)); + } + try { + return new AddFastCommand( + matcher.group("name"), + matcher.group("position"), + matcher.group("age"), + matcher.group("salary"), + matcher.group("team"), + matcher.group("country"), + matcher.group("jerseyNumber"), getTagsFromArgs(matcher.group("tagArguments")) ); } catch (IllegalValueException ive) { @@ -231,8 +279,9 @@ private Command prepareAddPerson(String args) { } } + /** - * Parses arguments in the context of the add player command. + * Parses arguments in the context of the add match command. * * @param args full command args string * @return the prepared command @@ -254,18 +303,19 @@ private Command prepareAddMatch(String args) { } } - /** - * Checks whether the private prefix of a contact detail in the add command's arguments string is present. - */ - private static boolean isPrivatePrefixPresent(String matchedPrefix) { - return matchedPrefix.equals("p"); - } + // /** + // * Checks whether the private prefix of a contact detail in the add command's arguments string is present. + // */ + // private static boolean isPrivatePrefixPresent(String matchedPrefix) { + // return matchedPrefix.equals("p"); + // } /** * Extracts the new player's tags from the add command's tag arguments string. * Extracts the new team's tags from the addTeam command's tag arguments string. * Merges duplicate tag strings. */ + private static Set getTagsFromArgs(String tagArguments) throws IllegalValueException { // no tags if (tagArguments.isEmpty()) { @@ -283,7 +333,7 @@ private static Set getTagsFromArgs(String tagArguments) throws IllegalVa * @param args full command args string * @return the prepared command */ - private Command prepareDeletePerson(String args) { + private Command prepareDeletePlayer(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); return new DeleteCommand(targetIndex); @@ -373,22 +423,6 @@ private Command prepareEditTeam(String args) { } } - /** - * Parses arguments in the context of the view command. - * - * @param args full command args string - * @return the prepared command - */ - private Command prepareView(String args) { - - try { - final int targetIndex = parseArgsAsDisplayedIndex(args); - return new ViewCommand(targetIndex); - } catch (ParseException | NumberFormatException e) { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - ViewCommand.MESSAGE_USAGE)); - } - } /** * Parses arguments in the context of the view all command. diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 85fc925c5..967ba78f8 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -27,7 +27,7 @@ public class StorageFile { /** Default file path used if the user doesn't provide the file name. */ - public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt"; + public static final String DEFAULT_STORAGE_FILEPATH = "league_tracker.txt"; /* Note: Note the use of nested classes below. * More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java b/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java index 026d45dd0..70f07d32d 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedAddressBook.java @@ -12,11 +12,12 @@ import seedu.addressbook.data.finance.UniqueFinanceList; import seedu.addressbook.data.match.Match; import seedu.addressbook.data.match.UniqueMatchList; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.UniquePersonList; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.UniquePlayerList; import seedu.addressbook.data.team.Team; import seedu.addressbook.data.team.UniqueTeamList; + /** * JAXB-friendly adapted address book data holder class. */ @@ -24,7 +25,7 @@ public class AdaptedAddressBook { @XmlElement - private List persons = new ArrayList<>(); + private List players = new ArrayList<>(); @XmlElement private List teams = new ArrayList<>(); @@ -44,10 +45,10 @@ public AdaptedAddressBook() {} * @param source future changes to this will not affect the created AdaptedAddressBook */ public AdaptedAddressBook(AddressBook source) { - persons = new ArrayList<>(); + players = new ArrayList<>(); matches = new ArrayList<>(); - source.getAllPersons().forEach(person -> persons.add(new AdaptedPerson(person))); + source.getAllPlayers().forEach(player -> players.add(new AdaptedPlayer(player))); source.getAllMatches().forEach(match -> matches.add(new AdaptedMatch(match))); source.getAllTeams().forEach(team -> teams.add(new AdaptedTeam(team))); @@ -63,7 +64,7 @@ public AdaptedAddressBook(AddressBook source) { * so we check for that. */ public boolean isAnyRequiredFieldMissing() { - return persons.stream().anyMatch(AdaptedPerson::isAnyRequiredFieldMissing) + return players.stream().anyMatch(AdaptedPlayer::isAnyRequiredFieldMissing) || matches.stream().anyMatch(AdaptedMatch::isAnyRequiredFieldMissing) || teams.stream().anyMatch(AdaptedTeam::isAnyRequiredFieldMissing); @@ -76,13 +77,13 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted match */ public AddressBook toModelType() throws IllegalValueException { - final List personList = new ArrayList<>(); + final List playerList = new ArrayList<>(); final List teamList = new ArrayList<>(); final List matchList = new ArrayList<>(); final List financeList = new ArrayList<>(); - for (AdaptedPerson person : persons) { - personList.add(person.toModelType()); + for (AdaptedPlayer player : players) { + playerList.add(player.toModelType()); } for (AdaptedTeam team : teams) { @@ -93,10 +94,8 @@ public AddressBook toModelType() throws IllegalValueException { matchList.add(match.toModelType()); } - - return new AddressBook( - new UniquePersonList(personList), + new UniquePlayerList(playerList), new UniqueTeamList(teamList), new UniqueMatchList(matchList), new UniqueFinanceList(financeList)); diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedMatch.java b/src/seedu/addressbook/storage/jaxb/AdaptedMatch.java index 4996d93d3..fe33305bd 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedMatch.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedMatch.java @@ -15,7 +15,7 @@ import seedu.addressbook.data.match.Match; import seedu.addressbook.data.match.ReadOnlyMatch; import seedu.addressbook.data.match.TicketSales; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; /** * JAXB-friendly adapted match data holder class. @@ -34,9 +34,9 @@ public class AdaptedMatch { @XmlElement (required = true) private String awaySales; @XmlElement - private List goalScored = new ArrayList<>(); + private List goalScored = new ArrayList<>(); @XmlElement - private List ownGoalScored = new ArrayList<>(); + private List ownGoalScored = new ArrayList<>(); /** * No-arg constructor for JAXB use. @@ -61,13 +61,13 @@ public AdaptedMatch(ReadOnlyMatch source) { awaySales = source.getAwaySales().value; goalScored = new ArrayList<>(); - for (Person person : source.getGoalScorers()) { - goalScored.add(new AdaptedPerson(person)); + for (Player player : source.getGoalScorers()) { + goalScored.add(new AdaptedPlayer(player)); } ownGoalScored = new ArrayList<>(); - for (Person person : source.getOwnGoalScorers()) { - ownGoalScored.add(new AdaptedPerson(person)); + for (Player player : source.getOwnGoalScorers()) { + ownGoalScored.add(new AdaptedPlayer(player)); } } @@ -80,13 +80,13 @@ public AdaptedMatch(ReadOnlyMatch source) { * so we check for that. */ public boolean isAnyRequiredFieldMissing() { - for (AdaptedPerson person : goalScored) { - if (person.isAnyRequiredFieldMissing()) { + for (AdaptedPlayer player : goalScored) { + if (player.isAnyRequiredFieldMissing()) { return true; } } - for (AdaptedPerson person : ownGoalScored) { - if (person.isAnyRequiredFieldMissing()) { + for (AdaptedPlayer player : ownGoalScored) { + if (player.isAnyRequiredFieldMissing()) { return true; } } @@ -100,13 +100,13 @@ public boolean isAnyRequiredFieldMissing() { * @throws IllegalValueException if there were any data constraints violated in the adapted match */ public Match toModelType() throws IllegalValueException { - final Set goalScorers = new HashSet<>(); - for (AdaptedPerson person : goalScored) { - goalScorers.add(person.toModelType()); + final Set goalScorers = new HashSet<>(); + for (AdaptedPlayer player : goalScored) { + goalScorers.add(player.toModelType()); } - final Set ownGoalScorers = new HashSet<>(); - for (AdaptedPerson person : ownGoalScored) { - ownGoalScorers.add(person.toModelType()); + final Set ownGoalScorers = new HashSet<>(); + for (AdaptedPlayer player : ownGoalScored) { + ownGoalScorers.add(player.toModelType()); } final Date date = new Date(this.date); final Home home = new Home(this.home); diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java b/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java deleted file mode 100644 index 2c47aacd5..000000000 --- a/src/seedu/addressbook/storage/jaxb/AdaptedPerson.java +++ /dev/null @@ -1,116 +0,0 @@ -package seedu.addressbook.storage.jaxb; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlValue; - -import seedu.addressbook.common.Utils; -import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.player.Address; -import seedu.addressbook.data.player.Email; -import seedu.addressbook.data.player.Name; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.Phone; -import seedu.addressbook.data.player.ReadOnlyPerson; -import seedu.addressbook.data.tag.Tag; - -/** - * JAXB-friendly adapted player data holder class. - */ -public class AdaptedPerson { - - /** - * JAXB-friendly place holder for information. - */ - private static class AdaptedContactDetail { - @XmlValue - private String value; - @XmlAttribute(required = true) - private boolean isPrivate; - } - - @XmlElement(required = true) - private String name; - @XmlElement(required = true) - private AdaptedContactDetail phone; - @XmlElement(required = true) - private AdaptedContactDetail email; - @XmlElement(required = true) - private AdaptedContactDetail address; - - @XmlElement - private List tagged = new ArrayList<>(); - - /** - * No-arg constructor for JAXB use. - */ - public AdaptedPerson() {} - - - /** - * Converts a given Person into this class for JAXB use. - * - * @param source future changes to this will not affect the created AdaptedPerson - */ - public AdaptedPerson(ReadOnlyPerson source) { - name = source.getName().fullName; - - phone = new AdaptedContactDetail(); - phone.isPrivate = source.getPhone().isPrivate(); - phone.value = source.getPhone().value; - - email = new AdaptedContactDetail(); - email.isPrivate = source.getEmail().isPrivate(); - email.value = source.getEmail().value; - - address = new AdaptedContactDetail(); - address.isPrivate = source.getAddress().isPrivate(); - address.value = source.getAddress().value; - - tagged = new ArrayList<>(); - for (Tag tag : source.getTags()) { - tagged.add(new AdaptedTag(tag)); - } - } - - /** - * Returns true if any required field is missing. - * - * JAXB does not enforce (required = true) without a given XML schema. - * Since we do most of our validation using the data class constructors, the only extra logic we need - * is to ensure that every xml element in the document is present. JAXB sets missing elements as null, - * so we check for that. - */ - public boolean isAnyRequiredFieldMissing() { - for (AdaptedTag tag : tagged) { - if (tag.isAnyRequiredFieldMissing()) { - return true; - } - } - // second call only happens if phone/email/address are all not null - return Utils.isAnyNull(name, phone, email, address) - || Utils.isAnyNull(phone.value, email.value, address.value); - } - - /** - * Converts this jaxb-friendly adapted player object into the Person object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted player - */ - public Person toModelType() throws IllegalValueException { - final Set tags = new HashSet<>(); - for (AdaptedTag tag : tagged) { - tags.add(tag.toModelType()); - } - final Name name = new Name(this.name); - final Phone phone = new Phone(this.phone.value, this.phone.isPrivate); - final Email email = new Email(this.email.value, this.email.isPrivate); - final Address address = new Address(this.address.value, this.address.isPrivate); - return new Person(name, phone, email, address, tags); - } -} diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedPlayer.java b/src/seedu/addressbook/storage/jaxb/AdaptedPlayer.java new file mode 100644 index 000000000..2e5d90061 --- /dev/null +++ b/src/seedu/addressbook/storage/jaxb/AdaptedPlayer.java @@ -0,0 +1,144 @@ +package seedu.addressbook.storage.jaxb; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElement; + +import seedu.addressbook.common.Utils; +import seedu.addressbook.data.exception.IllegalValueException; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Appearance; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.GoalsAssisted; +import seedu.addressbook.data.player.GoalsScored; +import seedu.addressbook.data.player.HealthStatus; +import seedu.addressbook.data.player.JerseyNumber; +import seedu.addressbook.data.player.Name; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; +import seedu.addressbook.data.tag.Tag; + +/** + * JAXB-friendly adapted player data holder class. + */ +public class AdaptedPlayer { + + /** + * JAXB-friendly place holder for information. + */ + // private static class AdaptedPlayerDetail { + // @XmlValue + // private String value; + // @XmlAttribute(required = true) + // private boolean isPrivate; + // } + + @XmlElement(required = true) + private String name; + @XmlElement(required = true) + private String position; + @XmlElement(required = true) + private String age; + @XmlElement(required = true) + private String salary; + @XmlElement(required = true) + private String goalsScored; + @XmlElement(required = true) + private String goalsAssisted; + @XmlElement(required = true) + private String team; + @XmlElement(required = true) + private String country; + @XmlElement(required = true) + private String jerseyNumber; + @XmlElement(required = true) + private String appearance; + @XmlElement(required = true) + private String healthStatus; + + @XmlElement + private List tagged = new ArrayList<>(); + + /** + * No-arg constructor for JAXB use. + */ + public AdaptedPlayer() { + } + + + /** + * Converts a given Person into this class for JAXB use. + * + * @param source future changes to this will not affect the created AdaptedPlayer + */ + public AdaptedPlayer(ReadOnlyPlayer source) { + name = source.getName().fullName; + position = source.getPositionPlayed().fullPosition; + age = source.getAge().value; + salary = source.getSalary().value; + goalsScored = source.getGoalsScored().value; + goalsAssisted = source.getGoalsAssisted().value; + team = source.getTeam().fullTeam; + country = source.getCountry().fullCountry; + jerseyNumber = source.getJerseyNumber().value; + appearance = source.getAppearance().value; + healthStatus = source.getHealthStatus().fullHs; + + tagged = new ArrayList<>(); + for (Tag tag : source.getTags()) { + tagged.add(new AdaptedTag(tag)); + } + } + + /** + * Returns true if any required field is missing. + *

+ * JAXB does not enforce (required = true) without a given XML schema. + * Since we do most of our validation using the data class constructors, the only extra logic we need + * is to ensure that every xml element in the document is present. JAXB sets missing elements as null, + * so we check for that. + */ + + public boolean isAnyRequiredFieldMissing() { + for (AdaptedTag tag : tagged) { + if (tag.isAnyRequiredFieldMissing()) { + return true; + } + } + // second call only happens if phone/email/address are all not null + return Utils.isAnyNull(name, position, age, salary, goalsScored, goalsAssisted, team, country, jerseyNumber, + appearance, healthStatus); + } + + /** + * Converts this jaxb-friendly adapted player object into the Player object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted player + */ + public Player toModelType() throws IllegalValueException { + final Set tags = new HashSet<>(); + for (AdaptedTag tag : tagged) { + tags.add(tag.toModelType()); + } + final Name name = new Name(this.name); + final PositionPlayed positionPlayed = new PositionPlayed(this.position); + final Age age = new Age(this.age); + final Salary salary = new Salary(this.salary); + final GoalsScored goalsScored = new GoalsScored(this.goalsScored); + final GoalsAssisted goalsAssisted = new GoalsAssisted(this.goalsAssisted); + final Team team = new Team(this.team); + final Country country = new Country(this.country); + final JerseyNumber jerseyNumber = new JerseyNumber(this.jerseyNumber); + final Appearance appearance = new Appearance(this.appearance); + final HealthStatus healthStatus = new HealthStatus(this.healthStatus); + + return new Player(name, positionPlayed, age, salary, goalsScored, goalsAssisted, + team, country, jerseyNumber, appearance, healthStatus, tags); + } +} diff --git a/src/seedu/addressbook/storage/jaxb/AdaptedTeam.java b/src/seedu/addressbook/storage/jaxb/AdaptedTeam.java index 553adf84f..360533b00 100644 --- a/src/seedu/addressbook/storage/jaxb/AdaptedTeam.java +++ b/src/seedu/addressbook/storage/jaxb/AdaptedTeam.java @@ -9,7 +9,7 @@ import seedu.addressbook.common.Utils; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.player.Person; +import seedu.addressbook.data.player.Player; import seedu.addressbook.data.tag.Tag; import seedu.addressbook.data.team.Country; import seedu.addressbook.data.team.Name; @@ -17,7 +17,6 @@ import seedu.addressbook.data.team.Sponsor; import seedu.addressbook.data.team.Team; - /** * JAXB-friendly adapted team data holder class. */ @@ -29,7 +28,7 @@ public class AdaptedTeam { @XmlElement(required = true) private String sponsor; @XmlElement - private List playerlist = new ArrayList<>(); + private List playerlist = new ArrayList<>(); @XmlElement private List tagged = new ArrayList<>(); @@ -48,8 +47,8 @@ public AdaptedTeam(ReadOnlyTeam source) { sponsor = source.getSponsor().toString(); playerlist = new ArrayList<>(); - for (Person person : source.getPlayers()) { - playerlist.add(new AdaptedPerson(person)); + for (Player player : source.getPlayers()) { + playerlist.add(new AdaptedPlayer(player)); } tagged = new ArrayList<>(); @@ -80,9 +79,9 @@ public boolean isAnyRequiredFieldMissing() { */ public Team toModelType() throws IllegalValueException { final Set tags = new HashSet<>(); - final Set players = new HashSet<>(); - for (AdaptedPerson person : playerlist) { - players.add(person.toModelType()); + final Set players = new HashSet<>(); + for (AdaptedPlayer player : playerlist) { + players.add(player.toModelType()); } for (AdaptedTag tag : tagged) { tags.add(tag.toModelType()); diff --git a/src/seedu/addressbook/ui/Formatter.java b/src/seedu/addressbook/ui/Formatter.java index 9d8b12419..5fa90d666 100644 --- a/src/seedu/addressbook/ui/Formatter.java +++ b/src/seedu/addressbook/ui/Formatter.java @@ -5,7 +5,7 @@ import seedu.addressbook.data.finance.ReadOnlyFinance; import seedu.addressbook.data.match.ReadOnlyMatch; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; import seedu.addressbook.data.team.ReadOnlyTeam; /** @@ -37,14 +37,15 @@ public String format(String... messages) { return sb.toString(); } - /** Formats the given list of persons for displaying to the user. */ - public String formatPersonResult(List persons) { + /** Formats the given list of players for displaying to the user. */ + public String formatPersonResult(List players) { final List formattedPersons = new ArrayList<>(); - for (ReadOnlyPerson person : persons) { - formattedPersons.add(person.getAsTextHidePrivate()); + for (ReadOnlyPlayer player : players) { + formattedPersons.add(player.getAsTextShowAll()); } return format(asIndexedList(formattedPersons)); } + /** Formats the given list of teams for displaying to the user. */ public String formatTeamResult(List teams) { final List formattedTeams = new ArrayList<>(); diff --git a/src/seedu/addressbook/ui/MainWindow.java b/src/seedu/addressbook/ui/MainWindow.java index 13e9eda7e..568740f18 100644 --- a/src/seedu/addressbook/ui/MainWindow.java +++ b/src/seedu/addressbook/ui/MainWindow.java @@ -16,11 +16,10 @@ import seedu.addressbook.commands.ExitCommand; import seedu.addressbook.data.finance.ReadOnlyFinance; import seedu.addressbook.data.match.ReadOnlyMatch; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.ReadOnlyPlayer; import seedu.addressbook.data.team.ReadOnlyTeam; import seedu.addressbook.logic.Logic; - /** * Main Window of the GUI. */ @@ -81,7 +80,7 @@ private void clearCommandInput() { commandInput.setText(""); } - /** Clears the output displayPersonResult area */ + /** Clears the output displayPlayerResult area */ public void clearOutputConsole() { outputConsole.clear(); } @@ -89,12 +88,12 @@ public void clearOutputConsole() { /** Displays the result of a command execution to the user. */ public void displayResult(CommandResult result) { clearOutputConsole(); - final Optional> resultPersons = result.getRelevantPersons(); + final Optional> resultPlayers = result.getRelevantPlayers(); final Optional> resultTeams = result.getRelevantTeams(); final Optional> resultMatches = result.getRelevantMatches(); final Optional> resultFinances = result.getRelevantFinances(); - if (resultPersons.isPresent()) { - displayPersonResult(resultPersons.get()); + if (resultPlayers.isPresent()) { + displayPlayerResult(resultPlayers.get()); } if (resultTeams.isPresent()) { displayTeamResult(resultTeams.get()); @@ -124,15 +123,15 @@ private void displayMatch(List matches) { } /** - * Displays the list of persons in the output displayPersonResult area, formatted as an indexed list. + * Displays the list of players in the output displayPlayerResult area, formatted as an indexed list. * Private contact details are hidden. */ - private void displayPersonResult(List persons) { - display(new Formatter().formatPersonResult(persons)); + private void displayPlayerResult(List players) { + display(new Formatter().formatPersonResult(players)); } /** - * Displays the list of teams in the output displayPersonResult area, formatted as an indexed list. + * Displays the list of teams in the output displayPlayerResult area, formatted as an indexed list. * Private contact details are hidden. */ private void displayTeamResult(List teams) { @@ -148,7 +147,7 @@ private void displayFinanceResult(List finances) { } /** - * Displays the given messages on the output displayPersonResult area, after formatting appropriately. + * Displays the given messages on the output displayPlayerResult area, after formatting appropriately. */ private void display(String... messages) { outputConsole.setText(outputConsole.getText() + new Formatter().format(messages)); diff --git a/test/data/StorageFileTest/InvalidData.txt b/test/data/StorageFileTest/InvalidData.txt index 91e8971a4..93f711dff 100644 --- a/test/data/StorageFileTest/InvalidData.txt +++ b/test/data/StorageFileTest/InvalidData.txt @@ -1,6 +1,6 @@ - + data - + diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.txt index fc6b00df6..cdfb4b4f5 100644 --- a/test/data/StorageFileTest/ValidData.txt +++ b/test/data/StorageFileTest/ValidData.txt @@ -1,17 +1,29 @@ - - John Doe - 98765432 - johnd@gmail.com -

John street, block 123, #01-01
- - - Betsy Crowe - 1234567 - betsycrowe@gmail.com -
Newgate Prison
- friend - criminal -
+ + Lionel Messi + RW + 30 + 200 + 30 + 20 + FC Barcelona + Argentina + 10 + 54 + Healthy + + + Luis Suarez + Striker + 32 + 200 + 30 + 20 + FC Barcelona + Uruguay + 9 + 54 + Healthy + diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index e084dcc49..a324e4d2d 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -16,24 +16,31 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import seedu.addressbook.commands.AddCommand; -import seedu.addressbook.commands.ClearCommand; import seedu.addressbook.commands.Command; import seedu.addressbook.commands.CommandResult; -import seedu.addressbook.commands.DeleteCommand; import seedu.addressbook.commands.ExitCommand; -import seedu.addressbook.commands.FindCommand; import seedu.addressbook.commands.HelpCommand; -import seedu.addressbook.commands.ViewAllCommand; -import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.player.AddCommand; +import seedu.addressbook.commands.player.AddFastCommand; +import seedu.addressbook.commands.player.ClearCommand; +import seedu.addressbook.commands.player.DeleteCommand; +import seedu.addressbook.commands.player.FindCommand; +import seedu.addressbook.commands.player.ViewAllCommand; import seedu.addressbook.common.Messages; import seedu.addressbook.data.AddressBook; -import seedu.addressbook.data.player.Address; -import seedu.addressbook.data.player.Email; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Appearance; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.GoalsAssisted; +import seedu.addressbook.data.player.GoalsScored; +import seedu.addressbook.data.player.HealthStatus; +import seedu.addressbook.data.player.JerseyNumber; import seedu.addressbook.data.player.Name; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.Phone; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; import seedu.addressbook.data.tag.Tag; import seedu.addressbook.storage.StorageFile; @@ -62,7 +69,7 @@ public void constructor() { //Constructor is called in the setup() method which executes before every test, no need to call it here again. //Confirm the last shown list is empty - assertEquals(Collections.emptyList(), logic.getLastPersonShownList()); + assertEquals(Collections.emptyList(), logic.getLastPlayerShownList()); } @Test @@ -75,6 +82,7 @@ public void execute_invalid() throws Exception { /** * Executes the command and confirms that the result message is correct. * Both the 'address book' and the 'last shown list' are expected to be empty. + * * @see #assertCommandBehavior(String, String, AddressBook, boolean, List) */ private void assertCommandBehavior(String inputCommand, String expectedMessage) throws Exception { @@ -84,36 +92,36 @@ private void assertCommandBehavior(String inputCommand, String expectedMessage) /** * Executes the command and confirms that the result message is correct and * also confirms that the following three parts of the Logic object's state are as expected:
- * - the internal address book data are same as those in the {@code expectedAddressBook}
- * - the internal 'last shown list' matches the {@code expectedLastList}
- * - the storage file content matches data in {@code expectedAddressBook}
+ * - the internal address book data are same as those in the {@code expectedAddressBook}
+ * - the internal 'last shown list' matches the {@code expectedLastList}
+ * - the storage file content matches data in {@code expectedAddressBook}
*/ private void assertCommandBehavior(String inputCommand, - String expectedMessage, - AddressBook expectedAddressBook, - boolean isRelevantPersonsExpected, - List lastPersonList) throws Exception { + String expectedMessage, + AddressBook expectedAddressBook, + boolean isRelevantPlayersExpected, + List lastPlayerList) throws Exception { //Execute the command CommandResult r = logic.execute(inputCommand); //Confirm the result contains the right data assertEquals(expectedMessage, r.feedbackToUser); - assertEquals(r.getRelevantPersons().isPresent(), isRelevantPersonsExpected); - if (isRelevantPersonsExpected) { - assertEquals(lastPersonList, r.getRelevantPersons().get()); + assertEquals(r.getRelevantPlayers().isPresent(), isRelevantPlayersExpected); + if (isRelevantPlayersExpected) { + assertEquals(lastPlayerList, r.getRelevantPlayers().get()); } //Confirm the state of data is as expected assertEquals(expectedAddressBook, addressBook); - assertEquals(lastPersonList, logic.getLastPersonShownList()); + assertEquals(lastPlayerList, logic.getLastPlayerShownList()); assertEquals(addressBook, saveFile.load()); } @Test public void execute_unknownCommandWord() throws Exception { - String unknownCommand = "uicfhmowqewca"; + String unknownCommand = "thisisnonsensebutyeahwhocares"; assertCommandBehavior(unknownCommand, HelpCommand.MESSAGE_ALL_USAGES); } @@ -130,10 +138,10 @@ public void execute_exit() throws Exception { @Test public void execute_clear() throws Exception { TestDataHelper helper = new TestDataHelper(); - addressBook.addPerson(helper.generatePerson(1, true)); - addressBook.addPerson(helper.generatePerson(2, true)); - addressBook.addPerson(helper.generatePerson(3, true)); - + addressBook.addPlayer(helper.generatePlayer(1)); + addressBook.addPlayer(helper.generatePlayer(2)); + addressBook.addPlayer(helper.generatePlayer(3)); + addressBook.addPlayer(helper.generatePlayer(4)); assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList()); } @@ -141,43 +149,148 @@ public void execute_clear() throws Exception { @Test public void execute_add_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); + + // anyhow argument + assertCommandBehavior( + "addPlayer wrong args wrong args", expectedMessage); + + //no position prefix + assertCommandBehavior( + "addPlayer Valid Name Striker a/30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoPositionPrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no age prefix assertCommandBehavior( - "add wrong args wrong args", expectedMessage); + "addPlayer Valid Name p/Striker 30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoAgePrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no salary prefix + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 20000 gs/0 " + + "ga/0 tm/validTeam.butNoSalaryPrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no goals scored prefix assertCommandBehavior( - "add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage); + "addPlayer Valid Name p/Striker a/30 sal/20000 0 " + + "ga/0 tm/validTeam.butNoGoalsScoredPrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no goals assisted prefix assertCommandBehavior( - "add Valid Name p/12345 valid@email.butNoPrefix a/valid, address", expectedMessage); + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "0 tm/validTeam.butNoGoalsAssistedPrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no team prefix assertCommandBehavior( - "add Valid Name p/12345 e/valid@email.butNoAddressPrefix valid, address", expectedMessage); + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "ga/0 validTeam.butNoPrefix ctry/China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no country prefix + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoCountryPrefix China " + + "jn/9 app/0 hs/Healthy", expectedMessage); + + //no jersey number prefix + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoJerseyNumberPrefix ctry/China " + + "9 app/0 hs/Healthy", expectedMessage); + + //no appearance prefix + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoAppearancePrefix ctry/China " + + "jn/9 0 hs/Healthy", expectedMessage); + + //no health status prefix + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 " + + "ga/0 tm/validTeam.butNoHealthStatusPrefix ctry/China " + + "jn/9 app/0 Healthy", expectedMessage); } @Test - public void execute_add_invalidPersonData() throws Exception { + public void execute_addFast_invalidArgsFormat() throws Exception { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddFastCommand.MESSAGE_USAGE); + assertCommandBehavior( - "add []\\[;] p/12345 e/valid@e.mail a/valid, address", Name.MESSAGE_NAME_CONSTRAINTS); + "addFast ValidName Striker a/30 sal/20000 tm/FC_NUS.butNoPositionPrefix ctry/Singapore jn/10", + expectedMessage); + assertCommandBehavior( - "add Valid Name p/not_numbers e/valid@e.mail a/valid, address", Phone.MESSAGE_PHONE_CONSTRAINTS); + "addFast ValidName p/Striker 30 sal/20000 tm/FC_NUS.butNoAgePrefix ctry/Singapore jn/10", + expectedMessage); + assertCommandBehavior( - "add Valid Name p/12345 e/notAnEmail a/valid, address", Email.MESSAGE_EMAIL_CONSTRAINTS); + "addFast ValidName p/Striker a/30 20000 tm/FC_NUS.butNoSalaryPrefix ctry/Singapore jn/10", + expectedMessage); + assertCommandBehavior( - "add Valid Name p/12345 e/valid@e.mail a/valid, address t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); + "addFast ValidName p/Striker a/30 sal/20000 FC_NUS.butNoPrefix ctry/Singapore jn/10", + expectedMessage); + assertCommandBehavior( + "addFast ValidName p/Striker a/30 sal/20000 tm/FC_NUS.butNoCountryPrefix Singapore jn/10", + expectedMessage); + + assertCommandBehavior( + "addFast ValidName p/Striker a/30 sal/20000 tm/FC_NUS.butNoJerseyNumberPrefix ctry/Singapore 10", + expectedMessage); + + } + + + @Test + public void execute_add_invalidPlayerData() throws Exception { + assertCommandBehavior( + "addPlayer []\\[;] p/Striker a/30 sal/20000 gs/0 ga/0 tm/validTeam ctry/China" + + "jn/9 app/0 hs/Healthy", Name.MESSAGE_NAME_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/thirty sal/20000 gs/0 ga/0 tm/validTeam ctry/China " + + "jn/9 app/0 hs/Healthy", Age.MESSAGE_AGE_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/zero gs/0 ga/0 tm/validTeam ctry/China " + + "jn/9 app/0 hs/Healthy", Salary.MESSAGE_SALARY_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/zero ga/0 tm/validTeam ctry/China " + + "jn/9 app/0 hs/Healthy", GoalsScored.MESSAGE_GS_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 ga/zero tm/validTeam ctry/China " + + "jn/9 app/0 hs/Healthy", GoalsAssisted.MESSAGE_GA_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 ga/0 tm/validTeam ctry/China " + + "jn/50 app/0 hs/Healthy", JerseyNumber.MESSAGE_JN_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 ga/0 tm/validTeam ctry/China " + + "jn/nine app/0 hs/Healthy", JerseyNumber.MESSAGE_JN_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 ga/0 tm/validTeam ctry/China " + + "jn/9 app/zero hs/Healthy", Appearance.MESSAGE_APPEARANCE_CONSTRAINTS); + assertCommandBehavior( + "addPlayer Valid Name p/Striker a/30 sal/20000 gs/0 ga/0 tm/validTeam ctry/China " + + "jn/9 app/0 hs/Healthy t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS); } @Test public void execute_add_successful() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Person toBeAdded = helper.adam(); + Player toBeAdded = helper.messi(); AddressBook expectedAb = new AddressBook(); - expectedAb.addPerson(toBeAdded); + expectedAb.addPlayer(toBeAdded); // execute command and verify result assertCommandBehavior(helper.generateAddCommand(toBeAdded), - String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded), - expectedAb, - false, - Collections.emptyList()); + String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded), + expectedAb, + false, + Collections.emptyList()); } @@ -185,17 +298,17 @@ public void execute_add_successful() throws Exception { public void execute_addDuplicate_notAllowed() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); - Person toBeAdded = helper.adam(); + Player toBeAdded = helper.messi(); AddressBook expectedAb = new AddressBook(); - expectedAb.addPerson(toBeAdded); + expectedAb.addPlayer(toBeAdded); // setup starting state - addressBook.addPerson(toBeAdded); // player already in internal address book + addressBook.addPlayer(toBeAdded); // player already in internal address book // execute command and verify result assertCommandBehavior( helper.generateAddCommand(toBeAdded), - AddCommand.MESSAGE_DUPLICATE_PERSON, + AddCommand.MESSAGE_DUPLICATE_PLAYER, expectedAb, false, Collections.emptyList()); @@ -206,92 +319,36 @@ public void execute_addDuplicate_notAllowed() throws Exception { public void execute_list_showsAllPersons() throws Exception { // prepare expectations TestDataHelper helper = new TestDataHelper(); - AddressBook expectedAb = helper.generateAddressBook(false, true); - List expectedList = expectedAb.getAllPersons().immutableListView(); + AddressBook expectedAb = helper.generateAddressBook(2); + List expectedList = expectedAb.getAllPlayers().immutableListView(); // prepare address book state - helper.addToAddressBook(addressBook, false, true); + helper.addToAddressBook(addressBook, 2); assertCommandBehavior("list", - Command.getMessageForPersonListShownSummary(expectedList), - expectedAb, - true, - expectedList); - } - - @Test - public void execute_view_invalidArgsFormat() throws Exception { - String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); - assertCommandBehavior("view ", expectedMessage); - assertCommandBehavior("view arg not number", expectedMessage); + Command.getMessageForPlayerListShownSummary(expectedList), + expectedAb, + true, + expectedList); } - @Test - public void execute_view_invalidIndex() throws Exception { - assertInvalidIndexBehaviorForCommand("view"); - } /** * Confirms the 'invalid argument index number behaviour' for the given command * targeting a single player in the last shown list, using visible index. + * * @param commandWord to test assuming it targets a single player in the last shown list based on visible index. */ private void assertInvalidIndexBehaviorForCommand(String commandWord) throws Exception { - String expectedMessage = Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; - TestDataHelper helper = new TestDataHelper(); - List lastPersonList = helper.generatePersonList(false, true); - - logic.setLastPersonShownList(lastPersonList); - - assertCommandBehavior(commandWord + " -1", expectedMessage, AddressBook.empty(), false, lastPersonList); - assertCommandBehavior(commandWord + " 0", expectedMessage, AddressBook.empty(), false, lastPersonList); - assertCommandBehavior(commandWord + " 3", expectedMessage, AddressBook.empty(), false, lastPersonList); - - } - - @Test - public void execute_view_onlyShowsNonPrivate() throws Exception { - - TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); - List lastPersonList = helper.generatePersonList(p1, p2); - AddressBook expectedAb = helper.generateAddressBook(lastPersonList); - helper.addToAddressBook(addressBook, lastPersonList); - - logic.setLastPersonShownList(lastPersonList); - - assertCommandBehavior("view 1", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextHidePrivate()), - expectedAb, - false, - lastPersonList); - - assertCommandBehavior("view 2", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextHidePrivate()), - expectedAb, - false, - lastPersonList); - } - - @Test - public void execute_tryToViewMissingPerson_errorMessage() throws Exception { + String expectedMessage = Messages.MESSAGE_INVALID_PLAYER_DISPLAYED_INDEX; TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); - List lastPersonList = helper.generatePersonList(p1, p2); + List lastPlayerList = helper.generatePlayerList(2); - AddressBook expectedAb = new AddressBook(); - expectedAb.addPerson(p2); + logic.setLastPlayerShownList(lastPlayerList); - addressBook.addPerson(p2); - logic.setLastPersonShownList(lastPersonList); - - assertCommandBehavior("view 1", - Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK, - expectedAb, - false, - lastPersonList); + assertCommandBehavior(commandWord + " -1", expectedMessage, AddressBook.empty(), false, lastPlayerList); + assertCommandBehavior(commandWord + " 0", expectedMessage, AddressBook.empty(), false, lastPlayerList); + assertCommandBehavior(commandWord + " 3", expectedMessage, AddressBook.empty(), false, lastPlayerList); } @Test @@ -307,47 +364,23 @@ public void execute_viewAll_invalidIndex() throws Exception { } @Test - public void execute_viewAll_alsoShowsPrivate() throws Exception { - TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, true); - Person p2 = helper.generatePerson(2, false); - List lastPersonList = helper.generatePersonList(p1, p2); - AddressBook expectedAb = helper.generateAddressBook(lastPersonList); - helper.addToAddressBook(addressBook, lastPersonList); - - logic.setLastPersonShownList(lastPersonList); - - assertCommandBehavior("viewall 1", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p1.getAsTextShowAll()), - expectedAb, - false, - lastPersonList); - - assertCommandBehavior("viewall 2", - String.format(ViewCommand.MESSAGE_VIEW_PERSON_DETAILS, p2.getAsTextShowAll()), - expectedAb, - false, - lastPersonList); - } - - @Test - public void execute_tryToViewAllPersonMissingInAddressBook_errorMessage() throws Exception { + public void execute_tryToViewAllPlayerMissingInAddressBook_errorMessage() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, false); - List lastPersonList = helper.generatePersonList(p1, p2); + Player p1 = helper.generatePlayer(1); + Player p2 = helper.generatePlayer(2); + List lastPlayerList = helper.generatePlayerList(p1, p2); AddressBook expectedAb = new AddressBook(); - expectedAb.addPerson(p1); + expectedAb.addPlayer(p1); - addressBook.addPerson(p1); - logic.setLastPersonShownList(lastPersonList); + addressBook.addPlayer(p1); + logic.setLastPlayerShownList(lastPlayerList); assertCommandBehavior("viewall 2", - Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK, - expectedAb, - false, - lastPersonList); + Messages.MESSAGE_PLAYER_NOT_IN_LEAGUE, + expectedAb, + false, + lastPlayerList); } @Test @@ -365,48 +398,47 @@ public void execute_delete_invalidIndex() throws Exception { @Test public void execute_delete_removesCorrectPerson() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Player p1 = helper.generatePlayer(1); + Player p2 = helper.generatePlayer(2); + Player p3 = helper.generatePlayer(3); - List threePersons = helper.generatePersonList(p1, p2, p3); + List threePlayers = helper.generatePlayerList(p1, p2, p3); - AddressBook expectedAb = helper.generateAddressBook(threePersons); - expectedAb.removePerson(p2); + AddressBook expectedAb = helper.generateAddressBook(threePlayers); + expectedAb.removePlayer(p2); - - helper.addToAddressBook(addressBook, threePersons); - logic.setLastPersonShownList(threePersons); + helper.addToAddressBook(addressBook, threePlayers); + logic.setLastPlayerShownList(threePlayers); assertCommandBehavior("delete 2", - String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, p2), - expectedAb, - false, - threePersons); + String.format(DeleteCommand.MESSAGE_DELETE_PLAYER_SUCCESS, p2), + expectedAb, + false, + threePlayers); } @Test public void execute_delete_missingInAddressBook() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person p1 = helper.generatePerson(1, false); - Person p2 = helper.generatePerson(2, true); - Person p3 = helper.generatePerson(3, true); + Player p1 = helper.generatePlayer(1); + Player p2 = helper.generatePlayer(2); + Player p3 = helper.generatePlayer(3); - List threePersons = helper.generatePersonList(p1, p2, p3); + List threePlayers = helper.generatePlayerList(p1, p2, p3); - AddressBook expectedAb = helper.generateAddressBook(threePersons); - expectedAb.removePerson(p2); + AddressBook expectedAb = helper.generateAddressBook(threePlayers); + expectedAb.removePlayer(p2); - helper.addToAddressBook(addressBook, threePersons); - addressBook.removePerson(p2); - logic.setLastPersonShownList(threePersons); + helper.addToAddressBook(addressBook, threePlayers); + addressBook.removePlayer(p2); + logic.setLastPlayerShownList(threePlayers); assertCommandBehavior("delete 2", - Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK, - expectedAb, - false, - threePersons); + Messages.MESSAGE_PLAYER_NOT_IN_LEAGUE, + expectedAb, + false, + threePlayers); } @Test @@ -418,61 +450,61 @@ public void execute_find_invalidArgsFormat() throws Exception { @Test public void execute_find_onlyMatchesFullWordsInNames() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla"); - Person pTarget2 = helper.generatePersonWithName("bla KEY bla bceofeia"); - Person p1 = helper.generatePersonWithName("KE Y"); - Person p2 = helper.generatePersonWithName("KEYKEYKEY sduauo"); + Player pTarget1 = helper.generatePlayerWithName("bla bla KEY bla"); + Player pTarget2 = helper.generatePlayerWithName("bla KEY bla bceofeia"); + Player p1 = helper.generatePlayerWithName("KE Y"); + Player p2 = helper.generatePlayerWithName("KEYKEYKEY sduauo"); - List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAb = helper.generateAddressBook(fourPersons); - List expectedList = helper.generatePersonList(pTarget1, pTarget2); - helper.addToAddressBook(addressBook, fourPersons); + List fourPlayers = helper.generatePlayerList(p1, pTarget1, p2, pTarget2); + AddressBook expectedAb = helper.generateAddressBook(fourPlayers); + List expectedList = helper.generatePlayerList(pTarget1, pTarget2); + helper.addToAddressBook(addressBook, fourPlayers); assertCommandBehavior("find KEY", - Command.getMessageForPersonListShownSummary(expectedList), - expectedAb, - true, - expectedList); + Command.getMessageForPlayerListShownSummary(expectedList), + expectedAb, + true, + expectedList); } @Test public void execute_find_isCaseSensitive() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla"); - Person pTarget2 = helper.generatePersonWithName("bla KEY bla bceofeia"); - Person p1 = helper.generatePersonWithName("key key"); - Person p2 = helper.generatePersonWithName("KEy sduauo"); + Player pTarget1 = helper.generatePlayerWithName("bla bla KEY bla"); + Player pTarget2 = helper.generatePlayerWithName("bla KEY bla bceofeia"); + Player p1 = helper.generatePlayerWithName("key key"); + Player p2 = helper.generatePlayerWithName("KEy sduauo"); - List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAb = helper.generateAddressBook(fourPersons); - List expectedList = helper.generatePersonList(pTarget1, pTarget2); - helper.addToAddressBook(addressBook, fourPersons); + List fourPlayers = helper.generatePlayerList(p1, pTarget1, p2, pTarget2); + AddressBook expectedAb = helper.generateAddressBook(fourPlayers); + List expectedList = helper.generatePlayerList(pTarget1, pTarget2); + helper.addToAddressBook(addressBook, fourPlayers); assertCommandBehavior("find KEY", - Command.getMessageForPersonListShownSummary(expectedList), - expectedAb, - true, - expectedList); + Command.getMessageForPlayerListShownSummary(expectedList), + expectedAb, + true, + expectedList); } @Test public void execute_find_matchesIfAnyKeywordPresent() throws Exception { TestDataHelper helper = new TestDataHelper(); - Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla"); - Person pTarget2 = helper.generatePersonWithName("bla rAnDoM bla bceofeia"); - Person p1 = helper.generatePersonWithName("key key"); - Person p2 = helper.generatePersonWithName("KEy sduauo"); + Player pTarget1 = helper.generatePlayerWithName("bla bla KEY bla"); + Player pTarget2 = helper.generatePlayerWithName("bla rAnDoM bla bceofeia"); + Player p1 = helper.generatePlayerWithName("key key"); + Player p2 = helper.generatePlayerWithName("KEy sduauo"); - List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); - AddressBook expectedAb = helper.generateAddressBook(fourPersons); - List expectedList = helper.generatePersonList(pTarget1, pTarget2); - helper.addToAddressBook(addressBook, fourPersons); + List fourPlayers = helper.generatePlayerList(p1, pTarget1, p2, pTarget2); + AddressBook expectedAb = helper.generateAddressBook(fourPlayers); + List expectedList = helper.generatePlayerList(pTarget1, pTarget2); + helper.addToAddressBook(addressBook, fourPlayers); assertCommandBehavior("find KEY rAnDoM", - Command.getMessageForPersonListShownSummary(expectedList), - expectedAb, - true, - expectedList); + Command.getMessageForPlayerListShownSummary(expectedList), + expectedAb, + true, + expectedList); } /** @@ -482,15 +514,24 @@ class TestDataHelper { /** * generate a person with the stated parameters */ - Person adam() throws Exception { - Name name = new Name("Adam Brown"); - Phone privatePhone = new Phone("111111", true); - Email email = new Email("adam@gmail.com", false); - Address privateAddress = new Address("111, alpha street", true); + Player messi() throws Exception { + Name name = new Name("Lionel Messi"); + PositionPlayed positionPlayed = new PositionPlayed("RW"); + Age age = new Age("30"); + Salary sal = new Salary("2000000"); + GoalsScored goalsScored = new GoalsScored("30"); + GoalsAssisted goalsAssisted = new GoalsAssisted("20"); + Team team = new Team("FC Barcelona"); + Country country = new Country("Argentina"); + JerseyNumber jerseyNumber = new JerseyNumber("10"); + Appearance appearance = new Appearance("54"); + HealthStatus healthStatus = new HealthStatus("Healthy"); + Tag tag1 = new Tag("tag1"); Tag tag2 = new Tag("tag2"); Set tags = new HashSet<>(Arrays.asList(tag1, tag2)); - return new Person(name, privatePhone, email, privateAddress, tags); + return new Player(name, positionPlayed, age, sal, goalsScored, goalsAssisted, + team, country, jerseyNumber, appearance, healthStatus, tags); } /** @@ -499,110 +540,118 @@ Person adam() throws Exception { * Each unique seed will generate a unique Person object. * * @param seed used to generate the player data field values - * @param isAllFieldsPrivate determines if private-able fields (phone, email, address) will be private */ - Person generatePerson(int seed, boolean isAllFieldsPrivate) throws Exception { - return new Person( - new Name("Person " + seed), - new Phone("" + Math.abs(seed), isAllFieldsPrivate), - new Email(seed + "@email", isAllFieldsPrivate), - new Address("House of " + seed, isAllFieldsPrivate), + Player generatePlayer(int seed) throws Exception { + return new Player( + new Name("Player " + seed), + new PositionPlayed("Position" + seed), + new Age("" + Math.abs(seed)), + new Salary("" + Math.abs(seed)), + new Team("Team" + Math.abs(seed)), + new Country("Country" + Math.abs(seed)), + new JerseyNumber("" + (Math.abs(seed) % 35)), new HashSet<>(Arrays.asList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))) ); } - /** Generates the correct add command based on the player given */ - String generateAddCommand(Person p) { + /** + * Generates the correct add command based on the player given + */ + String generateAddCommand(Player p) { StringJoiner cmd = new StringJoiner(" "); - cmd.add("add"); - + cmd.add("addPlayer"); cmd.add(p.getName().toString()); - cmd.add((p.getPhone().isPrivate() ? "pp/" : "p/") + p.getPhone()); - cmd.add((p.getEmail().isPrivate() ? "pe/" : "e/") + p.getEmail()); - cmd.add((p.getAddress().isPrivate() ? "pa/" : "a/") + p.getAddress()); - + cmd.add(" p/" + p.getPositionPlayed().toString()); + cmd.add(" a/" + p.getAge().toString()); + cmd.add(" sal/" + p.getSalary().toString()); + cmd.add(" gs/" + p.getGoalsScored().toString()); + cmd.add(" ga/" + p.getGoalsAssisted().toString()); + cmd.add(" tm/" + p.getTeam().toString()); + cmd.add(" ctry/" + p.getCountry().toString()); + cmd.add(" jn/" + p.getJerseyNumber().toString()); + cmd.add(" app/" + p.getAppearance().toString()); + cmd.add(" hs/" + p.getHealthStatus().toString()); Set tags = p.getTags(); - for (Tag t: tags) { + for (Tag t : tags) { cmd.add("t/" + t.tagName); } - return cmd.toString(); } /** * Generates an AddressBook with auto-generated persons. - * @param isPrivateStatuses flags to indicate if all contact details of respective persons should be set to - * private. + * + * @param num to indicate the number of player profiles that should be included in the League Tracker. */ - AddressBook generateAddressBook(Boolean... isPrivateStatuses) throws Exception { + AddressBook generateAddressBook(int num) throws Exception { AddressBook addressBook = new AddressBook(); - addToAddressBook(addressBook, isPrivateStatuses); + addToAddressBook(addressBook, num); return addressBook; } /** * Generates an AddressBook based on the list of Persons given. */ - AddressBook generateAddressBook(List persons) throws Exception { + AddressBook generateAddressBook(List players) throws Exception { AddressBook addressBook = new AddressBook(); - addToAddressBook(addressBook, persons); + addToAddressBook(addressBook, players); return addressBook; } /** * Adds auto-generated Person objects to the given AddressBook + * * @param addressBook The AddressBook to which the Persons will be added - * @param isPrivateStatuses flags to indicate if all contact details of generated persons should be set to - * private. + * @param num to indicate the number of players profiles that should exist in the League Tracker. */ - void addToAddressBook(AddressBook addressBook, Boolean... isPrivateStatuses) throws Exception { - addToAddressBook(addressBook, generatePersonList(isPrivateStatuses)); + void addToAddressBook(AddressBook addressBook, int num) throws Exception { + addToAddressBook(addressBook, generatePlayerList(num)); } /** * Adds the given list of Persons to the given AddressBook */ - void addToAddressBook(AddressBook addressBook, List personsToAdd) throws Exception { - for (Person p: personsToAdd) { - addressBook.addPerson(p); + void addToAddressBook(AddressBook addressBook, List playersToAdd) throws Exception { + for (Player p : playersToAdd) { + addressBook.addPlayer(p); } } /** * Creates a list of Persons based on the give Person objects. */ - List generatePersonList(Person... persons) throws Exception { - List personList = new ArrayList<>(); - for (Person p: persons) { + List generatePlayerList(Player... players) throws Exception { + List personList = new ArrayList<>(); + for (Player p : players) { personList.add(p); } return personList; } /** - * Generates a list of Persons based on the flags. - * @param isPrivateStatuses flags to indicate if all contact details of respective persons should be set to - * private. + * Generates a list of Persons based on the number given. */ - List generatePersonList(Boolean... isPrivateStatuses) throws Exception { - List persons = new ArrayList<>(); - int i = 1; - for (Boolean p: isPrivateStatuses) { - persons.add(generatePerson(i++, p)); + List generatePlayerList(int num) throws Exception { + List players = new ArrayList<>(); + for (int j = 1; j <= num; j++) { + players.add(generatePlayer(j)); } - return persons; + return players; } /** * Generates a Person object with given name. Other fields will have some dummy values. */ - Person generatePersonWithName(String name) throws Exception { - return new Person( + Player generatePlayerWithName(String name) throws Exception { + return new Player( new Name(name), - new Phone("1", false), - new Email("1@email", false), - new Address("House of 1", false), + new PositionPlayed("Striker"), + new Age("25"), + new Salary("20000"), + new Team("FC Barcelona"), + new Country("Argentina"), + new JerseyNumber("10"), Collections.singleton(new Tag("tag")) ); } diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 5d9803d21..95c1e95ed 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -11,24 +11,30 @@ import org.junit.Before; import org.junit.Test; -import seedu.addressbook.commands.AddCommand; -import seedu.addressbook.commands.ClearCommand; import seedu.addressbook.commands.Command; -import seedu.addressbook.commands.DeleteCommand; import seedu.addressbook.commands.ExitCommand; -import seedu.addressbook.commands.FindCommand; import seedu.addressbook.commands.HelpCommand; import seedu.addressbook.commands.IncorrectCommand; -import seedu.addressbook.commands.ListCommand; -import seedu.addressbook.commands.ViewAllCommand; -import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.player.AddCommand; +import seedu.addressbook.commands.player.ClearCommand; +import seedu.addressbook.commands.player.DeleteCommand; +import seedu.addressbook.commands.player.FindCommand; +import seedu.addressbook.commands.player.ListCommand; +import seedu.addressbook.commands.player.ViewAllCommand; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.player.Address; -import seedu.addressbook.data.player.Email; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Appearance; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.GoalsAssisted; +import seedu.addressbook.data.player.GoalsScored; +import seedu.addressbook.data.player.HealthStatus; +import seedu.addressbook.data.player.JerseyNumber; import seedu.addressbook.data.player.Name; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.Phone; -import seedu.addressbook.data.player.ReadOnlyPerson; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.ReadOnlyPlayer; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; import seedu.addressbook.data.tag.Tag; public class ParserTest { @@ -42,14 +48,14 @@ public void setup() { @Test public void emptyInput_returnsIncorrect() { - final String[] emptyInputs = { "", " ", "\n \n" }; + final String[] emptyInputs = {"", " ", "\n \n"}; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, emptyInputs); } @Test public void unknownCommandWord_returnsHelp() { - final String input = "unknowncommandword arguments arguments"; + final String input = "anyhowcommandword arguments arguments"; parseAndAssertCommandType(input, HelpCommand.class); } @@ -85,14 +91,14 @@ public void exitCommand_parsedCorrectly() { */ @Test public void deleteCommand_noArgs() { - final String[] inputs = { "delete", "delete " }; + final String[] inputs = {"delete", "delete "}; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); } @Test public void deleteCommand_argsIsNotSingleNumber() { - final String[] inputs = { "delete notAnumber ", "delete 8*wh12", "delete 1 2 3 4 5" }; + final String[] inputs = {"delete notANumber ", "delete 8*wh12", "delete 1 2 3 4 5"}; final String resultMessage; resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); @@ -106,31 +112,9 @@ public void deleteCommand_numericArg_indexParsedCorrectly() { assertEquals(result.getTargetIndex(), testIndex); } - @Test - public void viewCommand_noArgs() { - final String[] inputs = { "view", "view " }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); - parseAndAssertIncorrectWithMessage(resultMessage, inputs); - } - - @Test - public void viewCommand_argsIsNotSingleNumber() { - final String[] inputs = { "view notAnumber ", "view 8*wh12", "view 1 2 3 4 5" }; - final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); - parseAndAssertIncorrectWithMessage(resultMessage, inputs); - } - - @Test - public void viewCommand_numericArg_indexParsedCorrectly() { - final int testIndex = 2; - final String input = "view " + testIndex; - final ViewCommand result = parseAndAssertCommandType(input, ViewCommand.class); - assertEquals(result.getTargetIndex(), testIndex); - } - @Test public void viewAllCommand_noArgs() { - final String[] inputs = { "viewall", "viewall " }; + final String[] inputs = {"viewall", "viewall "}; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); @@ -138,7 +122,7 @@ public void viewAllCommand_noArgs() { @Test public void viewAllCommand_argsIsNotSingleNumber() { - final String[] inputs = { "viewall notAnumber ", "viewall 8*wh12", "viewall 1 2 3 4 5" }; + final String[] inputs = {"viewall notAnumber ", "viewall 8*wh12", "viewall 1 2 3 4 5"}; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewAllCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); } @@ -152,16 +136,13 @@ public void viewAllCommand_numericArg_indexParsedCorrectly() { } /** - * Test find persons by keyword in name command + * Test find players by keyword in name command */ @Test public void findCommand_invalidArgs() { // no keywords - final String[] inputs = { - "find", - "find " - }; + final String[] inputs = {"find", "find "}; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); @@ -169,7 +150,7 @@ public void findCommand_invalidArgs() { @Test public void findCommand_validArgs_parsedCorrectly() { - final String[] keywords = { "key1", "key2", "key3" }; + final String[] keywords = {"key1", "key2", "key3"}; final Set keySet = new HashSet<>(Arrays.asList(keywords)); final String input = "find " + String.join(" ", keySet); @@ -180,7 +161,7 @@ public void findCommand_validArgs_parsedCorrectly() { @Test public void findCommand_duplicateKeys_parsedCorrectly() { - final String[] keywords = { "key1", "key2", "key3" }; + final String[] keywords = {"key1", "key2", "key3"}; final Set keySet = new HashSet<>(Arrays.asList(keywords)); // duplicate every keyword @@ -195,44 +176,135 @@ public void findCommand_duplicateKeys_parsedCorrectly() { */ @Test public void addCommand_invalidArgs() { - final String[] inputs = { - "add", - "add ", - "add wrong args format", - // no phone prefix - String.format("add $s $s e/$s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no email prefix - String.format("add $s p/$s $s a/$s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE), - // no address prefix - String.format("add $s p/$s e/$s $s", Name.EXAMPLE, Phone.EXAMPLE, Email.EXAMPLE, Address.EXAMPLE) + final String[] inputs = {"addPlayer", "addPlayer ", "addPlayer wrong args format", + // no position prefix + String.format("addPlayer %1$s %2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + // no age prefix + String.format("addPlayer %1$s p/%2$s %3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + // no salary prefix + String.format("addPlayer %1$s p/%2$s a/%3$s %4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no GoalsScored prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s %5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no GoalsAssisted prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no Team prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s %7$s ctry/%8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no Country prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s %8$s jn/%9$s app/%10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no JerseyNumber prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s %9$s app/%10$s hs/%11$s", Name.EXAMPLE, + PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no Appearance prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s %10$s hs/%11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), + + //no HealthStatus prefix + String.format("addPlayer %1$s p/%2$s a/%3$s sal/%4$s gs/%5$s " + + "ga/%6$s tm/%7$s ctry/%8$s jn/%9$s app/%10$s %11$s", + Name.EXAMPLE, PositionPlayed.EXAMPLE, Age.EXAMPLE, Salary.EXAMPLE, GoalsScored.EXAMPLE, + GoalsAssisted.EXAMPLE, Team.EXAMPLE, Country.EXAMPLE, JerseyNumber.EXAMPLE, Appearance.EXAMPLE, + HealthStatus.EXAMPLE), }; final String resultMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); parseAndAssertIncorrectWithMessage(resultMessage, inputs); } @Test - public void addCommand_invalidPersonDataInArgs() { + public void addCommand_invalidPlayerDataInArgs() { + // name, age, salary, gs, ga, jn and appearance are the ones that need to be tested final String invalidName = "[]\\[;]"; final String validName = Name.EXAMPLE; - final String invalidPhoneArg = "p/not__numbers"; - final String validPhoneArg = "p/" + Phone.EXAMPLE; - final String invalidEmailArg = "e/notAnEmail123"; - final String validEmailArg = "e/" + Email.EXAMPLE; + final String invalidAgeArg = "a/not_numbers"; + final String validAgeArg = "a/" + Age.EXAMPLE; + final String invalidSalaryArg = "sal/not_number"; + final String validSalaryArg = "sal/" + Salary.EXAMPLE; + final String invalidGsArg = "gs/not_number"; + final String validGsArg = "gs/" + GoalsScored.EXAMPLE; + final String invalidGaArg = "ga/not_number"; + final String validGaArg = "ga/" + GoalsAssisted.EXAMPLE; + final String invalidJnArg = "jn/not_number"; + final String validJnArg = "jn/" + JerseyNumber.EXAMPLE; + final String invalidAppearanceArg = "app/not_number"; + final String validAppearanceArg = "app/" + Appearance.EXAMPLE; + final String invalidTagArg = "t/invalid_-[.tag"; - // address can be any string, so no invalid address - final String addCommandFormatString = "add $s $s $s a/" + Address.EXAMPLE; + // PositionPlayer, Team, Country and HealthStatus can be any string, so no invalid address + // name, age, salary, gs, ga, jn, app + + final String addCommandFormatString = "addPlayer %1$s " + "p/" + + PositionPlayed.EXAMPLE + " %2$s %3$s %4$s %5$s " + "tm/" + + Team.EXAMPLE + " ctry/" + Country.EXAMPLE + " %6$s %7$s " + "hs/" + + HealthStatus.EXAMPLE + " "; // test each incorrect player data field argument individually final String[] inputs = { // invalid name - String.format(addCommandFormatString, invalidName, validPhoneArg, validEmailArg), - // invalid phone - String.format(addCommandFormatString, validName, invalidPhoneArg, validEmailArg), - // invalid email - String.format(addCommandFormatString, validName, validPhoneArg, invalidEmailArg), + String.format(addCommandFormatString, invalidName, validAgeArg, validSalaryArg, validGsArg, + validGaArg, validJnArg, validAppearanceArg), + // invalid age + String.format(addCommandFormatString, validName, invalidAgeArg, validSalaryArg, validGsArg, + validGaArg, validJnArg, validAppearanceArg), + // invalid salary + String.format(addCommandFormatString, validName, validAgeArg, invalidSalaryArg, validGsArg, + validGaArg, validJnArg, validAppearanceArg), + // invalid GS + String.format(addCommandFormatString, validName, validAgeArg, validSalaryArg, invalidGsArg, + validGaArg, validJnArg, validAppearanceArg), + // invalid GA + String.format(addCommandFormatString, validName, validAgeArg, validSalaryArg, validGsArg, + invalidGaArg, validJnArg, validAppearanceArg), + // invalid JN + String.format(addCommandFormatString, validName, validAgeArg, validSalaryArg, validGsArg, + validGaArg, invalidJnArg, validAppearanceArg), + // invalid Appearance + String.format(addCommandFormatString, validName, validAgeArg, validSalaryArg, validGsArg, + validGaArg, validJnArg, invalidAppearanceArg), // invalid tag - String.format(addCommandFormatString, validName, validPhoneArg, validEmailArg) + " " + invalidTagArg + String.format(addCommandFormatString, validName, validAgeArg, validSalaryArg, validGsArg, + validGaArg, validJnArg, validAppearanceArg) + " " + invalidTagArg }; for (String input : inputs) { parseAndAssertCommandType(input, IncorrectCommand.class); @@ -240,36 +312,45 @@ public void addCommand_invalidPersonDataInArgs() { } @Test - public void addCommand_validPersonData_parsedCorrectly() { - final Person testPerson = generateTestPerson(); - final String input = convertPersonToAddCommandString(testPerson); + public void addCommand_validPlayerData_parsedCorrectly() { + final Player testPlayer = generateTestPlayer(); + final String input = convertPlayerToAddCommandString(testPlayer); final AddCommand result = parseAndAssertCommandType(input, AddCommand.class); - assertEquals(result.getPerson(), testPerson); + assertEquals(result.getPlayer(), testPlayer); } @Test public void addCommand_duplicateTags_merged() throws IllegalValueException { - final Person testPerson = generateTestPerson(); - String input = convertPersonToAddCommandString(testPerson); - for (Tag tag : testPerson.getTags()) { + final Player testPlayer = generateTestPlayer(); + String input = convertPlayerToAddCommandString(testPlayer); + for (Tag tag : testPlayer.getTags()) { // create duplicates by doubling each tag input += " t/" + tag.tagName; } final AddCommand result = parseAndAssertCommandType(input, AddCommand.class); - assertEquals(result.getPerson(), testPerson); + assertEquals(result.getPlayer(), testPlayer); } + + /** - * generates a test person + * generates a test player */ - private static Person generateTestPerson() { + private static Player generateTestPlayer() { try { - return new Person( - new Name(Name.EXAMPLE), - new Phone(Phone.EXAMPLE, true), - new Email(Email.EXAMPLE, false), - new Address(Address.EXAMPLE, true), - new HashSet<>(Arrays.asList(new Tag("tag1"), new Tag("tag2"), new Tag("tag3"))) + return new Player( + new Name(Name.EXAMPLE), + new PositionPlayed(PositionPlayed.EXAMPLE), + new Age(Age.EXAMPLE), + new Salary(Salary.EXAMPLE), + new GoalsScored(GoalsScored.EXAMPLE), + new GoalsAssisted(GoalsAssisted.EXAMPLE), + new Team(Team.EXAMPLE), + new Country(Country.EXAMPLE), + new JerseyNumber(JerseyNumber.EXAMPLE), + new Appearance(Appearance.EXAMPLE), + new HealthStatus(HealthStatus.EXAMPLE), + new HashSet<>(Arrays.asList(new Tag("tag1"), new Tag("tag2"), new Tag("tag3"))) ); } catch (IllegalValueException ive) { throw new RuntimeException("test player data should be valid by definition"); @@ -277,15 +358,22 @@ private static Person generateTestPerson() { } /** - * Converts person to add command string + * Converts player to add command string */ - private static String convertPersonToAddCommandString(ReadOnlyPerson person) { - String addCommand = "add " - + person.getName().fullName - + (person.getPhone().isPrivate() ? " pp/" : " p/") + person.getPhone().value - + (person.getEmail().isPrivate() ? " pe/" : " e/") + person.getEmail().value - + (person.getAddress().isPrivate() ? " pa/" : " a/") + person.getAddress().value; - for (Tag tag : person.getTags()) { + private static String convertPlayerToAddCommandString(ReadOnlyPlayer player) { + String addCommand = "addPlayer " + + player.getName().fullName + + " p/" + player.getPositionPlayed().fullPosition + + " a/" + player.getAge().value + + " sal/" + player.getSalary().value + + " gs/" + player.getGoalsScored().value + + " ga/" + player.getGoalsAssisted().value + + " tm/" + player.getTeam().fullTeam + + " ctry/" + player.getCountry().fullCountry + + " jn/" + player.getJerseyNumber().value + + " app/" + player.getAppearance().value + + " hs/" + player.getHealthStatus().fullHs; + for (Tag tag : player.getTags()) { addCommand += " t/" + tag.tagName; } return addCommand; @@ -308,13 +396,16 @@ private void parseAndAssertIncorrectWithMessage(String feedbackMessage, String.. /** * Utility method for parsing input and asserting the class/type of the returned command object. * - * @param input to be parsed + * @param input to be parsed * @param expectedCommandClass expected class of returned command * @return the parsed command object */ + private T parseAndAssertCommandType(String input, Class expectedCommandClass) { final Command result = parser.parseCommand(input); assertTrue(result.getClass().isAssignableFrom(expectedCommandClass)); return (T) result; } + + } diff --git a/test/java/seedu/addressbook/storage/StorageFileTest.java b/test/java/seedu/addressbook/storage/StorageFileTest.java index f4e15faa5..daf290385 100644 --- a/test/java/seedu/addressbook/storage/StorageFileTest.java +++ b/test/java/seedu/addressbook/storage/StorageFileTest.java @@ -4,9 +4,7 @@ import static seedu.addressbook.util.TestUtil.assertTextFilesEqual; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import org.junit.Rule; import org.junit.Test; @@ -15,12 +13,18 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.exception.IllegalValueException; -import seedu.addressbook.data.player.Address; -import seedu.addressbook.data.player.Email; +import seedu.addressbook.data.player.Age; +import seedu.addressbook.data.player.Appearance; +import seedu.addressbook.data.player.Country; +import seedu.addressbook.data.player.GoalsAssisted; +import seedu.addressbook.data.player.GoalsScored; +import seedu.addressbook.data.player.HealthStatus; +import seedu.addressbook.data.player.JerseyNumber; import seedu.addressbook.data.player.Name; -import seedu.addressbook.data.player.Person; -import seedu.addressbook.data.player.Phone; -import seedu.addressbook.data.tag.Tag; +import seedu.addressbook.data.player.Player; +import seedu.addressbook.data.player.PositionPlayed; +import seedu.addressbook.data.player.Salary; +import seedu.addressbook.data.player.Team; import seedu.addressbook.storage.StorageFile.StorageOperationException; public class StorageFileTest { @@ -59,7 +63,7 @@ public void load_validFormat() throws Exception { // ensure loaded AddressBook is properly constructed with test data // TODO: overwrite equals method in AddressBook class and replace with equals method below - assertEquals(actualAb.getAllPersons(), expectedAb.getAllPersons()); + assertEquals(actualAb.getAllPlayers(), expectedAb.getAllPlayers()); } @Test @@ -97,16 +101,32 @@ private StorageFile getTempStorage() throws Exception { private AddressBook getTestAddressBook() throws Exception { AddressBook ab = new AddressBook(); - ab.addPerson(new Person(new Name("John Doe"), - new Phone("98765432", false), - new Email("johnd@gmail.com", false), - new Address("John street, block 123, #01-01", false), + + ab.addPlayer(new Player(new Name("Lionel Messi"), + new PositionPlayed("RW"), + new Age("30"), + new Salary("200"), + new GoalsScored("30"), + new GoalsAssisted("20"), + new Team("FC Barcelona"), + new Country("Argentina"), + new JerseyNumber("10"), + new Appearance("54"), + new HealthStatus("Healthy"), + Collections.emptySet())); + + ab.addPlayer(new Player(new Name("Luis Suarez"), + new PositionPlayed("Striker"), + new Age("32"), + new Salary("200"), + new GoalsScored("30"), + new GoalsAssisted("20"), + new Team("FC Barcelona"), + new Country("Uruguay"), + new JerseyNumber("9"), + new Appearance("54"), + new HealthStatus("Healthy"), Collections.emptySet())); - ab.addPerson(new Person(new Name("Betsy Crowe"), - new Phone("1234567", true), - new Email("betsycrowe@gmail.com", false), - new Address("Newgate Prison", true), - new HashSet<>(Arrays.asList(new Tag("friend"), new Tag("criminal"))))); return ab; } }