From fe9fe0f879311f1d0b3cd19f07835e9e007b8eb8 Mon Sep 17 00:00:00 2001 From: Putra Danish Date: Thu, 6 Sep 2018 14:39:20 +0800 Subject: [PATCH 01/15] Added confirm/cancel clear option to after clear command --- .../commands/CancelClearCommand.java | 14 +++++ .../addressbook/commands/ClearCommand.java | 6 +- .../commands/ConfirmClearCommand.java | 15 +++++ src/seedu/addressbook/parser/Parser.java | 56 +++++++++---------- 4 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 src/seedu/addressbook/commands/CancelClearCommand.java create mode 100644 src/seedu/addressbook/commands/ConfirmClearCommand.java diff --git a/src/seedu/addressbook/commands/CancelClearCommand.java b/src/seedu/addressbook/commands/CancelClearCommand.java new file mode 100644 index 000000000..66ea3565e --- /dev/null +++ b/src/seedu/addressbook/commands/CancelClearCommand.java @@ -0,0 +1,14 @@ +package seedu.addressbook.commands; + +public class CancelClearCommand extends Command { + + public static final String COMMAND_WORD = "no"; + public static final String MESSAGE_CANCEL = "Address book has not been cleared."; + + public CancelClearCommand() {} + + @Override + public CommandResult execute() { + return new CommandResult(MESSAGE_CANCEL); + } +} \ No newline at end of file diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java index 72468ac27..1d7220732 100644 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ b/src/seedu/addressbook/commands/ClearCommand.java @@ -9,14 +9,12 @@ public class ClearCommand extends Command { public static final String MESSAGE_USAGE = "Clears address book permanently.\n" + "Example: " + COMMAND_WORD; - public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + public static final String MESSAGE_CONFIRM = "Are you sure you want to clear the Address book? Enter yes or no."; public ClearCommand() {} - @Override public CommandResult execute() { - addressBook.clear(); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(MESSAGE_CONFIRM); } } diff --git a/src/seedu/addressbook/commands/ConfirmClearCommand.java b/src/seedu/addressbook/commands/ConfirmClearCommand.java new file mode 100644 index 000000000..493bb087b --- /dev/null +++ b/src/seedu/addressbook/commands/ConfirmClearCommand.java @@ -0,0 +1,15 @@ +package seedu.addressbook.commands; + +public class ConfirmClearCommand extends Command { + + public static final String COMMAND_WORD = "yes"; + public static final String MESSAGE_SUCCESS = "Address book has been cleared!"; + + public ConfirmClearCommand() {} + + @Override + public CommandResult execute() { + addressBook.clear(); + return new CommandResult(MESSAGE_SUCCESS); + } +} \ No newline at end of file diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 25c412f6b..d4aaf1734 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -11,17 +11,7 @@ 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.ViewAllCommand; -import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.*; import seedu.addressbook.data.exception.IllegalValueException; /** @@ -75,33 +65,39 @@ public Command parseCommand(String userInput) { switch (commandWord) { - case AddCommand.COMMAND_WORD: - return prepareAdd(arguments); + case AddCommand.COMMAND_WORD: + return prepareAdd(arguments); - case DeleteCommand.COMMAND_WORD: - return prepareDelete(arguments); + case DeleteCommand.COMMAND_WORD: + return prepareDelete(arguments); - case ClearCommand.COMMAND_WORD: - return new ClearCommand(); + case ClearCommand.COMMAND_WORD: + return new ClearCommand(); - case FindCommand.COMMAND_WORD: - return prepareFind(arguments); + case ConfirmClearCommand.COMMAND_WORD: + return new ConfirmClearCommand(); - case ListCommand.COMMAND_WORD: - return new ListCommand(); + case CancelClearCommand.COMMAND_WORD: + return new CancelClearCommand(); - case ViewCommand.COMMAND_WORD: - return prepareView(arguments); + case FindCommand.COMMAND_WORD: + return prepareFind(arguments); - case ViewAllCommand.COMMAND_WORD: - return prepareViewAll(arguments); + case ListCommand.COMMAND_WORD: + return new ListCommand(); - case ExitCommand.COMMAND_WORD: - return new ExitCommand(); + case ViewCommand.COMMAND_WORD: + return prepareView(arguments); - case HelpCommand.COMMAND_WORD: // Fallthrough - default: - return new HelpCommand(); + case ViewAllCommand.COMMAND_WORD: + return prepareViewAll(arguments); + + case ExitCommand.COMMAND_WORD: + return new ExitCommand(); + + case HelpCommand.COMMAND_WORD: // Fallthrough + default: + return new HelpCommand(); } } From f22df67f8715e178cbb68de7b625bd50ddf1f3d5 Mon Sep 17 00:00:00 2001 From: Putra Danish Date: Thu, 6 Sep 2018 14:51:01 +0800 Subject: [PATCH 02/15] Update UserGuide Includes Clear/Cancel command prompt guide --- docs/UserGuide.adoc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..e88e3c636 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -153,9 +153,19 @@ Views all details of the 1st person in the results of the `find` command. == Clearing all entries : `clear` -Clears all entries from the address book. + +Gives user a warning prompt to confirm or cancel deletion of address book.+ Format: `clear` +== Confirm Clear all entries : `yes` + +Clears all entries from the address book. + +Format: `yes` + +== Cancel the clearing of all entries : `no` + +Informs user that the address book has not been cleared. + +Format: `no` + == Exiting the program : `exit` Exits the program. + From ffa8b03bc1d8f355fedd657b51c69b8609c5f8fc Mon Sep 17 00:00:00 2001 From: Matthew Alexander Date: Thu, 6 Sep 2018 20:25:04 +0800 Subject: [PATCH 03/15] Delete by name command --- src/seedu/addressbook/commands/Command.java | 17 ++++++++++++ .../addressbook/commands/DeleteCommand.java | 6 +++-- src/seedu/addressbook/parser/Parser.java | 27 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index 2ff8f1575..eb494ab34 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -15,6 +15,7 @@ public class Command { protected AddressBook addressBook; protected List relevantPersons; private int targetIndex = -1; + private String name = ""; /** * @param targetIndex last visible listing index of the target person @@ -23,6 +24,8 @@ public Command(int targetIndex) { this.setTargetIndex(targetIndex); } + public Command(String name) { this.name = name; } + protected Command() { } @@ -57,6 +60,7 @@ public void setData(AddressBook addressBook, List rele * @throws IndexOutOfBoundsException if the target index is out of bounds of the last viewed listing */ protected ReadOnlyPerson getTargetPerson() throws IndexOutOfBoundsException { + if (getTargetIndex() == -1) { setTargetIndex(getTargetIndexByName(this.name)); } // getTargetIndex == -1, DeleteCommand(name) return relevantPersons.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET); } @@ -67,4 +71,17 @@ public int getTargetIndex() { public void setTargetIndex(int targetIndex) { this.targetIndex = targetIndex; } + + public int getTargetIndexByName(String name) { + int targetIndex = DISPLAYED_INDEX_OFFSET; + + for (ReadOnlyPerson person : relevantPersons) { + if (person.getName().toString().equals(name)) { + return targetIndex; + } + targetIndex++; + } + + return targetIndex; + } } diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 493d75da6..0180f650e 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -11,10 +11,11 @@ public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; + public static final String COMMAND_WORD_STRING = "delete_name"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the person identified by the index number used in the last person listing.\n" - + "Parameters: INDEX\n" + + "Parameters: INDEX/NAME\n" + "Example: " + COMMAND_WORD + " 1"; public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; @@ -24,6 +25,8 @@ public DeleteCommand(int targetVisibleIndex) { super(targetVisibleIndex); } + public DeleteCommand(String name) { super(name); } + @Override public CommandResult execute() { @@ -31,7 +34,6 @@ public CommandResult execute() { final ReadOnlyPerson target = getTargetPerson(); addressBook.removePerson(target); return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, target)); - } catch (IndexOutOfBoundsException ie) { return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } catch (PersonNotFoundException pnfe) { diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 25c412f6b..41eea9884 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -81,6 +81,9 @@ public Command parseCommand(String userInput) { case DeleteCommand.COMMAND_WORD: return prepareDelete(arguments); + case DeleteCommand.COMMAND_WORD_STRING: + return prepareDeleteWithName(arguments); + case ClearCommand.COMMAND_WORD: return new ClearCommand(); @@ -176,6 +179,15 @@ private Command prepareDelete(String args) { } } + private Command prepareDeleteWithName(String args) { + try { + final String name = parseArgsAsName(args); + return new DeleteCommand(name); + } catch (ParseException pe) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE)); + } + } + /** * Parses arguments in the context of the view command. * @@ -231,6 +243,21 @@ private int parseArgsAsDisplayedIndex(String args) throws ParseException, Number } + /** + * Parses arguments string to get the name of the person + * + * @param args arguments string to parse as name + * @return name + * @throws ParseException if no region of args string can be found for name + */ + private String parseArgsAsName(String args) throws ParseException { + final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim()); + if (!matcher.matches()) { + throw new ParseException("Could not find name to parse"); + } + return matcher.group(); + } + /** * Parses arguments in the context of the find person command. * From d3d0e5523359e23ccd3190518d9dca55ee230dee Mon Sep 17 00:00:00 2001 From: Matthew Alexander Date: Thu, 6 Sep 2018 21:41:24 +0800 Subject: [PATCH 04/15] Added user guide for new delete_name command --- docs/UserGuide.adoc | 23 ++++++++++++++++++- src/seedu/addressbook/commands/Command.java | 2 +- .../addressbook/commands/DeleteCommand.java | 4 +--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..5fc3a7015 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -91,7 +91,7 @@ Returns `John Doe` but not `john`. * `find Betsy Tim John` + Returns Any person having names `Betsy`, `Tim`, or `John`. -== Deleting a person : `delete` +== Deleting a person by index: `delete` Deletes the specified person from the address book. Irreversible. + Format: `delete INDEX` @@ -111,6 +111,27 @@ Deletes the 2nd person in the address book. `delete 1` + Deletes the 1st person in the results of the `find` command. +== Deleting a person by name: `delete_name` + +Deletes the specified person from the address book after indexing other commands. Irreversible. + +Format: `delete NAME` + +**** +Deletes the person by `NAME` not case sensitive. +`NAME` refers to the full name of the person. +**** + +Examples: + +* `list` + +`delete_name Matthew Alexander` + +Deletes the Matthew Alexander in the address book. + +* `find Betsy` + +`delete_name Betsy` + +Deletes the 1st person in the results of the `find` command. + + == View non-private details of a person : `view` Displays the non-private details of the specified person. + diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index eb494ab34..3adc8c538 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -76,7 +76,7 @@ public int getTargetIndexByName(String name) { int targetIndex = DISPLAYED_INDEX_OFFSET; for (ReadOnlyPerson person : relevantPersons) { - if (person.getName().toString().equals(name)) { + if (person.getName().toString().equalsIgnoreCase(name)) { return targetIndex; } targetIndex++; diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 0180f650e..323b1dab3 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -21,9 +21,7 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; - public DeleteCommand(int targetVisibleIndex) { - super(targetVisibleIndex); - } + public DeleteCommand(int targetVisibleIndex) { super(targetVisibleIndex); } public DeleteCommand(String name) { super(name); } From 07b409a1ea2a9205ee7d5ffbb743c332f501ed0b Mon Sep 17 00:00:00 2001 From: Ong Wee Keong Date: Fri, 7 Sep 2018 10:58:35 +0800 Subject: [PATCH 05/15] added nonsense --- README.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.adoc b/README.adoc index 419faa5ce..2c9643a9e 100644 --- a/README.adoc +++ b/README.adoc @@ -25,3 +25,6 @@ The full list of contributors for se-edu can be found https://se-edu.github.io/T * *Bug reports, Suggestions* : Post in our https://github.com/se-edu/addressbook-level2/issues[issue tracker] if you noticed bugs or have suggestions on how to improve. * *Contributing* : We welcome pull requests. Follow the process described https://github.com/oss-generic/process[here] + + +i am adding stuff that is not relevant. \ No newline at end of file From ba96540accaf8b82b5685531f6d31dcc63d9b183 Mon Sep 17 00:00:00 2001 From: Ong Wee Keong Date: Fri, 7 Sep 2018 11:06:02 +0800 Subject: [PATCH 06/15] deleted nonsense --- README.adoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.adoc b/README.adoc index 2c9643a9e..50d115650 100644 --- a/README.adoc +++ b/README.adoc @@ -26,5 +26,3 @@ The full list of contributors for se-edu can be found https://se-edu.github.io/T if you noticed bugs or have suggestions on how to improve. * *Contributing* : We welcome pull requests. Follow the process described https://github.com/oss-generic/process[here] - -i am adding stuff that is not relevant. \ No newline at end of file From 2a5b474ef8ffb78930a1b5fe90d498dba29b37ab Mon Sep 17 00:00:00 2001 From: Harun Date: Fri, 7 Sep 2018 18:57:00 +0800 Subject: [PATCH 07/15] added total command and edited user guide --- docs/UserGuide.adoc | 5 ++++ .../addressbook/commands/TotalCommand.java | 27 +++++++++++++++++++ src/seedu/addressbook/data/AddressBook.java | 6 +++++ .../data/person/UniquePersonList.java | 8 ++++++ src/seedu/addressbook/parser/Parser.java | 15 +++-------- 5 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/seedu/addressbook/commands/TotalCommand.java diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..d361bc114 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -67,6 +67,11 @@ Examples: * `add John Doe p/98765432 e/johnd@gmail.com a/John street, block 123, #01-01` * `add Betsy Crowe pp/1234567 e/betsycrowe@gmail.com pa/Newgate Prison t/criminal t/friend` +== Showing current number of contacts : `total` + +Shows the current total number of contacts in the address book, without showing the names. + +Format: `total` + == Listing all persons : `list` Shows a list of all persons, along with their non-private details, in the address book. + diff --git a/src/seedu/addressbook/commands/TotalCommand.java b/src/seedu/addressbook/commands/TotalCommand.java new file mode 100644 index 000000000..87f241db2 --- /dev/null +++ b/src/seedu/addressbook/commands/TotalCommand.java @@ -0,0 +1,27 @@ +package seedu.addressbook.commands; + +import seedu.addressbook.data.person.ReadOnlyPerson; + +import java.util.List; + + +/** + * Shows current total number of contacts in book. + */ +public class TotalCommand extends Command { + + public static final String COMMAND_WORD = "total"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Displays the current number of contacts in the AB.\n" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_SUCCESS = " Contact(s) found"; + + + @Override + public CommandResult execute() { + int TotalContacts = addressBook.total(); + return new CommandResult(TotalContacts + "" + MESSAGE_SUCCESS); + } +} diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 537d35c89..b90c7d0b5 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -61,6 +61,12 @@ public void clear() { allPersons.clear(); } + /** + * Returns total number of contacts + */ + + public int total() {return allPersons.total();} + /** * Returns a new UniquePersonList of all persons in the address book at the time of the call. */ diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index d7acd8b4a..941b772a9 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -110,6 +110,14 @@ public void add(Person toAdd) throws DuplicatePersonException { internalList.add(toAdd); } + /** + * Gets total contacts + */ + + public int total(){ + return internalList.size(); + } + /** * Removes the equivalent person from the list. * diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 25c412f6b..01490f672 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -11,17 +11,7 @@ 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.ViewAllCommand; -import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.*; import seedu.addressbook.data.exception.IllegalValueException; /** @@ -96,6 +86,9 @@ public Command parseCommand(String userInput) { case ViewAllCommand.COMMAND_WORD: return prepareViewAll(arguments); + case TotalCommand.COMMAND_WORD: + return new TotalCommand(); + case ExitCommand.COMMAND_WORD: return new ExitCommand(); From 871908be46ae72305e6009f30298c823d3fd6619 Mon Sep 17 00:00:00 2001 From: Ong Wee Keong Date: Thu, 13 Sep 2018 15:31:05 +0800 Subject: [PATCH 08/15] Added further constraints to 'add' feature --- docs/UserGuide.adoc | 2 ++ src/seedu/addressbook/data/person/ReadOnlyPerson.java | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index e215a3c24..eb5f82fd5 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -59,6 +59,8 @@ items with `...` after them can have multiple instances. Order of parameters are Put a `p` before the phone / email / address prefixes to mark it as `private`. `private` details can only be seen using the `viewall` command. +Persons with duplicate primary key identity fields (Same name AND same phone number/email, or even different name with same phone number AND email) will not be allowed. + Persons can have any number of tags (including 0). **** diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 1493f0a2b..9ed67fff3 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -22,13 +22,17 @@ public interface ReadOnlyPerson { Set getTags(); /** - * Returns true if both persons have the same identity fields (name and telephone). + * Returns true if both persons have the same identity fields (name and telephone and/or email). + * Will also return true if a different person has the same telephone and email. */ default boolean isSamePerson(ReadOnlyPerson other) { return (other == this) || (other != null - && other.getName().equals(this.getName()) - && other.getPhone().equals(this.getPhone())); + && (other.getName().equals(this.getName()) + && (other.getPhone().equals(this.getPhone()) + || other.getEmail().equals(this.getEmail()))) + || other.getPhone().equals(this.getPhone()) + && other.getEmail().equals(this.getEmail())); } /** From 9eddf0d42294ce8a1b04a06651dee332ea2a6783 Mon Sep 17 00:00:00 2001 From: Ong Wee Keong Date: Thu, 13 Sep 2018 15:34:21 +0800 Subject: [PATCH 09/15] Edited user guide --- docs/UserGuide.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index eb5f82fd5..a7f503c31 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -59,7 +59,8 @@ items with `...` after them can have multiple instances. Order of parameters are Put a `p` before the phone / email / address prefixes to mark it as `private`. `private` details can only be seen using the `viewall` command. -Persons with duplicate primary key identity fields (Same name AND same phone number/email, or even different name with same phone number AND email) will not be allowed. +Persons with duplicate primary key identity fields (Same name AND same phone number/email, or even different +name with same phone number AND email) will not be allowed. Persons can have any number of tags (including 0). **** From 7e71dcaafede736946c87604c641ca03e9068605 Mon Sep 17 00:00:00 2001 From: Matthew Alexander Date: Thu, 13 Sep 2018 16:43:33 +0800 Subject: [PATCH 10/15] Revert "[W5.11][CS2113-AY1819S1-F10-3]Ong Wee Keong" From 4ebc7f0ec193f16d6f3de2019f4b445022b30983 Mon Sep 17 00:00:00 2001 From: Ong Wee Keong Date: Thu, 13 Sep 2018 16:51:39 +0800 Subject: [PATCH 11/15] Added restrictions to 'add' command & removed duplicate labels --- src/seedu/addressbook/data/person/ReadOnlyPerson.java | 8 ++++---- src/seedu/addressbook/parser/Parser.java | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/seedu/addressbook/data/person/ReadOnlyPerson.java b/src/seedu/addressbook/data/person/ReadOnlyPerson.java index 9ed67fff3..7c228565a 100644 --- a/src/seedu/addressbook/data/person/ReadOnlyPerson.java +++ b/src/seedu/addressbook/data/person/ReadOnlyPerson.java @@ -28,11 +28,11 @@ public interface ReadOnlyPerson { default boolean isSamePerson(ReadOnlyPerson other) { return (other == this) || (other != null - && (other.getName().equals(this.getName()) + && other.getPhone().equals(this.getPhone()) + && other.getEmail().equals(this.getEmail()) + || (other.getName().equals(this.getName()) && (other.getPhone().equals(this.getPhone()) - || other.getEmail().equals(this.getEmail()))) - || other.getPhone().equals(this.getPhone()) - && other.getEmail().equals(this.getEmail())); + || other.getEmail().equals(this.getEmail())))); } /** diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index c1eabdfa5..85589ae9f 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -86,11 +86,6 @@ public Command parseCommand(String userInput) { case FindCommand.COMMAND_WORD: return prepareFind(arguments); - case TotalCommand.COMMAND_WORD: - return new TotalCommand(); - - case ExitCommand.COMMAND_WORD: - return new ExitCommand(); case ListCommand.COMMAND_WORD: return new ListCommand(); From f705fc028dff6254ed5c1853cde85c104e3cabcd Mon Sep 17 00:00:00 2001 From: ShreyasKp Date: Thu, 13 Sep 2018 19:18:23 +0800 Subject: [PATCH 12/15] add functionality to list top five persons --- .../addressbook/commands/TopFiveCommand.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/seedu/addressbook/commands/TopFiveCommand.java diff --git a/src/seedu/addressbook/commands/TopFiveCommand.java b/src/seedu/addressbook/commands/TopFiveCommand.java new file mode 100644 index 000000000..81bd42198 --- /dev/null +++ b/src/seedu/addressbook/commands/TopFiveCommand.java @@ -0,0 +1,34 @@ +package seedu.addressbook.commands; + +import seedu.addressbook.data.person.ReadOnlyPerson; + +import java.util.ArrayList; +import java.util.List; + +/** + * Lists the first five persons in the address book to the user. + */ + +public class TopFiveCommand extends Command{ + public static final String COMMAND_WORD = "topFive"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Displays first five persons in the address book as a list with index numbers.\n" + + "Example: " + COMMAND_WORD; + + @Override + public CommandResult execute() { + List allPersons = addressBook.getAllPersons().immutableListView(); + int size = allPersons.size(); + if(size < 5) { + return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons); + } + else { + List toBeDisplayed = new ArrayList<>(); + for(int i = 0; i < 5; i++) { + toBeDisplayed.add(i, allPersons.get(i)); + } + return new CommandResult(getMessageForPersonListShownSummary(toBeDisplayed), toBeDisplayed); + } + } +} From a8529c55a2e6bb4a7ae302b8f8df99ea35c624e5 Mon Sep 17 00:00:00 2001 From: ShreyasKp Date: Thu, 13 Sep 2018 19:22:57 +0800 Subject: [PATCH 13/15] update user guide and parser files --- docs/UserGuide.adoc | 5 +++++ src/seedu/addressbook/parser/Parser.java | 3 +++ .../seedu/addressbook/parser/ParserTest.java | 18 +++++++----------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 44121a3d1..f1371f29d 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -72,6 +72,11 @@ Examples: Shows a list of all persons, along with their non-private details, in the address book. + Format: `list` +== Listing first five persons : `topFive` + +Shows a list of the first five persons, along with their non-private details, in the address book. + +Format: `topFive` + == Finding all persons containing any keyword in their name: `find` Finds persons whose names contain any of the given keywords. + diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 8b4f0b589..f663e10fb 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -89,6 +89,9 @@ public Command parseCommand(String userInput) { case ListCommand.COMMAND_WORD: return new ListCommand(); + case TopFiveCommand.COMMAND_WORD: + return new TopFiveCommand(); + case ViewCommand.COMMAND_WORD: return prepareView(arguments); diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 8b7259950..2129dea51 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -12,17 +12,7 @@ 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.*; import seedu.addressbook.data.exception.IllegalValueException; import seedu.addressbook.data.person.Address; import seedu.addressbook.data.person.Email; @@ -81,6 +71,12 @@ public void parse_listCommand_parsedCorrectly() { parseAndAssertCommandType(input, ListCommand.class); } + @Test + public void parse_topFiveCommand_parsedCorrectly() { + final String input = "topFive"; + parseAndAssertCommandType(input, TopFiveCommand.class); + } + @Test public void parse_exitCommand_parsedCorrectly() { final String input = "exit"; From 1ee73fae525e86c5397b83977724e1f00644c4b3 Mon Sep 17 00:00:00 2001 From: ShreyasKp Date: Thu, 13 Sep 2018 21:42:09 +0800 Subject: [PATCH 14/15] update ParserTest --- test/java/seedu/addressbook/parser/ParserTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 2129dea51..8a944bae5 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -71,11 +71,11 @@ public void parse_listCommand_parsedCorrectly() { parseAndAssertCommandType(input, ListCommand.class); } - @Test - public void parse_topFiveCommand_parsedCorrectly() { - final String input = "topFive"; - parseAndAssertCommandType(input, TopFiveCommand.class); - } + //@Test + //public void parse_topFiveCommand_parsedCorrectly() { + // final String input = "topFive"; + // parseAndAssertCommandType(input, TopFiveCommand.class); + //} @Test public void parse_exitCommand_parsedCorrectly() { From 9951c4231a2f746f6fa8b908fcc272f8cf6bbbe5 Mon Sep 17 00:00:00 2001 From: ShreyasKp Date: Thu, 13 Sep 2018 22:12:30 +0800 Subject: [PATCH 15/15] remove ParserTest edit --- test/java/seedu/addressbook/parser/ParserTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index 8a944bae5..2129dea51 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -71,11 +71,11 @@ public void parse_listCommand_parsedCorrectly() { parseAndAssertCommandType(input, ListCommand.class); } - //@Test - //public void parse_topFiveCommand_parsedCorrectly() { - // final String input = "topFive"; - // parseAndAssertCommandType(input, TopFiveCommand.class); - //} + @Test + public void parse_topFiveCommand_parsedCorrectly() { + final String input = "topFive"; + parseAndAssertCommandType(input, TopFiveCommand.class); + } @Test public void parse_exitCommand_parsedCorrectly() {