From ff6e5ee1de1a92fdacf5f22017db7a13c2814992 Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Mon, 11 Feb 2019 22:04:14 +0800 Subject: [PATCH 1/9] initial commit --- src/seedu/addressbook/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index bc18bed7e..aa50b351a 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -15,7 +15,7 @@ import seedu.addressbook.storage.StorageFile.StorageOperationException; import seedu.addressbook.ui.TextUi; - +// hello world /** * Entry point of the Address Book application. * Initializes the application and starts the interaction with the user. From af71333e560be9ee2b836f17dd470dc44673ffa2 Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 13:00:42 +0800 Subject: [PATCH 2/9] Encapsulation for commandresult member feedbackToUser --- src/seedu/addressbook/Main.java | 1 - src/seedu/addressbook/commands/CommandResult.java | 6 +++++- src/seedu/addressbook/ui/TextUi.java | 2 +- test/java/seedu/addressbook/commands/AddCommandTest.java | 4 ++-- test/java/seedu/addressbook/commands/DeleteCommandTest.java | 2 +- test/java/seedu/addressbook/commands/FindCommandTest.java | 2 +- test/java/seedu/addressbook/commands/ViewCommandTest.java | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index aa50b351a..0d4605798 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -15,7 +15,6 @@ import seedu.addressbook.storage.StorageFile.StorageOperationException; import seedu.addressbook.ui.TextUi; -// hello world /** * Entry point of the Address Book application. * Initializes the application and starts the interaction with the user. diff --git a/src/seedu/addressbook/commands/CommandResult.java b/src/seedu/addressbook/commands/CommandResult.java index 8864681c6..4be0b8f74 100644 --- a/src/seedu/addressbook/commands/CommandResult.java +++ b/src/seedu/addressbook/commands/CommandResult.java @@ -11,7 +11,7 @@ public class CommandResult { /** The feedback message to be shown to the user. Contains a description of the execution result */ - public final String feedbackToUser; + private final String feedbackToUser; /** The list of persons that was produced by the command */ private final List relevantPersons; @@ -33,4 +33,8 @@ public Optional> getRelevantPersons() { return Optional.ofNullable(relevantPersons); } + public String getfeedbackToUser(){ + return this.feedbackToUser; + } + } diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index d30371c70..97afc9cf0 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -129,7 +129,7 @@ public void showResultToUser(CommandResult result) { if (resultPersons.isPresent()) { showPersonListView(resultPersons.get()); } - showToUser(result.feedbackToUser, DIVIDER); + showToUser(result.getfeedbackToUser(), DIVIDER); } /** diff --git a/test/java/seedu/addressbook/commands/AddCommandTest.java b/test/java/seedu/addressbook/commands/AddCommandTest.java index 461017710..5b96cd1d1 100644 --- a/test/java/seedu/addressbook/commands/AddCommandTest.java +++ b/test/java/seedu/addressbook/commands/AddCommandTest.java @@ -126,7 +126,7 @@ public void addCommand_emptyAddressBook_addressBookContainsPerson() { assertTrue(people.contains(p)); assertEquals(1, people.immutableListView().size()); assertFalse(result.getRelevantPersons().isPresent()); - assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, p), result.feedbackToUser); + assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, p), result.getfeedbackToUser()); } @Test @@ -139,7 +139,7 @@ public void addCommand_addressBookAlreadyContainsPerson_addressBookUnmodified() CommandResult result = command.execute(); assertFalse(result.getRelevantPersons().isPresent()); - assertEquals(AddCommand.MESSAGE_DUPLICATE_PERSON, result.feedbackToUser); + assertEquals(AddCommand.MESSAGE_DUPLICATE_PERSON, result.getfeedbackToUser()); UniquePersonList people = book.getAllPersons(); assertTrue(people.contains(p)); assertEquals(1, people.immutableListView().size()); diff --git a/test/java/seedu/addressbook/commands/DeleteCommandTest.java b/test/java/seedu/addressbook/commands/DeleteCommandTest.java index 02a77b0c2..4a6d80d9a 100644 --- a/test/java/seedu/addressbook/commands/DeleteCommandTest.java +++ b/test/java/seedu/addressbook/commands/DeleteCommandTest.java @@ -109,7 +109,7 @@ private void assertCommandBehaviour(DeleteCommand deleteCommand, String expected CommandResult result = deleteCommand.execute(); - assertEquals(expectedMessage, result.feedbackToUser); + assertEquals(expectedMessage, result.getfeedbackToUser()); assertEquals(expectedAddressBook.getAllPersons(), actualAddressBook.getAllPersons()); } diff --git a/test/java/seedu/addressbook/commands/FindCommandTest.java b/test/java/seedu/addressbook/commands/FindCommandTest.java index f21b1e8e7..9e8f162f0 100644 --- a/test/java/seedu/addressbook/commands/FindCommandTest.java +++ b/test/java/seedu/addressbook/commands/FindCommandTest.java @@ -50,7 +50,7 @@ private void assertFindCommandBehavior(String[] keywords, List e FindCommand command = createFindCommand(keywords); CommandResult result = command.execute(); - assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser); + assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.getfeedbackToUser()); } private FindCommand createFindCommand(String[] keywords) { diff --git a/test/java/seedu/addressbook/commands/ViewCommandTest.java b/test/java/seedu/addressbook/commands/ViewCommandTest.java index f2e4d420a..de02dd906 100644 --- a/test/java/seedu/addressbook/commands/ViewCommandTest.java +++ b/test/java/seedu/addressbook/commands/ViewCommandTest.java @@ -143,7 +143,7 @@ private static void assertViewBehavior(Command viewCommand, AddressBook addressB CommandResult result = viewCommand.execute(); // feedback message is as expected and there are no relevant persons returned. - assertEquals(expectedMessage, result.feedbackToUser); + assertEquals(expectedMessage, result.getfeedbackToUser()); assertEquals(Optional.empty(), result.getRelevantPersons()); // addressbook was not modified. From bc48c0930824710450df110534d7deb94e2eba0c Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 13:43:14 +0800 Subject: [PATCH 3/9] Split Address into seprate class BLOCK,STREET,UNIT,POSTAL CODE --- .../addressbook/data/person/Address.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 131d71b46..a9b33bdaa 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -2,6 +2,8 @@ import seedu.addressbook.data.exception.IllegalValueException; +import java.lang.String; + /** * Represents a Person's address in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} @@ -9,12 +11,21 @@ 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"; + public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses must in the format : a/BLOCK, STREET, UNIT, POSTAL CODE "; public static final String ADDRESS_VALIDATION_REGEX = ".+"; public final String value; private boolean isPrivate; + /** + * Class Implementation of BLOCK, STREET, UNIT, POSTAL CODE + * The address string will be split into the sub-address members + */ + private Block blk; + private Street street; + private Unit unit; + private PostalC postalC; + /** * Validates given address. * @@ -27,6 +38,8 @@ public Address(String address, boolean isPrivate) throws IllegalValueException { throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS); } this.value = trimmedAddress; + + splitAddress(value); } /** @@ -36,6 +49,20 @@ public static boolean isValidAddress(String test) { return test.matches(ADDRESS_VALIDATION_REGEX); } + /** + * Splits the address into the sub address BLOCK,STREET,UNIT,POSTAL CODE and + * initialize the class objects associated with the sub-address accordingly + * @param address + */ + public void splitAddress(String address){ + String[] subAddress = address.split(", "); + + blk = new Block(subAddress[0]); + street = new Street(subAddress[1]); + unit = new Unit(subAddress[2]); + postalC = new PostalC(subAddress[3]); + } + @Override public String toString() { return value; From ee1b3fbacc0ce7733e64f546f28f5f010245b9ae Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 13:44:50 +0800 Subject: [PATCH 4/9] class Unit, Street, Block, PostalC added --- src/seedu/addressbook/data/person/Block.java | 13 +++++++++++++ src/seedu/addressbook/data/person/PostalC.java | 13 +++++++++++++ src/seedu/addressbook/data/person/Street.java | 13 +++++++++++++ src/seedu/addressbook/data/person/Unit.java | 13 +++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/seedu/addressbook/data/person/Block.java create mode 100644 src/seedu/addressbook/data/person/PostalC.java create mode 100644 src/seedu/addressbook/data/person/Street.java create mode 100644 src/seedu/addressbook/data/person/Unit.java diff --git a/src/seedu/addressbook/data/person/Block.java b/src/seedu/addressbook/data/person/Block.java new file mode 100644 index 000000000..4b9f1e9be --- /dev/null +++ b/src/seedu/addressbook/data/person/Block.java @@ -0,0 +1,13 @@ +package seedu.addressbook.data.person; + +public class Block { + private String blockNo; + + public Block(String blockNo){ + this.blockNo = blockNo; + } + + public String getBlockNo(){ + return this.blockNo; + } +} diff --git a/src/seedu/addressbook/data/person/PostalC.java b/src/seedu/addressbook/data/person/PostalC.java new file mode 100644 index 000000000..94fdc6eb1 --- /dev/null +++ b/src/seedu/addressbook/data/person/PostalC.java @@ -0,0 +1,13 @@ +package seedu.addressbook.data.person; + +public class PostalC { + private String postalCode; + + public PostalC(String postalc){ + this.postalCode = postalc; + } + + public String getPostalC(){ + return postalCode; + } +} diff --git a/src/seedu/addressbook/data/person/Street.java b/src/seedu/addressbook/data/person/Street.java new file mode 100644 index 000000000..7f333d1a7 --- /dev/null +++ b/src/seedu/addressbook/data/person/Street.java @@ -0,0 +1,13 @@ +package seedu.addressbook.data.person; + +public class Street { + private String street; + + public Street(String street){ + this.street = street; + } + + public String getStreet() { + return street; + } +} diff --git a/src/seedu/addressbook/data/person/Unit.java b/src/seedu/addressbook/data/person/Unit.java new file mode 100644 index 000000000..5a82714fb --- /dev/null +++ b/src/seedu/addressbook/data/person/Unit.java @@ -0,0 +1,13 @@ +package seedu.addressbook.data.person; + +public class Unit { + private String unit; + + public Unit(String unit){ + this.unit = unit; + } + + public String getUnit(){ + return this.unit; + } +} From 7835303d44a71f92669fd6276e08e7dfd8d112bb Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 14:29:08 +0800 Subject: [PATCH 5/9] Exception added when.txt file is read-only --- src/seedu/addressbook/storage/StorageFile.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 41147edf5..77f889e47 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -94,6 +94,9 @@ public AddressBook load() throws StorageOperationException { return new AddressBook(); } + if(!Files.isWritable(path)){ + throw new StorageOperationException("Storage File "+ path + "is a read-only file. "); + } try { return AddressBookDecoder.decodeAddressBook(Files.readAllLines(path)); } catch (FileNotFoundException fnfe) { From 280b35cd8e98803f8e3d08dd8e066c3348a62241 Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 15:28:54 +0800 Subject: [PATCH 6/9] Inheritance Contact for Address, Phone, Email --- .../addressbook/data/person/Address.java | 2 +- .../addressbook/data/person/Contact.java | 34 +++++++++++++++++++ src/seedu/addressbook/data/person/Email.java | 2 +- src/seedu/addressbook/data/person/Phone.java | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/seedu/addressbook/data/person/Contact.java diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index a9b33bdaa..0e0c06521 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -8,7 +8,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 extends Contact{ public static final String EXAMPLE = "123, some street"; public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses must in the format : a/BLOCK, STREET, UNIT, POSTAL CODE "; diff --git a/src/seedu/addressbook/data/person/Contact.java b/src/seedu/addressbook/data/person/Contact.java new file mode 100644 index 000000000..716ca3b11 --- /dev/null +++ b/src/seedu/addressbook/data/person/Contact.java @@ -0,0 +1,34 @@ +package seedu.addressbook.data.person; + +public class Contact { + private String value; + private boolean isPrivate; + + public Contact(){ + } + public String toString() { + return value; + } + + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Contact // instanceof handles nulls + && this.value.equals(((Contact) other).value)); // state check + } + + public int hashCode() { + return value.hashCode(); + } + + public boolean isPrivate() { + return isPrivate; + } + + public void setValue(String value){ + this.value = value; + } + + public void setisPrivate(boolean isPrivate){ + this.isPrivate = isPrivate; + } +} diff --git a/src/seedu/addressbook/data/person/Email.java b/src/seedu/addressbook/data/person/Email.java index ad623b5b8..8da6edc4b 100644 --- a/src/seedu/addressbook/data/person/Email.java +++ b/src/seedu/addressbook/data/person/Email.java @@ -6,7 +6,7 @@ * Represents a Person's email in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} */ -public class Email { +public class Email extends Contact{ public static final String EXAMPLE = "valid@e.mail"; public static final String MESSAGE_EMAIL_CONSTRAINTS = diff --git a/src/seedu/addressbook/data/person/Phone.java b/src/seedu/addressbook/data/person/Phone.java index 431a7a882..00a61a93b 100644 --- a/src/seedu/addressbook/data/person/Phone.java +++ b/src/seedu/addressbook/data/person/Phone.java @@ -6,7 +6,7 @@ * Represents a Person's phone number in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)} */ -public class Phone { +public class Phone extends Contact{ public static final String EXAMPLE = "123456789"; public static final String MESSAGE_PHONE_CONSTRAINTS = "Person phone numbers should only contain numbers"; From 3d42c8078ebe9d9d5b6932fdd69fd1f456058e4a Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 19:06:00 +0800 Subject: [PATCH 7/9] reset the changes --- .../addressbook/data/person/Address.java | 27 +-------------- src/seedu/addressbook/data/person/Block.java | 13 ------- .../addressbook/data/person/Contact.java | 34 ------------------- src/seedu/addressbook/data/person/Email.java | 2 +- src/seedu/addressbook/data/person/Phone.java | 2 +- .../addressbook/data/person/PostalC.java | 13 ------- src/seedu/addressbook/data/person/Street.java | 13 ------- src/seedu/addressbook/data/person/Unit.java | 13 ------- .../addressbook/storage/StorageFile.java | 3 -- 9 files changed, 3 insertions(+), 117 deletions(-) delete mode 100644 src/seedu/addressbook/data/person/Block.java delete mode 100644 src/seedu/addressbook/data/person/Contact.java delete mode 100644 src/seedu/addressbook/data/person/PostalC.java delete mode 100644 src/seedu/addressbook/data/person/Street.java delete mode 100644 src/seedu/addressbook/data/person/Unit.java diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 0e0c06521..8754c1dc9 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -8,7 +8,7 @@ * Represents a Person's address in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} */ -public class Address extends Contact{ +public class Address{ public static final String EXAMPLE = "123, some street"; public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses must in the format : a/BLOCK, STREET, UNIT, POSTAL CODE "; @@ -17,15 +17,6 @@ public class Address extends Contact{ public final String value; private boolean isPrivate; - /** - * Class Implementation of BLOCK, STREET, UNIT, POSTAL CODE - * The address string will be split into the sub-address members - */ - private Block blk; - private Street street; - private Unit unit; - private PostalC postalC; - /** * Validates given address. * @@ -38,8 +29,6 @@ public Address(String address, boolean isPrivate) throws IllegalValueException { throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS); } this.value = trimmedAddress; - - splitAddress(value); } /** @@ -49,20 +38,6 @@ public static boolean isValidAddress(String test) { return test.matches(ADDRESS_VALIDATION_REGEX); } - /** - * Splits the address into the sub address BLOCK,STREET,UNIT,POSTAL CODE and - * initialize the class objects associated with the sub-address accordingly - * @param address - */ - public void splitAddress(String address){ - String[] subAddress = address.split(", "); - - blk = new Block(subAddress[0]); - street = new Street(subAddress[1]); - unit = new Unit(subAddress[2]); - postalC = new PostalC(subAddress[3]); - } - @Override public String toString() { return value; diff --git a/src/seedu/addressbook/data/person/Block.java b/src/seedu/addressbook/data/person/Block.java deleted file mode 100644 index 4b9f1e9be..000000000 --- a/src/seedu/addressbook/data/person/Block.java +++ /dev/null @@ -1,13 +0,0 @@ -package seedu.addressbook.data.person; - -public class Block { - private String blockNo; - - public Block(String blockNo){ - this.blockNo = blockNo; - } - - public String getBlockNo(){ - return this.blockNo; - } -} diff --git a/src/seedu/addressbook/data/person/Contact.java b/src/seedu/addressbook/data/person/Contact.java deleted file mode 100644 index 716ca3b11..000000000 --- a/src/seedu/addressbook/data/person/Contact.java +++ /dev/null @@ -1,34 +0,0 @@ -package seedu.addressbook.data.person; - -public class Contact { - private String value; - private boolean isPrivate; - - public Contact(){ - } - public String toString() { - return value; - } - - public boolean equals(Object other) { - return other == this // short circuit if same object - || (other instanceof Contact // instanceof handles nulls - && this.value.equals(((Contact) other).value)); // state check - } - - public int hashCode() { - return value.hashCode(); - } - - public boolean isPrivate() { - return isPrivate; - } - - public void setValue(String value){ - this.value = value; - } - - public void setisPrivate(boolean isPrivate){ - this.isPrivate = isPrivate; - } -} diff --git a/src/seedu/addressbook/data/person/Email.java b/src/seedu/addressbook/data/person/Email.java index 8da6edc4b..187560f68 100644 --- a/src/seedu/addressbook/data/person/Email.java +++ b/src/seedu/addressbook/data/person/Email.java @@ -6,7 +6,7 @@ * Represents a Person's email in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} */ -public class Email extends Contact{ +public class Email{ public static final String EXAMPLE = "valid@e.mail"; public static final String MESSAGE_EMAIL_CONSTRAINTS = diff --git a/src/seedu/addressbook/data/person/Phone.java b/src/seedu/addressbook/data/person/Phone.java index 00a61a93b..c3f192fe7 100644 --- a/src/seedu/addressbook/data/person/Phone.java +++ b/src/seedu/addressbook/data/person/Phone.java @@ -6,7 +6,7 @@ * Represents a Person's phone number in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)} */ -public class Phone extends Contact{ +public class Phone{ public static final String EXAMPLE = "123456789"; public static final String MESSAGE_PHONE_CONSTRAINTS = "Person phone numbers should only contain numbers"; diff --git a/src/seedu/addressbook/data/person/PostalC.java b/src/seedu/addressbook/data/person/PostalC.java deleted file mode 100644 index 94fdc6eb1..000000000 --- a/src/seedu/addressbook/data/person/PostalC.java +++ /dev/null @@ -1,13 +0,0 @@ -package seedu.addressbook.data.person; - -public class PostalC { - private String postalCode; - - public PostalC(String postalc){ - this.postalCode = postalc; - } - - public String getPostalC(){ - return postalCode; - } -} diff --git a/src/seedu/addressbook/data/person/Street.java b/src/seedu/addressbook/data/person/Street.java deleted file mode 100644 index 7f333d1a7..000000000 --- a/src/seedu/addressbook/data/person/Street.java +++ /dev/null @@ -1,13 +0,0 @@ -package seedu.addressbook.data.person; - -public class Street { - private String street; - - public Street(String street){ - this.street = street; - } - - public String getStreet() { - return street; - } -} diff --git a/src/seedu/addressbook/data/person/Unit.java b/src/seedu/addressbook/data/person/Unit.java deleted file mode 100644 index 5a82714fb..000000000 --- a/src/seedu/addressbook/data/person/Unit.java +++ /dev/null @@ -1,13 +0,0 @@ -package seedu.addressbook.data.person; - -public class Unit { - private String unit; - - public Unit(String unit){ - this.unit = unit; - } - - public String getUnit(){ - return this.unit; - } -} diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 77f889e47..41147edf5 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -94,9 +94,6 @@ public AddressBook load() throws StorageOperationException { return new AddressBook(); } - if(!Files.isWritable(path)){ - throw new StorageOperationException("Storage File "+ path + "is a read-only file. "); - } try { return AddressBookDecoder.decodeAddressBook(Files.readAllLines(path)); } catch (FileNotFoundException fnfe) { From e89378e90530776fae87104efd888a9c9805df2a Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 20:41:04 +0800 Subject: [PATCH 8/9] Enhancement: Sort Command --- .../META-INF/addressbook-level2.kotlin_module | Bin 0 -> 16 bytes .../addressbook/commands/HelpCommand.java | 1 + .../addressbook/commands/SortCommand.java | 36 ++++++++++++++++++ src/seedu/addressbook/data/AddressBook.java | 9 +++++ .../data/person/UniquePersonList.java | 24 +++++++++--- src/seedu/addressbook/parser/Parser.java | 4 ++ 6 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 out/production/addressbook-level2/META-INF/addressbook-level2.kotlin_module create mode 100644 src/seedu/addressbook/commands/SortCommand.java diff --git a/out/production/addressbook-level2/META-INF/addressbook-level2.kotlin_module b/out/production/addressbook-level2/META-INF/addressbook-level2.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..8fb60192d378759239a3ecbf60eac8c8de446e9c GIT binary patch literal 16 RcmZQzU|?ooU|@t|UH|}6022TJ literal 0 HcmV?d00001 diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 9be217d89..3a7992589 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -23,6 +23,7 @@ public CommandResult execute() { + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE + + "\n" + SortCommand.MESSAGE_USAGE ); } } diff --git a/src/seedu/addressbook/commands/SortCommand.java b/src/seedu/addressbook/commands/SortCommand.java new file mode 100644 index 000000000..42ba919c8 --- /dev/null +++ b/src/seedu/addressbook/commands/SortCommand.java @@ -0,0 +1,36 @@ +package seedu.addressbook.commands; + +public class SortCommand extends Command { + public static final String COMMAND_WORD = "sort"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Sorts the list according to user preference. " + + "List can be sorted by name, email or address.\n" + + "Parameters: Type of sort[name/email/address]\n" + + "Example: " + COMMAND_WORD + + " name"; + + public static final String MESSAGE_SUCCESS = "The list is sorted!"; + public static final String MESSAGE_INVALID_ARGUMENT = "Invalid Argument produced; please use valid arguments"; + public static final String MESSAGE_ERROR_UNSORTABLE = "Bruh the list is empty man......."; + + private String type; + + public SortCommand(String type){ + this.type = type.trim(); + } + + @Override + public CommandResult execute(){ + if(type.equals("name") || type.equals("email") || type.equals("address")) { + boolean isSorted = addressBook.sort(this.type); + + if(isSorted){ + return new CommandResult(MESSAGE_SUCCESS); + }else{ + return new CommandResult(MESSAGE_ERROR_UNSORTABLE); + } + }else{ + return new CommandResult(MESSAGE_INVALID_ARGUMENT); + } + } +} diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 537d35c89..bfa297527 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -74,4 +74,13 @@ public boolean equals(Object other) { || (other instanceof AddressBook // instanceof handles nulls && this.allPersons.equals(((AddressBook) other).allPersons)); } + + public boolean sort(String type){ + if(!allPersons.isEmpty()) { + allPersons.sort(type); + return true; + }else{ + return false; + } + } } diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index d7acd8b4a..99307a9b0 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -1,11 +1,6 @@ package seedu.addressbook.data.person; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; +import java.util.*; import seedu.addressbook.common.Utils; import seedu.addressbook.data.exception.DuplicateDataException; @@ -129,6 +124,23 @@ public void clear() { internalList.clear(); } + public void sort(String type){ + if(type.equals("name")) + internalList.sort(Comparator.comparing((Person p)-> p.getName().toString())); + if(type.equals("email")) + internalList.sort(Comparator.comparing((Person p)-> p.getEmail().toString())); + if(type.equals("address")) + internalList.sort(Comparator.comparing((Person p)-> p.getAddress().toString())); + } + + public boolean isEmpty(){ + if(internalList.isEmpty()){ + return true; + }else{ + return false; + } + } + @Override public Iterator iterator() { return internalList.iterator(); diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index abddb3f45..69ac260d8 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -22,6 +22,7 @@ import seedu.addressbook.commands.ListCommand; import seedu.addressbook.commands.ViewAllCommand; import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.SortCommand; import seedu.addressbook.data.exception.IllegalValueException; /** @@ -97,6 +98,9 @@ public Command parseCommand(String userInput) { case ExitCommand.COMMAND_WORD: return new ExitCommand(); + case SortCommand.COMMAND_WORD: + return new SortCommand(arguments); + case HelpCommand.COMMAND_WORD: // Fallthrough default: return new HelpCommand(); From 02d14bbbd0004445b4a3c4b2a70069de677da501 Mon Sep 17 00:00:00 2001 From: Anand270294 Date: Tue, 12 Feb 2019 20:51:13 +0800 Subject: [PATCH 9/9] Updated the user guide for the new sort command --- docs/UserGuide.adoc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..b6248d493 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -156,6 +156,16 @@ Views all details of the 1st person in the results of the `find` command. Clears all entries from the address book. + Format: `clear` +== Sorting the List : `sort` + +Sorts the list according to the user preference using either name, email or address +Format: `sort TYPE_OF_SORT` + +Example: + +* `sort email` +Sorts the list according the email address of everybody + == Exiting the program : `exit` Exits the program. +