From 812a9d2e61119bae99efe44bf9622e3ea1ea0b4a Mon Sep 17 00:00:00 2001 From: Abhiman2211 <49817648+Abhiman2211@users.noreply.github.com> Date: Wed, 2 Oct 2019 19:25:36 +0800 Subject: [PATCH] Alfred Add Command Parsers (#32) * Add Alfred-specific parser classes. * Modify prefixes. * Implement Add Command Parsers. --- docs/UserGuide.adoc | 3 +- docs/tutorials/RemovingFields.adoc | 1 - .../address/logic/commands/EditCommand.java | 19 +-- .../logic/parser/AddCommandParser.java | 11 +- .../AddMentorCommandParser.java | 54 +++++++ .../AddParticipantCommandParser.java | 47 ++++++ .../AddTeamCommandParser.java | 58 ++++++++ .../logic/parser/AddressBookParser.java | 2 +- .../logic/parser/AlfredParserUtil.java | 140 ++++++++++++++++++ .../seedu/address/logic/parser/CliSyntax.java | 10 +- .../logic/parser/DeleteCommandParser.java | 2 +- .../DeleteMentorCommandParser.java | 27 ++++ .../DeleteParticipantCommandParser.java | 29 ++++ .../DeleteTeamCommandParser.java | 27 ++++ .../logic/parser/EditCommandParser.java | 7 +- .../EditMentorCommandParser.java | 48 ++++++ .../EditParticipantCommandParser.java | 49 ++++++ .../EditTeamCommandParser.java | 48 ++++++ .../ListMentorCommandParser.java | 52 +++++++ .../ListParticipantCommandParser.java | 52 +++++++ .../ListTeamCommandParser.java | 52 +++++++ .../address/logic/parser/ParserUtil.java | 2 +- .../ViewMentorCommandParser.java | 52 +++++++ .../ViewParticipantCommandParser.java | 52 +++++++ .../ViewTeamCommandParser.java | 52 +++++++ .../address/model/entity/ProjectType.java | 1 + .../address/model/entity/SubjectName.java | 2 - .../seedu/address/model/person/Person.java | 15 +- .../address/model/util/SampleDataUtil.java | 7 - .../address/storage/JsonAdaptedPerson.java | 16 +- .../java/seedu/address/ui/PersonCard.java | 1 - src/main/resources/view/PersonListCard.fxml | 1 - .../logic/parser/AddCommandParserTest.java | 4 - .../logic/parser/EditCommandParserTest.java | 15 +- .../address/logic/parser/ParserUtilTest.java | 74 ++++----- .../address/model/person/AddressTest.java | 36 ----- .../storage/JsonAdaptedPersonTest.java | 32 +--- .../testutil/EditPersonDescriptorBuilder.java | 10 -- .../seedu/address/testutil/PersonBuilder.java | 14 +- .../seedu/address/testutil/PersonUtil.java | 2 - 40 files changed, 901 insertions(+), 225 deletions(-) create mode 100644 src/main/java/seedu/address/logic/parser/AddCommandParsers/AddMentorCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/AddCommandParsers/AddParticipantCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/AddCommandParsers/AddTeamCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/AlfredParserUtil.java create mode 100644 src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteMentorCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteParticipantCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteTeamCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/EditCommandParsers/EditMentorCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/EditCommandParsers/EditParticipantCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/EditCommandParsers/EditTeamCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ListCommandParsers/ListMentorCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ListCommandParsers/ListParticipantCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ListCommandParsers/ListTeamCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewMentorCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewParticipantCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewTeamCommandParser.java delete mode 100644 src/test/java/seedu/address/model/person/AddressTest.java diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 26a8bdd972f..0e41b4aa950 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -72,11 +72,12 @@ For example in the case of `add {mentor/participant/list}`, you can choose to ty This command displays a help page in a separate pop-up window. Should you require further information, the pop-up window also includes links to further references and documentation. + + Format: `help` === Adding an Entity: `add {participant/mentor/team}` -Adds an entity for Alfred to keep track of + +Use this command to add an entity for Alfred to keep track of. + **** * Creates an Entity as specified by you. Each Entity object will have a unique ID autmatically assigned to it. * As of version 1.1, you must provide all the fields. There are no optional fields. diff --git a/docs/tutorials/RemovingFields.adoc b/docs/tutorials/RemovingFields.adoc index 5a50b6965a6..9a37426f7ac 100644 --- a/docs/tutorials/RemovingFields.adoc +++ b/docs/tutorials/RemovingFields.adoc @@ -24,7 +24,6 @@ Fortunately, the IntelliJ IDEA provides a robust refactoring tool that can ident Let's try to use it as much as we can. === Assisted refactoring -The `address` field in `Person` is actually an instance of the `seedu.address.model.person.Address` class. Since removing the `Address` class will break the application, we start by identifying ``Address``'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` > `Safe Delete` through the menu. diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 7e36114902f..71e7d5e98bc 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,7 +1,6 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; @@ -19,7 +18,6 @@ import seedu.address.commons.util.CollectionUtil; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -40,7 +38,6 @@ public class EditCommand extends Command { + "[" + PREFIX_NAME + "NAME] " + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " - + "[" + PREFIX_ADDRESS + "ADDRESS] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " @@ -96,10 +93,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); - Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedTags); } @Override @@ -128,7 +124,6 @@ public static class EditPersonDescriptor { private Name name; private Phone phone; private Email email; - private Address address; private Set tags; public EditPersonDescriptor() {} @@ -141,7 +136,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setName(toCopy.name); setPhone(toCopy.phone); setEmail(toCopy.email); - setAddress(toCopy.address); setTags(toCopy.tags); } @@ -149,7 +143,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, tags); } public void setName(Name name) { @@ -176,14 +170,6 @@ public Optional getEmail() { return Optional.ofNullable(email); } - public void setAddress(Address address) { - this.address = address; - } - - public Optional
getAddress() { - return Optional.ofNullable(address); - } - /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. @@ -219,7 +205,6 @@ public boolean equals(Object other) { return getName().equals(e.getName()) && getPhone().equals(e.getPhone()) && getEmail().equals(e.getEmail()) - && getAddress().equals(e.getAddress()) && getTags().equals(e.getTags()); } } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 3b8bfa035e8..8ff27940a97 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -1,7 +1,6 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; @@ -12,7 +11,6 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -31,9 +29,9 @@ public class AddCommandParser implements Parser { */ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } @@ -41,10 +39,9 @@ public AddCommand parse(String args) throws ParseException { Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); - Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Set tagList = AlfredParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + Person person = new Person(name, phone, email, tagList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddMentorCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddMentorCommandParser.java new file mode 100644 index 00000000000..37bdcd17503 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddMentorCommandParser.java @@ -0,0 +1,54 @@ +package seedu.address.logic.parser.AddCommandParsers; + +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ORGANISATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SPECIALISATION; +import seedu.address.logic.commands.addcommand.AddCommand; +import seedu.address.logic.commands.addcommand.AddMentorCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.entity.Email; +import seedu.address.model.entity.Id; +import seedu.address.model.entity.Mentor; +import seedu.address.model.entity.Phone; +import seedu.address.model.entity.SubjectName; +import seedu.address.model.entity.Name; +import seedu.address.model.entitylist.MentorList; + +/** + * Parses input arguments and creates a new AddCommand object + */ +public class AddMentorCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddCommand + * and returns an AddCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AddMentorCommand parse(String args) throws ParseException { + + /** + * Added the below code as a placeholder. We will replace it with proper code + * once the Mentor class is finalised. + */ + + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ORGANISATION, + PREFIX_SPECIALISATION); + Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); + Phone phone = AlfredParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); + Email email = AlfredParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + Name organisation = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_ORGANISATION).get()); + SubjectName subject = AlfredParserUtil.parseSubject(argMultimap.getValue(PREFIX_SPECIALISATION).get()); + Id id = new MentorList().generateID(); + + Mentor mentor = new Mentor(name, id, phone, email, organisation, subject); + + return new AddMentorCommand(mentor); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddParticipantCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddParticipantCommandParser.java new file mode 100644 index 00000000000..b6a8f7383cd --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddParticipantCommandParser.java @@ -0,0 +1,47 @@ +package seedu.address.logic.parser.AddCommandParsers; + +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import seedu.address.logic.commands.addcommand.AddParticipantCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.entity.Email; +import seedu.address.model.entity.Id; +import seedu.address.model.entity.Name; +import seedu.address.model.entity.Participant; +import seedu.address.model.entity.Phone; +import seedu.address.model.entitylist.ParticipantList; + +/** + * Parses input arguments and creates a new AddCommand object + */ +public class AddParticipantCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddCommand + * and returns an AddCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AddParticipantCommand parse(String args) throws ParseException { + + /** + * Added the below code as a placeholder. We will replace it with proper code + * once the Participant class is finalised. + */ + + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL); + Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); + Phone phone = AlfredParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); + Email email = AlfredParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + Id id = new ParticipantList().generateID(); + + Participant participant = new Participant(name, id, email, phone); + + return new AddParticipantCommand(participant); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddTeamCommandParser.java new file mode 100644 index 00000000000..caee1450a73 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddCommandParsers/AddTeamCommandParser.java @@ -0,0 +1,58 @@ +package seedu.address.logic.parser.AddCommandParsers; + +import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TYPE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SPECIALISATION; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import seedu.address.logic.commands.addcommand.AddCommand; +import seedu.address.logic.commands.addcommand.AddTeamCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.entity.Id; +import seedu.address.model.entity.Location; +import seedu.address.model.entity.Mentor; +import seedu.address.model.entity.Name; +import seedu.address.model.entity.Participant; +import seedu.address.model.entity.ProjectType; +import seedu.address.model.entity.Score; +import seedu.address.model.entity.SubjectName; +import seedu.address.model.entity.Team; +import seedu.address.model.entitylist.TeamList; + +/** + * Parses input arguments and creates a new AddCommand object + */ +public class AddTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddCommand + * and returns an AddCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AddTeamCommand parse(String args) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_SPECIALISATION, PREFIX_PROJECT_NAME, + PREFIX_PROJECT_TYPE, PREFIX_LOCATION); + + Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); + SubjectName subject = AlfredParserUtil.parseSubject(argMultimap.getValue(PREFIX_SPECIALISATION).get()); + Name projectName = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_PROJECT_NAME).get()); + ProjectType projectType = AlfredParserUtil.parseProjectType(argMultimap.getValue(PREFIX_PROJECT_TYPE).get()); + Location location = AlfredParserUtil.parseLocation(argMultimap.getValue(PREFIX_LOCATION).get()); + Id id = new TeamList().generateID(); + List participants = new LinkedList<>(); + Score score = new Score(0); + Optional mentor = Optional.empty(); + + Team team = new Team(id, name, participants, mentor, subject, score, projectName, projectType, location); + + return new AddTeamCommand(team); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 1e466792b46..0a8511c3a0e 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -30,7 +30,7 @@ public class AddressBookParser { /** * Parses user input into command for execution. * - * @param userInput full user input string + * @param userInput full input string * @return the command based on the user input * @throws ParseException if the user input does not conform the expected format */ diff --git a/src/main/java/seedu/address/logic/parser/AlfredParserUtil.java b/src/main/java/seedu/address/logic/parser/AlfredParserUtil.java new file mode 100644 index 00000000000..a2c0681b891 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AlfredParserUtil.java @@ -0,0 +1,140 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.util.StringUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.entity.Email; +import seedu.address.model.entity.Location; +import seedu.address.model.entity.Name; +import seedu.address.model.entity.Phone; +import seedu.address.model.entity.ProjectType; +import seedu.address.model.entity.SubjectName; +import seedu.address.model.tag.Tag; + + +/** + * Contains utility methods used for parsing strings in the various *Parser classes. + */ +public class AlfredParserUtil { + + public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; + + /** + * Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be + * trimmed. + * @throws ParseException if the specified index is invalid (not non-zero unsigned integer). + */ + public static Index parseIndex(String oneBasedIndex) throws ParseException { + String trimmedIndex = oneBasedIndex.trim(); + if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) { + throw new ParseException(MESSAGE_INVALID_INDEX); + } + return Index.fromOneBased(Integer.parseInt(trimmedIndex)); + } + + /** + * Parses a {@code String name} into a {@code Name}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code name} is invalid. + */ + public static Name parseName(String name) throws ParseException { + requireNonNull(name); + String trimmedName = name.trim(); + if (!Name.isValidName(trimmedName)) { + throw new ParseException(Name.MESSAGE_CONSTRAINTS); + } + return new Name(trimmedName); + } + + /** + * Parses a {@code String phone} into a {@code Phone}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code phone} is invalid. + */ + public static Phone parsePhone(String phone) throws ParseException { + requireNonNull(phone); + String trimmedPhone = phone.trim(); + if (!Phone.isValidPhone(trimmedPhone)) { + throw new ParseException(Phone.MESSAGE_CONSTRAINTS); + } + return new Phone(trimmedPhone); + } + + /** + * Parses a {@code String email} into an {@code Email}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code email} is invalid. + */ + public static Email parseEmail(String email) throws ParseException { + requireNonNull(email); + String trimmedEmail = email.trim(); + if (!Email.isValidEmail(trimmedEmail)) { + throw new ParseException(Email.MESSAGE_CONSTRAINTS); + } + return new Email(trimmedEmail); + } + + /** + * Parses a {@code String tag} into a {@code Tag}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code tag} is invalid. + */ + public static Tag parseTag(String tag) throws ParseException { + requireNonNull(tag); + String trimmedTag = tag.trim(); + if (!Tag.isValidTagName(trimmedTag)) { + throw new ParseException(Tag.MESSAGE_CONSTRAINTS); + } + return new Tag(trimmedTag); + } + + public static Location parseLocation(String location) throws ParseException { + requireNonNull(location); + int trimmedLocation = Integer.parseInt(location.trim()); + if (!Location.isValidNumber(trimmedLocation)) { + throw new ParseException(Location.MESSAGE_CONSTRAINTS_INVALID_TABLE_NUMBER); + } + return new Location(trimmedLocation); + } + + public static SubjectName parseSubject(String subject) throws ParseException { + requireNonNull(subject); + String trimmedSubject = subject.trim(); + if (!SubjectName.isValidSubjectName(trimmedSubject)) { + throw new ParseException(SubjectName.MESSAGE_CONSTRAINTS); + } + return SubjectName.PLACEHOLDER; + } + + + public static ProjectType parseProjectType(String type) throws ParseException { + requireNonNull(type); + String trimmedType = type.trim(); + if (!SubjectName.isValidSubjectName(trimmedType)) { + throw new ParseException(SubjectName.MESSAGE_CONSTRAINTS); + } + return ProjectType.PLACEHOLDER; + } + + /** + * Parses {@code Collection tags} into a {@code Set}. + */ + public static Set parseTags(Collection tags) throws ParseException { + requireNonNull(tags); + final Set tagSet = new HashSet<>(); + for (String tagName : tags) { + tagSet.add(parseTag(tagName)); + } + return tagSet; + } +} diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index ac409fc94e3..2d45df58992 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -11,13 +11,13 @@ public class CliSyntax { public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); - - /* Entity Types */ - // Can change to enum. Just following the above convention - // Or maybe we can define an EntityType class? + public static final Prefix PREFIX_ORGANISATION = new Prefix("o/"); + public static final Prefix PREFIX_SPECIALISATION = new Prefix("s/"); + public static final Prefix PREFIX_PROJECT_NAME = new Prefix("pn/"); + public static final Prefix PREFIX_PROJECT_TYPE = new Prefix("pt/"); + public static final Prefix PREFIX_LOCATION = new Prefix("l/"); public static final String ENTITY_ISSUE = "issue"; public static final String ENTITY_MENTOR = "mentor"; public static final String ENTITY_PARTICIPANT = "participant"; public static final String ENTITY_TEAM = "team"; - } diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 522b93081cc..00b33c68962 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -18,7 +18,7 @@ public class DeleteCommandParser implements Parser { */ public DeleteCommand parse(String args) throws ParseException { try { - Index index = ParserUtil.parseIndex(args); + Index index = AlfredParserUtil.parseIndex(args); return new DeleteCommand(index); } catch (ParseException pe) { throw new ParseException( diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteMentorCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteMentorCommandParser.java new file mode 100644 index 00000000000..a6bc896ee89 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteMentorCommandParser.java @@ -0,0 +1,27 @@ +package seedu.address.logic.parser.DeleteCommandParsers; + +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteCommand object + */ +public class DeleteMentorCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns a DeleteCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteCommand parse(String args) throws ParseException { + + /** + * The below is just placeholder code until the Mentor class + * is finalised after which we will replace with actual code. + */ + + return null; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteParticipantCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteParticipantCommandParser.java new file mode 100644 index 00000000000..39d235375b3 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteParticipantCommandParser.java @@ -0,0 +1,29 @@ +package seedu.address.logic.parser.DeleteCommandParsers; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteCommand object + */ +public class DeleteParticipantCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns a DeleteCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteCommand parse(String args) throws ParseException { + + /** + * The below is just placeholder code until the Participant class + * is finalised after which we will replace with actual code. + */ + + return null; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteTeamCommandParser.java new file mode 100644 index 00000000000..1e5691d4080 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParsers/DeleteTeamCommandParser.java @@ -0,0 +1,27 @@ +package seedu.address.logic.parser.DeleteCommandParsers; + +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteCommand object + */ +public class DeleteTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns a DeleteCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteCommand parse(String args) throws ParseException { + + /** + * The below is just placeholder code until the Team class + * is finalised after which we will replace with actual code. + */ + + return null; + } + +} diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 845644b7dea..ae5f3deaa00 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -37,7 +37,7 @@ public EditCommand parse(String args) throws ParseException { Index index; try { - index = ParserUtil.parseIndex(argMultimap.getPreamble()); + index = AlfredParserUtil.parseIndex(argMultimap.getPreamble()); } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } @@ -52,9 +52,6 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); } - if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { - editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); - } parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); if (!editPersonDescriptor.isAnyFieldEdited()) { @@ -76,7 +73,7 @@ private Optional> parseTagsForEdit(Collection tags) throws Pars return Optional.empty(); } Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; - return Optional.of(ParserUtil.parseTags(tagSet)); + return Optional.of(AlfredParserUtil.parseTags(tagSet)); } } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditMentorCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditMentorCommandParser.java new file mode 100644 index 00000000000..48c0492c1e5 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditMentorCommandParser.java @@ -0,0 +1,48 @@ +package seedu.address.logic.parser.EditCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class EditMentorCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + /** + * This is just placeholder code. We will implement proper code + * when the Mentor class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditParticipantCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditParticipantCommandParser.java new file mode 100644 index 00000000000..12d9462fc20 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditParticipantCommandParser.java @@ -0,0 +1,49 @@ +package seedu.address.logic.parser.EditCommandParsers; + +import static java.util.Objects.requireNonNull; +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class EditParticipantCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + /** + * This is just placeholder code. We will implement proper code + * when the Participant class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditTeamCommandParser.java new file mode 100644 index 00000000000..4eabaf52d67 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/EditCommandParsers/EditTeamCommandParser.java @@ -0,0 +1,48 @@ +package seedu.address.logic.parser.EditCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class EditTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + /** + * This is just placeholder code. We will implement proper code + * when the Team class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListMentorCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListMentorCommandParser.java new file mode 100644 index 00000000000..59f51bbb66d --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListMentorCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ListCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ListMentorCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ListMentorCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Mentor class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListParticipantCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListParticipantCommandParser.java new file mode 100644 index 00000000000..e6fbefce573 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListParticipantCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ListCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ListParticipantCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ListParticipantCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Participant class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListTeamCommandParser.java new file mode 100644 index 00000000000..7085b7f71d6 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ListCommandParsers/ListTeamCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ListCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ListTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ListTeamCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Team class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b117acb9c55..9f23a6e163e 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -121,4 +121,4 @@ public static Set parseTags(Collection tags) throws ParseException } return tagSet; } -} +} \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewMentorCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewMentorCommandParser.java new file mode 100644 index 00000000000..0dfb834d45e --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewMentorCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ViewCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ViewMentorCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ViewTeamCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Team class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewParticipantCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewParticipantCommandParser.java new file mode 100644 index 00000000000..48bf185c2b3 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewParticipantCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ViewCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ViewParticipantCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ViewTeamCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Team class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewTeamCommandParser.java new file mode 100644 index 00000000000..0cad38e4321 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ViewCommandParsers/ViewTeamCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.ViewCommandParsers; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.Set; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.AlfredParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new EditCommand object + */ +public class ViewTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditCommand + * and returns an EditCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public EditCommand parse(String args) throws ParseException { + + // The return type of this command will also have to be corrected + // to return a ViewTeamCommand object as designed by John instead of an + // EditCommand Object. + + /** + * This is just placeholder code. We will implement proper code + * when the Team class has been finalised. + */ + + return null; + } + + /** + * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Set} containing zero tags. + */ + private Optional> parseTagsForEdit(Collection tags) throws ParseException { + assert tags != null; + + if (tags.isEmpty()) { + return Optional.empty(); + } + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(AlfredParserUtil.parseTags(tagSet)); + } + +} diff --git a/src/main/java/seedu/address/model/entity/ProjectType.java b/src/main/java/seedu/address/model/entity/ProjectType.java index 950d9a217d2..2a5178a01c6 100644 --- a/src/main/java/seedu/address/model/entity/ProjectType.java +++ b/src/main/java/seedu/address/model/entity/ProjectType.java @@ -1,6 +1,7 @@ package seedu.address.model.entity; public enum ProjectType { + PLACEHOLDER("placeholder"); private final String projectTypeString; diff --git a/src/main/java/seedu/address/model/entity/SubjectName.java b/src/main/java/seedu/address/model/entity/SubjectName.java index 26feb1c510c..f9c176d94b2 100644 --- a/src/main/java/seedu/address/model/entity/SubjectName.java +++ b/src/main/java/seedu/address/model/entity/SubjectName.java @@ -18,8 +18,6 @@ public enum SubjectName { private static final String VALIDATION_REGEX = "^[" + SPECIAL_CHARACTERS + " a-zA-Z" + "]+$"; - - private final String subjectNameString; private SubjectName(String subjectNameString) { diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 557a7a60cd5..f43cae3f1a1 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -21,18 +21,16 @@ public class Person { private final Email email; // Data fields - private final Address address; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { - requireAllNonNull(name, phone, email, address, tags); + public Person(Name name, Phone phone, Email email, Set tags) { + requireAllNonNull(name, phone, email, tags); this.name = name; this.phone = phone; this.email = email; - this.address = address; this.tags.addAll(tags); } @@ -48,10 +46,6 @@ public Email getEmail() { return email; } - public Address getAddress() { - return address; - } - /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -92,14 +86,13 @@ public boolean equals(Object other) { return otherPerson.getName().equals(getName()) && otherPerson.getPhone().equals(getPhone()) && otherPerson.getEmail().equals(getEmail()) - && otherPerson.getAddress().equals(getAddress()) && otherPerson.getTags().equals(getTags()); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); + return Objects.hash(name, phone, email, tags); } @Override @@ -110,8 +103,6 @@ public String toString() { .append(getPhone()) .append(" Email: ") .append(getEmail()) - .append(" Address: ") - .append(getAddress()) .append(" Tags: "); getTags().forEach(builder::append); return builder.toString(); diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..c8ca69d0cbc 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -6,7 +6,6 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -20,22 +19,16 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), getTagSet("friends")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), getTagSet("colleagues", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), getTagSet("neighbours")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), getTagSet("family")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), getTagSet("classmates")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), getTagSet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index a6321cec2ea..52af76e9ca7 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -27,7 +26,6 @@ class JsonAdaptedPerson { private final String name; private final String phone; private final String email; - private final String address; private final List tagged = new ArrayList<>(); /** @@ -35,12 +33,11 @@ class JsonAdaptedPerson { */ @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("email") String email, @JsonProperty("tagged") List tagged) { this.name = name; this.phone = phone; this.email = email; - this.address = address; if (tagged != null) { this.tagged.addAll(tagged); } @@ -53,7 +50,6 @@ public JsonAdaptedPerson(Person source) { name = source.getName().fullName; phone = source.getPhone().value; email = source.getEmail().value; - address = source.getAddress().value; tagged.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -94,16 +90,8 @@ public Person toModelType() throws IllegalValueException { } final Email modelEmail = new Email(email); - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); - } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); - } - final Address modelAddress = new Address(address); - final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelTags); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 0684b088868..85142fe6048 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -47,7 +47,6 @@ public PersonCard(Person person, int displayedIndex) { id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); email.setText(person.getEmail().value); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f08ea32ad55..2a8da41fae8 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -29,7 +29,6 @@