From d6fa04cf5ae73a557de0acf8bdd9fb7651c884cf Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Fri, 22 Sep 2017 08:16:49 +0800 Subject: [PATCH 01/11] added NFR, isMutating() --- doc/DeveloperGuide.md | 2 +- src/seedu/addressbook/commands/AddCommand.java | 3 +++ src/seedu/addressbook/commands/ClearCommand.java | 4 ++++ src/seedu/addressbook/commands/Command.java | 4 ++++ src/seedu/addressbook/commands/DeleteCommand.java | 4 ++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/DeveloperGuide.md b/doc/DeveloperGuide.md index c82c3afb9..0db91800d 100644 --- a/doc/DeveloperGuide.md +++ b/doc/DeveloperGuide.md @@ -80,7 +80,7 @@ Use case ends. 2. Should be able to hold up to 1000 persons. 3. Should come with automated unit tests and open source code. 4. Should favor DOS style commands over Unix-style commands. - +5. Response should be within 2 seconds ## Appendix D : Glossary ##### Mainstream OS diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index b0f202d42..aee69702b 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -67,4 +67,7 @@ public CommandResult execute() { } } + public boolean isMutating() { + return true; + } } diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java index 330146aaa..1cb858763 100644 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ b/src/seedu/addressbook/commands/ClearCommand.java @@ -16,4 +16,8 @@ public CommandResult execute() { addressBook.clear(); return new CommandResult(MESSAGE_SUCCESS); } + + public boolean isMutating() { + return true; + } } diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index ccd4fcbf4..8a1a30b66 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -65,4 +65,8 @@ public int getTargetIndex() { public void setTargetIndex(int targetIndex) { this.targetIndex = targetIndex; } + + public boolean isMutating() { + return false; + } } diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 1dd78f85e..9ed99d260 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -39,4 +39,8 @@ public CommandResult execute() { } } + public boolean isMutating() { + return true; + } + } From 3ca39eb82657e65e333bfb1e97e8f2591c4d066b Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Fri, 22 Sep 2017 08:29:46 +0800 Subject: [PATCH 02/11] added printable interface --- src/seedu/addressbook/data/person/Address.java | 6 +++++- src/seedu/addressbook/data/person/Printable.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/seedu/addressbook/data/person/Printable.java diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 8ac726444..cac8ea798 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -6,7 +6,7 @@ * Represents a Person's address in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} */ -public class Address { +public class Address implements Printable { public static final String EXAMPLE = "123, some street"; public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses can be in any format"; @@ -55,4 +55,8 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } + + public String getPrintableString(Printable p, Printable p1, Printable p2) { + return value; + } } \ No newline at end of file diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java new file mode 100644 index 000000000..4f2aa441b --- /dev/null +++ b/src/seedu/addressbook/data/person/Printable.java @@ -0,0 +1,5 @@ +package seedu.addressbook.data.person; + +public interface Printable { + String getPrintableString(Printable p, Printable p1, Printable p2); +} From 90efdb9c4cbaae3004f42915d0add4bbc66f8cf6 Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Fri, 22 Sep 2017 08:30:11 +0800 Subject: [PATCH 03/11] made font changes in gui --- src/seedu/addressbook/ui/Gui.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/seedu/addressbook/ui/Gui.java b/src/seedu/addressbook/ui/Gui.java index ed21989a4..6be44fa0c 100644 --- a/src/seedu/addressbook/ui/Gui.java +++ b/src/seedu/addressbook/ui/Gui.java @@ -6,6 +6,8 @@ import seedu.addressbook.logic.Logic; import seedu.addressbook.Main; +import javafx.scene.text.Font; +import javafx.scene.text.Text; import java.io.File; import java.io.IOException; @@ -42,6 +44,12 @@ private MainWindow createMainWindow(Stage stage, Stoppable mainApp) throws IOExc */ loader.setLocation(Main.class.getResource("ui/mainwindow.fxml")); + //set font + Text text = new Text(); + text.setText("Test"); + text.setFont(Font.font("Arial",16)); + + stage.setTitle(version); stage.setScene(new Scene(loader.load(), INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT)); stage.show(); From 0cfcb9ed53b88f231d878165d843f8a72db44046 Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sun, 24 Sep 2017 16:11:36 +0800 Subject: [PATCH 04/11] Revert "made font changes in gui" This reverts commit 90efdb9c4cbaae3004f42915d0add4bbc66f8cf6. --- src/seedu/addressbook/ui/Gui.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/seedu/addressbook/ui/Gui.java b/src/seedu/addressbook/ui/Gui.java index 6be44fa0c..ed21989a4 100644 --- a/src/seedu/addressbook/ui/Gui.java +++ b/src/seedu/addressbook/ui/Gui.java @@ -6,8 +6,6 @@ import seedu.addressbook.logic.Logic; import seedu.addressbook.Main; -import javafx.scene.text.Font; -import javafx.scene.text.Text; import java.io.File; import java.io.IOException; @@ -44,12 +42,6 @@ private MainWindow createMainWindow(Stage stage, Stoppable mainApp) throws IOExc */ loader.setLocation(Main.class.getResource("ui/mainwindow.fxml")); - //set font - Text text = new Text(); - text.setText("Test"); - text.setFont(Font.font("Arial",16)); - - stage.setTitle(version); stage.setScene(new Scene(loader.load(), INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT)); stage.show(); From 950807d878df2a207ea96f9423081f2b1890d7e5 Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sun, 24 Sep 2017 16:12:22 +0800 Subject: [PATCH 05/11] Revert "added printable interface" This reverts commit 3ca39eb82657e65e333bfb1e97e8f2591c4d066b. --- src/seedu/addressbook/data/person/Address.java | 6 +----- src/seedu/addressbook/data/person/Printable.java | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 src/seedu/addressbook/data/person/Printable.java diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index cac8ea798..8ac726444 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -6,7 +6,7 @@ * Represents a Person's address in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} */ -public class Address implements Printable { +public class Address { public static final String EXAMPLE = "123, some street"; public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses can be in any format"; @@ -55,8 +55,4 @@ public int hashCode() { public boolean isPrivate() { return isPrivate; } - - public String getPrintableString(Printable p, Printable p1, Printable p2) { - return value; - } } \ No newline at end of file diff --git a/src/seedu/addressbook/data/person/Printable.java b/src/seedu/addressbook/data/person/Printable.java deleted file mode 100644 index 4f2aa441b..000000000 --- a/src/seedu/addressbook/data/person/Printable.java +++ /dev/null @@ -1,5 +0,0 @@ -package seedu.addressbook.data.person; - -public interface Printable { - String getPrintableString(Printable p, Printable p1, Printable p2); -} From 423ee81096d0f157f20b1c0edcb014beb04635ed Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sun, 24 Sep 2017 16:12:34 +0800 Subject: [PATCH 06/11] Revert "added NFR, isMutating()" This reverts commit d6fa04cf5ae73a557de0acf8bdd9fb7651c884cf. --- doc/DeveloperGuide.md | 2 +- src/seedu/addressbook/commands/AddCommand.java | 3 --- src/seedu/addressbook/commands/ClearCommand.java | 4 ---- src/seedu/addressbook/commands/Command.java | 4 ---- src/seedu/addressbook/commands/DeleteCommand.java | 4 ---- 5 files changed, 1 insertion(+), 16 deletions(-) diff --git a/doc/DeveloperGuide.md b/doc/DeveloperGuide.md index 0db91800d..c82c3afb9 100644 --- a/doc/DeveloperGuide.md +++ b/doc/DeveloperGuide.md @@ -80,7 +80,7 @@ Use case ends. 2. Should be able to hold up to 1000 persons. 3. Should come with automated unit tests and open source code. 4. Should favor DOS style commands over Unix-style commands. -5. Response should be within 2 seconds + ## Appendix D : Glossary ##### Mainstream OS diff --git a/src/seedu/addressbook/commands/AddCommand.java b/src/seedu/addressbook/commands/AddCommand.java index aee69702b..b0f202d42 100644 --- a/src/seedu/addressbook/commands/AddCommand.java +++ b/src/seedu/addressbook/commands/AddCommand.java @@ -67,7 +67,4 @@ public CommandResult execute() { } } - public boolean isMutating() { - return true; - } } diff --git a/src/seedu/addressbook/commands/ClearCommand.java b/src/seedu/addressbook/commands/ClearCommand.java index 1cb858763..330146aaa 100644 --- a/src/seedu/addressbook/commands/ClearCommand.java +++ b/src/seedu/addressbook/commands/ClearCommand.java @@ -16,8 +16,4 @@ public CommandResult execute() { addressBook.clear(); return new CommandResult(MESSAGE_SUCCESS); } - - public boolean isMutating() { - return true; - } } diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index 8a1a30b66..ccd4fcbf4 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -65,8 +65,4 @@ public int getTargetIndex() { public void setTargetIndex(int targetIndex) { this.targetIndex = targetIndex; } - - public boolean isMutating() { - return false; - } } diff --git a/src/seedu/addressbook/commands/DeleteCommand.java b/src/seedu/addressbook/commands/DeleteCommand.java index 9ed99d260..1dd78f85e 100644 --- a/src/seedu/addressbook/commands/DeleteCommand.java +++ b/src/seedu/addressbook/commands/DeleteCommand.java @@ -39,8 +39,4 @@ public CommandResult execute() { } } - public boolean isMutating() { - return true; - } - } From 176b36f8d9a21d9b5a7a79247eb8b14cd9e22ef8 Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sun, 24 Sep 2017 16:14:42 +0800 Subject: [PATCH 07/11] add sort command --- src/seedu/addressbook/commands/SortCommand.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/seedu/addressbook/commands/SortCommand.java diff --git a/src/seedu/addressbook/commands/SortCommand.java b/src/seedu/addressbook/commands/SortCommand.java new file mode 100644 index 000000000..8036e7eeb --- /dev/null +++ b/src/seedu/addressbook/commands/SortCommand.java @@ -0,0 +1,4 @@ +package seedu.addressbook.commands; + +public class SortCommand { +} From a33f339439c28f73e469433e574999478b117786 Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sun, 24 Sep 2017 16:27:04 +0800 Subject: [PATCH 08/11] added sort --- doc/UserGuide.md | 5 +++++ .../addressbook/commands/HelpCommand.java | 1 + .../addressbook/commands/SortCommand.java | 21 +++++++++++++++++-- src/seedu/addressbook/data/AddressBook.java | 8 +++++++ .../data/person/UniquePersonList.java | 11 ++++++++++ src/seedu/addressbook/parser/Parser.java | 3 +++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/UserGuide.md b/doc/UserGuide.md index 3e4baae95..1bbd1ca63 100644 --- a/doc/UserGuide.md +++ b/doc/UserGuide.md @@ -103,6 +103,11 @@ Format: `clear` Exits the program.
Format: `exit` +## Sorting the entries alphabetically by name : `sort` +Sorts addressbook alphabetically
+Format: `sort` + + ## Saving the data Address book data are saved in the hard disk automatically after any command that changes the data.
There is no need to save manually. diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index ef2ed7d0e..0c8006167 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -16,6 +16,7 @@ public class HelpCommand extends Command { + "\n" + ClearCommand.MESSAGE_USAGE + "\n" + FindCommand.MESSAGE_USAGE + "\n" + ListCommand.MESSAGE_USAGE + + "\n" + SortCommand.MESSAGE_USAGE + "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE diff --git a/src/seedu/addressbook/commands/SortCommand.java b/src/seedu/addressbook/commands/SortCommand.java index 8036e7eeb..b50b9e089 100644 --- a/src/seedu/addressbook/commands/SortCommand.java +++ b/src/seedu/addressbook/commands/SortCommand.java @@ -1,4 +1,21 @@ package seedu.addressbook.commands; -public class SortCommand { -} +/* +* sorts the addressbook + */ +public class SortCommand extends Command{ + public static final String COMMAND_WORD = "sort"; + public static final String MESSAGE_USAGE = "Sort the Addressbook alphabetically.\n" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_SUCCESS = "Address book has been sorted!"; + + public SortCommand() {} + + + @Override + public CommandResult execute() { + addressBook.sort(); + return new CommandResult(MESSAGE_SUCCESS); + } +} \ No newline at end of file diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index b3ab0dfeb..b78588f81 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -158,4 +158,12 @@ public int hashCode() { // use this method for custom fields hashing instead of implementing your own return Objects.hash(allPersons, allTags); } + + /* + * sorts the list alphabetically + */ + public void sort() { + allPersons.sort(); + + } } diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index c4848a1b4..4c3be7af9 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -131,4 +131,15 @@ public int hashCode() { return internalList.hashCode(); } + /* + * sorts list alphabetically + */ + public void sort() { + Collections.sort(internalList, new Comparator() { + @Override + public int compare(Person o1, Person o2) { + return o1.getName().fullName.compareTo(o2.getName().fullName); + } + }); + } } diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 58f4f7e6c..2cd0f5a55 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -72,6 +72,9 @@ public Command parseCommand(String userInput) { case ListCommand.COMMAND_WORD: return new ListCommand(); + case SortCommand.COMMAND_WORD: + return new SortCommand(); + case ViewCommand.COMMAND_WORD: return prepareView(arguments); From deeae6f36260f3dd93b9f0e30114a7e08bf1857f Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Fri, 13 Oct 2017 12:16:48 +0800 Subject: [PATCH 09/11] add junit test for sort --- .../seedu/addressbook/logic/LogicTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 7efa921ca..9de254baa 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -201,6 +201,19 @@ public void execute_list_showsAllPersons() throws Exception { expectedList); } + @Test + public void execute_sort() throws Exception { + // prepare expectations + TestDataHelper helper = new TestDataHelper(); + addressBook.addPerson(helper.generatePerson(3, true)); + addressBook.addPerson(helper.generatePerson(2, true)); + addressBook.addPerson(helper.generatePerson(1, true)); + AddressBook expectedAB = helper.sort(addressBook); + + //verify results + assertCommandBehavior("sort", SortCommand.MESSAGE_SUCCESS,expectedAB,false,Collections.emptyList()); + } + @Test public void execute_view_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); @@ -586,6 +599,14 @@ Person generatePersonWithName(String name) throws Exception { new UniqueTagList(new Tag("tag")) ); } + + /* + * sort the addressbook + */ + AddressBook sort(AddressBook addressBook) { + addressBook.sort(); + return addressBook; + } } } From 04e9dd73090ea39248c1a5d74952159cdadd602c Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Fri, 13 Oct 2017 14:02:31 +0800 Subject: [PATCH 10/11] corrected junit tests --- .../seedu/addressbook/logic/LogicTest.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 9de254baa..dfc71e9fc 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -205,10 +205,16 @@ public void execute_list_showsAllPersons() throws Exception { public void execute_sort() throws Exception { // prepare expectations TestDataHelper helper = new TestDataHelper(); - addressBook.addPerson(helper.generatePerson(3, true)); - addressBook.addPerson(helper.generatePerson(2, true)); - addressBook.addPerson(helper.generatePerson(1, true)); - AddressBook expectedAB = helper.sort(addressBook); + Person p1 = helper.generatePerson(4, true); + Person p2 = helper.generatePerson(5, true); + List PersonsInOrder = helper.generatePersonList(p1, p2); + List PersonsNotIO = helper.generatePersonList(p2, p1); + + //set up the expected AB + AddressBook inOrderAB = new AddressBook(); + helper.addToAddressBook(inOrderAB,PersonsInOrder); + helper.addToAddressBook(addressBook,PersonsNotIO); + AddressBook expectedAB = new AddressBook(inOrderAB.getAllPersons(), addressBook.getAllTags()); //verify results assertCommandBehavior("sort", SortCommand.MESSAGE_SUCCESS,expectedAB,false,Collections.emptyList()); @@ -607,6 +613,15 @@ AddressBook sort(AddressBook addressBook) { addressBook.sort(); return addressBook; } - } + /* + * adds and returns the addressbook + */ + AddressBook addToABandReturn(AddressBook addressBook, List personsToAdd) throws Exception{ + for(Person p: personsToAdd){ + addressBook.addPerson(p); + } + return addressBook; + } + } } From 5b4838229d517ca8cfdf710390bdc850de48a2be Mon Sep 17 00:00:00 2001 From: "APPLETEA\\Huijia" Date: Sat, 14 Oct 2017 00:41:11 +0800 Subject: [PATCH 11/11] tidied code and cut out unused methods --- .../seedu/addressbook/logic/LogicTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index dfc71e9fc..21f0d2fbd 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -605,23 +605,5 @@ Person generatePersonWithName(String name) throws Exception { new UniqueTagList(new Tag("tag")) ); } - - /* - * sort the addressbook - */ - AddressBook sort(AddressBook addressBook) { - addressBook.sort(); - return addressBook; - } - - /* - * adds and returns the addressbook - */ - AddressBook addToABandReturn(AddressBook addressBook, List personsToAdd) throws Exception{ - for(Person p: personsToAdd){ - addressBook.addPerson(p); - } - return addressBook; - } } }