From 53ab11451cad3914ce014f83f67d30892cd418f2 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 17:31:03 +0800 Subject: [PATCH 01/37] Add factory method for DeleteCommand --- src/main/java/seedu/address/logic/commands/DeleteCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index b825274b32c..72aa9d47039 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -25,6 +25,10 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = "Deleted Contact: %1$s"; + public static DeleteCommand selectIndex(Index targetIndex, boolean deleteChildren) { + return new DeleteCommand(targetIndex); + } + private final Index targetIndex; public DeleteCommand(Index targetIndex) { From ead20a17f997626adceb6d0b1ddb8250081fe19d Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 17:32:23 +0800 Subject: [PATCH 02/37] Add subclass for DeleteCommand --- .../logic/commands/DeleteWithChildrenCommand.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java new file mode 100644 index 00000000000..c26fbfd0470 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -0,0 +1,9 @@ +package seedu.address.logic.commands; + +import seedu.address.commons.core.index.Index; + +public class DeleteWithChildrenCommand extends DeleteCommand { + public DeleteWithChildrenCommand(Index targetIndex) { + super(targetIndex); + } +} From 5f132cf5c338f66b49f934abb55b5a5b74ae1355 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 17:35:38 +0800 Subject: [PATCH 03/37] Add tasks in comments --- src/main/java/seedu/address/logic/commands/DeleteCommand.java | 4 ++++ .../address/logic/commands/DeleteWithChildrenCommand.java | 1 + 2 files changed, 5 insertions(+) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 72aa9d47039..610959ff088 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -26,6 +26,10 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = "Deleted Contact: %1$s"; public static DeleteCommand selectIndex(Index targetIndex, boolean deleteChildren) { + //TODO Add documentation to DG + if (deleteChildren) { + return new DeleteWithChildrenCommand(targetIndex); + } return new DeleteCommand(targetIndex); } diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index c26fbfd0470..f5ede90e7e0 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -4,6 +4,7 @@ public class DeleteWithChildrenCommand extends DeleteCommand { public DeleteWithChildrenCommand(Index targetIndex) { + //TODO add documentation in DG super(targetIndex); } } From ed10babf1aec013ee41779970b056cb6eba7b543 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 17:39:57 +0800 Subject: [PATCH 04/37] Add getChildren method for Contact --- .../seedu/address/logic/commands/DeleteCommand.java | 2 +- .../logic/commands/DeleteWithChildrenCommand.java | 2 +- .../java/seedu/address/model/person/Contact.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 610959ff088..602281713d0 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -26,7 +26,7 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = "Deleted Contact: %1$s"; public static DeleteCommand selectIndex(Index targetIndex, boolean deleteChildren) { - //TODO Add documentation to DG + // TODO Add documentation to DG if (deleteChildren) { return new DeleteWithChildrenCommand(targetIndex); } diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index f5ede90e7e0..ac9f9a1325e 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -4,7 +4,7 @@ public class DeleteWithChildrenCommand extends DeleteCommand { public DeleteWithChildrenCommand(Index targetIndex) { - //TODO add documentation in DG + // TODO add documentation in DG super(targetIndex); } } diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index 5f36151b297..53a2ed13e30 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -74,6 +74,19 @@ public boolean isSameContact(Contact otherContact) { && otherContact.getName().equals(getName()); } + /** + * Gives the array of contacts that are linked under this contact. + * + * For example, organizations will give the list of recruiters working for it. + * Recruiters do not have any contacts under them. + * @return the array of contacts linked under this contact. + */ + public Contact[] getChildren() { + // default return value + // TODO add to DG + return new Contact[]{}; + } + /** * Returns true if both contacts have the same identity and data fields. * This defines a stronger notion of equality between two contacts. From e9f6f02e55c5159090cabc9b19730d57b901a7f4 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 17:46:15 +0800 Subject: [PATCH 05/37] Add addChild method for Contact --- src/main/java/seedu/address/model/person/Contact.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index 53a2ed13e30..17c605fd174 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -87,6 +87,11 @@ public Contact[] getChildren() { return new Contact[]{}; } + public void addChild(Contact childContact) { + // Should throw exception if the type of contact cannot have child contacts. + // TODO add to DG, do JavaDocs + } + /** * Returns true if both contacts have the same identity and data fields. * This defines a stronger notion of equality between two contacts. From b077f23a30b1f5b0d8b98ecb10273e6619b2b46f Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 18:05:25 +0800 Subject: [PATCH 06/37] Add new exception for illegal operations --- .../exceptions/IllegalOperationException.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/seedu/address/commons/exceptions/IllegalOperationException.java diff --git a/src/main/java/seedu/address/commons/exceptions/IllegalOperationException.java b/src/main/java/seedu/address/commons/exceptions/IllegalOperationException.java new file mode 100644 index 00000000000..ea12750e5ad --- /dev/null +++ b/src/main/java/seedu/address/commons/exceptions/IllegalOperationException.java @@ -0,0 +1,21 @@ +package seedu.address.commons.exceptions; + +/** + * Exception thrown when attempting to make illegal. + */ +public class IllegalOperationException extends Exception { + /** + * @param message that informs the user that it has attempted an illegal operation. + */ + public IllegalOperationException(String message) { + super(message); + } + + /** + * @param message that informs the user that it has attempted an illegal operation. + * @param cause of the main exception. + */ + public IllegalOperationException(String message, Throwable cause) { + super(message, cause); + } +} From ff7ae089acdce76a37020fc3754c6b3fb7c0a2d5 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 10 Oct 2023 18:08:49 +0800 Subject: [PATCH 07/37] Add exception thrown when calling addChild --- src/main/java/seedu/address/model/person/Contact.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index 17c605fd174..020359144e2 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.Set; +import seedu.address.commons.exceptions.IllegalOperationException; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; @@ -16,6 +17,8 @@ */ public class Contact { + private static String illegalOperationMessage = "Contact cannot have child contacts"; + // Identity fields private final Name name; private final Phone phone; @@ -87,9 +90,10 @@ public Contact[] getChildren() { return new Contact[]{}; } - public void addChild(Contact childContact) { + public void addChild(Contact childContact) throws IllegalOperationException { // Should throw exception if the type of contact cannot have child contacts. // TODO add to DG, do JavaDocs + throw new IllegalOperationException(illegalOperationMessage); } /** From 2805ec6eb6eca20ad60e583b95dc80415ae4fb32 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 12:21:44 +0800 Subject: [PATCH 08/37] Add javadocs to delete commands --- .../address/logic/commands/DeleteCommand.java | 18 ++++++++++++------ .../commands/DeleteWithChildrenCommand.java | 6 ++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 602281713d0..426b71b8314 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -12,7 +12,7 @@ import seedu.address.model.person.Contact; /** - * Deletes a contact identified using it's displayed index from the address book. + * Deletes a contact identified using its displayed index from the address book. */ public class DeleteCommand extends Command { @@ -25,16 +25,22 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = "Deleted Contact: %1$s"; - public static DeleteCommand selectIndex(Index targetIndex, boolean deleteChildren) { - // TODO Add documentation to DG - if (deleteChildren) { + private final Index targetIndex; + + /** + * Creates an executable DeleteCommand based on whether to delete recursively. + * + * @param targetIndex of the contact to delete in the current list + * @param shouldDeleteChildren specifies if child contacts should be deleted + */ + public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteChildren) { + // TODO: Add documentation to DG + if (shouldDeleteChildren) { return new DeleteWithChildrenCommand(targetIndex); } return new DeleteCommand(targetIndex); } - private final Index targetIndex; - public DeleteCommand(Index targetIndex) { this.targetIndex = targetIndex; } diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index ac9f9a1325e..4244fe08f2e 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -2,7 +2,13 @@ import seedu.address.commons.core.index.Index; +/** + * Deletes a contact identified with its displayed index and also deletes its child contacts. + */ public class DeleteWithChildrenCommand extends DeleteCommand { + /** + * @param targetIndex of the contact to be deleted in the current contact list + */ public DeleteWithChildrenCommand(Index targetIndex) { // TODO add documentation in DG super(targetIndex); From 1ad1b59bfd95aff58cce0f0a3b7ab415f8ebb69a Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 12:25:29 +0800 Subject: [PATCH 09/37] Add javadocs for Contact methods --- src/main/java/seedu/address/model/person/Contact.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index 020359144e2..f4109e377e7 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -79,10 +79,6 @@ public boolean isSameContact(Contact otherContact) { /** * Gives the array of contacts that are linked under this contact. - * - * For example, organizations will give the list of recruiters working for it. - * Recruiters do not have any contacts under them. - * @return the array of contacts linked under this contact. */ public Contact[] getChildren() { // default return value @@ -90,6 +86,10 @@ public Contact[] getChildren() { return new Contact[]{}; } + /** + * Adds a child contact under this contact. + * @throws IllegalOperationException if this contact cannot accept child contacts + */ public void addChild(Contact childContact) throws IllegalOperationException { // Should throw exception if the type of contact cannot have child contacts. // TODO add to DG, do JavaDocs From 572205484e2cac7a37484d02fff5f74b25713158 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 12:26:57 +0800 Subject: [PATCH 10/37] Fix style issues in DeleteCommand --- .../java/seedu/address/logic/commands/DeleteCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 426b71b8314..ff4e4168c3d 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -27,6 +27,10 @@ public class DeleteCommand extends Command { private final Index targetIndex; + public DeleteCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + /** * Creates an executable DeleteCommand based on whether to delete recursively. * @@ -41,10 +45,6 @@ public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteC return new DeleteCommand(targetIndex); } - public DeleteCommand(Index targetIndex) { - this.targetIndex = targetIndex; - } - @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); From 8ef6769a199b21fac4fde6bc367c5576b410c316 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 12:51:53 +0800 Subject: [PATCH 11/37] Add ContactId --- .../seedu/address/model/person/ContactId.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/seedu/address/model/person/ContactId.java diff --git a/src/main/java/seedu/address/model/person/ContactId.java b/src/main/java/seedu/address/model/person/ContactId.java new file mode 100644 index 00000000000..c78073f1799 --- /dev/null +++ b/src/main/java/seedu/address/model/person/ContactId.java @@ -0,0 +1,57 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Contact's ID in the address book. + * Guarantees: immutable, is valid as declared in {@link #isValidId(String)} + */ +public class ContactId { + + public static final String MESSAGE_CONSTRAINTS = + "Contact ID should not be blank"; + + // TODO: I need help with this part + public static final String VALIDATION_REGEX = ""; + + public final String contactId; + + /** + * Constructs a {@code ContactId}. + * + * @param contactId A valid contact id. + */ + public ContactId(String contactId) { + requireNonNull(contactId); + checkArgument(isValidId(contactId), MESSAGE_CONSTRAINTS); + this.contactId = contactId; + } + + /** + * Returns true if a given string is a valid contact ID. + */ + public static boolean isValidId(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return contactId; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + //instanceof handles nulls + if (!(other instanceof ContactId)) { + return false; + } + + ContactId otherId = (ContactId) other; + return contactId.equals(otherId.contactId); + } +} From 5033786e19d37d453c7e3da9544704ada7a50410 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 13:02:26 +0800 Subject: [PATCH 12/37] Add DeleteByIdCommand --- .../logic/commands/DeleteByIdCommand.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java new file mode 100644 index 00000000000..f3a56598b29 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java @@ -0,0 +1,25 @@ +package seedu.address.logic.commands; + +import seedu.address.model.Model; +import seedu.address.model.person.ContactId; + +/** + * Deletes a contact identified using its ID from the addressbook. + */ +public class DeleteByIdCommand extends DeleteCommand { + + private final ContactId contactId; + + public DeleteByIdCommand(ContactId id) { + // TODO: Might want to change this since null is dangerous + super(null); + this.contactId = id; + } + + @Override + public CommandResult execute(Model model) { + // TODO: Implement the get function based on id for the model + // Currently overridden to avoid NPE + return null; + } +} From 26f4670999bf01fda37a0c91c16e718e1f8e9744 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 13:07:49 +0800 Subject: [PATCH 13/37] Add DeleteByIdWithChildrenCommand --- .../commands/DeleteByIdWithChildrenCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java new file mode 100644 index 00000000000..5f07c748e4e --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java @@ -0,0 +1,16 @@ +package seedu.address.logic.commands; + +import seedu.address.model.person.ContactId; + +/** + * Deletes a contact identified with its id and also deletes its child contacts. + */ +public class DeleteByIdWithChildrenCommand extends DeleteByIdCommand { + + /** + * @param id of the contact to be deleted along with its child contacts + */ + public DeleteByIdWithChildrenCommand(ContactId id) { + super(id); + } +} From 538c16db2c3022365b8c82b8277fd5c75253eaba Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 13:08:49 +0800 Subject: [PATCH 14/37] Update javadocs of delete commands --- .../java/seedu/address/logic/commands/DeleteByIdCommand.java | 3 +++ .../address/logic/commands/DeleteByIdWithChildrenCommand.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java index f3a56598b29..8014b2932d6 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java @@ -10,6 +10,9 @@ public class DeleteByIdCommand extends DeleteCommand { private final ContactId contactId; + /** + * @param id of the contact to be deleted. + */ public DeleteByIdCommand(ContactId id) { // TODO: Might want to change this since null is dangerous super(null); diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java index 5f07c748e4e..41532fe9509 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java @@ -8,7 +8,7 @@ public class DeleteByIdWithChildrenCommand extends DeleteByIdCommand { /** - * @param id of the contact to be deleted along with its child contacts + * @param id of the contact to be deleted along with its child contacts. */ public DeleteByIdWithChildrenCommand(ContactId id) { super(id); From f87453f456a837782360112c525ff88f63a377e2 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 13:10:07 +0800 Subject: [PATCH 15/37] Add select ID for delete command --- .../address/logic/commands/DeleteCommand.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index ff4e4168c3d..4650ea15971 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -10,6 +10,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; /** * Deletes a contact identified using its displayed index from the address book. @@ -45,6 +46,20 @@ public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteC return new DeleteCommand(targetIndex); } + /** + * Creates an executable DeleteCommand based on whether to delete recursively. + * + * @param contactId of the contact to delete in the current list + * @param shouldDeleteChildren specifies if child contacts should be deleted + */ + public static DeleteCommand selectId(ContactId contactId, boolean shouldDeleteChildren) { + // TODO: Add documentation to DG + if (shouldDeleteChildren) { + return new DeleteByIdWithChildrenCommand(contactId); + } + return new DeleteByIdCommand(contactId); + } + @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); From 4dfabe6efaff42daf59748949ef6912afdde1434 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 13:40:17 +0800 Subject: [PATCH 16/37] Add functionality to delete child contacts --- .../commands/DeleteWithChildrenCommand.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index 4244fe08f2e..c070da71116 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -1,16 +1,53 @@ package seedu.address.logic.commands; +import static java.util.Objects.requireNonNull; + +import java.util.Arrays; +import java.util.List; + import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Contact; /** * Deletes a contact identified with its displayed index and also deletes its child contacts. */ public class DeleteWithChildrenCommand extends DeleteCommand { + + public static String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + "with:\n%s"; + + private final Index targetIndex; + /** * @param targetIndex of the contact to be deleted in the current contact list */ public DeleteWithChildrenCommand(Index targetIndex) { // TODO add documentation in DG super(targetIndex); + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredContactList(); + + if (targetIndex.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_CONTACT_DISPLAYED_INDEX); + } + + Contact contactToDelete = lastShownList.get(targetIndex.getZeroBased()); + Contact[] childContacts = contactToDelete.getChildren(); + model.deleteContact(contactToDelete); + Arrays.stream(childContacts).forEach(contact -> {model.deleteContact(contactToDelete);}); + return new CommandResult(String.format( + MESSAGE_DELETE_CONTACT_SUCCESS, + Messages.format(contactToDelete), + Arrays.stream(childContacts) + .map(c -> Messages.format(c) + "\n") + .reduce((c1, c2) -> c1 + c2) + )); } } From 8a35390cdba563327825d1f66333419ec9925461 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 14:17:49 +0800 Subject: [PATCH 17/37] Add hashcode function to ContactId --- src/main/java/seedu/address/model/person/ContactId.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/seedu/address/model/person/ContactId.java b/src/main/java/seedu/address/model/person/ContactId.java index c78073f1799..8f1bd98450e 100644 --- a/src/main/java/seedu/address/model/person/ContactId.java +++ b/src/main/java/seedu/address/model/person/ContactId.java @@ -54,4 +54,9 @@ public boolean equals(Object other) { ContactId otherId = (ContactId) other; return contactId.equals(otherId.contactId); } + + @Override + public int hashCode() { + return contactId.hashCode(); + } } From f66a7ffd0e4805f53d80658d657fb40df61fba26 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Thu, 12 Oct 2023 14:33:59 +0800 Subject: [PATCH 18/37] Add regex to ContactId --- src/main/java/seedu/address/model/person/ContactId.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/ContactId.java b/src/main/java/seedu/address/model/person/ContactId.java index 8f1bd98450e..f5bcdd694e9 100644 --- a/src/main/java/seedu/address/model/person/ContactId.java +++ b/src/main/java/seedu/address/model/person/ContactId.java @@ -13,7 +13,7 @@ public class ContactId { "Contact ID should not be blank"; // TODO: I need help with this part - public static final String VALIDATION_REGEX = ""; + public static final String VALIDATION_REGEX = "^[a-zA-Z0-9\\-_]+$"; public final String contactId; From 79db31cd9475ca6de6c60cee8e84a0b471f5fd4b Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 19:39:54 +0800 Subject: [PATCH 19/37] Add functionality to get contact by id --- src/main/java/seedu/address/model/AddressBook.java | 11 +++++++++++ src/main/java/seedu/address/model/person/Contact.java | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index e33c03abef3..8358bfca2ba 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -7,6 +7,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; import seedu.address.model.person.UniqueContactList; /** @@ -94,6 +95,16 @@ public void removeContact(Contact key) { contacts.remove(key); } + public Contact getContactById(ContactId id) { + requireNonNull(id); + for (Contact c: contacts) { + if (id.equals(c.getContactId())) { + return c; + } + } + return null; + } + //// util methods @Override diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index f4109e377e7..4c7f5bfabed 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -20,6 +20,7 @@ public class Contact { private static String illegalOperationMessage = "Contact cannot have child contacts"; // Identity fields + private final ContactId contactId = null; private final Name name; private final Phone phone; private final Email email; @@ -40,6 +41,10 @@ public Contact(Name name, Phone phone, Email email, Address address, Set ta this.tags.addAll(tags); } + public ContactId getContactId() { + return contactId; + } + public Name getName() { return name; } From 93add4581b5af48980d4ca153d5ebc613cc2806f Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 19:42:49 +0800 Subject: [PATCH 20/37] Add javadocs to AddressBook --- src/main/java/seedu/address/model/AddressBook.java | 5 +++++ src/main/java/seedu/address/model/ModelManager.java | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 8358bfca2ba..6774a34c2b1 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -95,6 +95,11 @@ public void removeContact(Contact key) { contacts.remove(key); } + /** + * Gives a contact which id matches the given id. + * Gives null if a contact with such id does not exist. + * Given id must not be null. + */ public Contact getContactById(ContactId id) { requireNonNull(id); for (Contact c: contacts) { diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 97701f412ac..47f7f02f22a 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -111,6 +111,8 @@ public void setContact(Contact target, Contact editedContact) { addressBook.setContact(target, editedContact); } + + //=========== Filtered Contact List Accessors ============================================================= /** From 6e99018d655a937799ac283c5db4916af654b292 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 19:45:24 +0800 Subject: [PATCH 21/37] Add functionality to get contact by id in Model --- src/main/java/seedu/address/model/Model.java | 8 ++++++++ src/main/java/seedu/address/model/ModelManager.java | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 391db23d995..28cc5f7de5c 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -6,6 +6,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; /** * The API of the Model component. @@ -76,6 +77,13 @@ public interface Model { */ void setContact(Contact target, Contact editedContact); + /** + * Gives a contact hsa the given id. + * Gives null if no such contact is found. + * Given id must not be null. + */ + Contact getContactById(ContactId id); + /** Returns an unmodifiable view of the filtered contact list */ ObservableList getFilteredContactList(); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 47f7f02f22a..a0077884800 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -12,6 +12,7 @@ import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; /** * Represents the in-memory model of the address book data. @@ -111,7 +112,10 @@ public void setContact(Contact target, Contact editedContact) { addressBook.setContact(target, editedContact); } - + @Override + public Contact getContactById(ContactId id) { + return addressBook.getContactById(id); + } //=========== Filtered Contact List Accessors ============================================================= From ee662e9ab959a5b8d367588fbc9125c87cac1e2c Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 19:58:29 +0800 Subject: [PATCH 22/37] Implement delete by id commands --- .../logic/commands/DeleteByIdCommand.java | 10 ++++-- .../DeleteByIdWithChildrenCommand.java | 33 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java index 8014b2932d6..092c4a0597d 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import seedu.address.model.Model; +import seedu.address.model.person.Contact; import seedu.address.model.person.ContactId; /** @@ -8,6 +9,7 @@ */ public class DeleteByIdCommand extends DeleteCommand { + public static final String NO_SUCH_CONTACT_WITH_ID = "No such contact with id: %s"; private final ContactId contactId; /** @@ -22,7 +24,11 @@ public DeleteByIdCommand(ContactId id) { @Override public CommandResult execute(Model model) { // TODO: Implement the get function based on id for the model - // Currently overridden to avoid NPE - return null; + Contact c = model.getContactById(contactId); + if (c == null) { + return new CommandResult(String.format(NO_SUCH_CONTACT_WITH_ID, contactId)); + } + model.deleteContact(c); + return new CommandResult(String.format(MESSAGE_DELETE_CONTACT_SUCCESS, c)); } } diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java index 41532fe9509..bd731f5f16c 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java @@ -1,16 +1,45 @@ package seedu.address.logic.commands; +import static seedu.address.logic.commands.DeleteByIdCommand.NO_SUCH_CONTACT_WITH_ID; + +import java.util.Arrays; + +import seedu.address.logic.Messages; +import seedu.address.model.Model; +import seedu.address.model.person.Contact; import seedu.address.model.person.ContactId; /** * Deletes a contact identified with its id and also deletes its child contacts. */ -public class DeleteByIdWithChildrenCommand extends DeleteByIdCommand { +public class DeleteByIdWithChildrenCommand extends DeleteCommand { + private final ContactId contactId; /** * @param id of the contact to be deleted along with its child contacts. */ public DeleteByIdWithChildrenCommand(ContactId id) { - super(id); + super(null); + this.contactId = id; + } + + @Override + public CommandResult execute(Model model) { + Contact contactToDelete = model.getContactById(contactId); + if (contactToDelete == null) { + return new CommandResult(String.format(NO_SUCH_CONTACT_WITH_ID, contactId)); + } + Contact[] childContacts = contactToDelete.getChildren(); + model.deleteContact(contactToDelete); + Arrays.stream(childContacts).forEach(contact -> { + model.deleteContact(contactToDelete); + }); + return new CommandResult(String.format( + DeleteWithChildrenCommand.MESSAGE_DELETE_CONTACT_SUCCESS, + Messages.format(contactToDelete), + Arrays.stream(childContacts) + .map(c -> Messages.format(c) + "\n") + .reduce((c1, c2) -> c1 + c2) + )); } } From ea0c0d336f389b66c8e805679565806c0c9378dd Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 19:59:48 +0800 Subject: [PATCH 23/37] Fix formatting and spelling errors --- .../address/logic/commands/DeleteWithChildrenCommand.java | 4 +++- src/main/java/seedu/address/model/Model.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index c070da71116..f97f85c317f 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -41,7 +41,9 @@ public CommandResult execute(Model model) throws CommandException { Contact contactToDelete = lastShownList.get(targetIndex.getZeroBased()); Contact[] childContacts = contactToDelete.getChildren(); model.deleteContact(contactToDelete); - Arrays.stream(childContacts).forEach(contact -> {model.deleteContact(contactToDelete);}); + Arrays.stream(childContacts).forEach(contact -> { + model.deleteContact(contactToDelete); + }); return new CommandResult(String.format( MESSAGE_DELETE_CONTACT_SUCCESS, Messages.format(contactToDelete), diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 28cc5f7de5c..bea4f0770cd 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -78,7 +78,7 @@ public interface Model { void setContact(Contact target, Contact editedContact); /** - * Gives a contact hsa the given id. + * Gives a contact which matches the given id. * Gives null if no such contact is found. * Given id must not be null. */ From a9b73c197bf6daee0f3ce0360102d416c046fa53 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 20:02:42 +0800 Subject: [PATCH 24/37] Fix checkstyle issues --- .../address/logic/commands/DeleteWithChildrenCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index f97f85c317f..853bb081daa 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -16,7 +16,8 @@ */ public class DeleteWithChildrenCommand extends DeleteCommand { - public static String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + "with:\n%s"; + public static final String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + "with" + + ":\n%s"; private final Index targetIndex; From 83126be58d3b0ae450d30703aabae32bd62e50a0 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Mon, 16 Oct 2023 20:05:14 +0800 Subject: [PATCH 25/37] Implement new model method in test --- .../java/seedu/address/logic/commands/AddCommandTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index d8b517a864e..554157348f2 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -23,6 +23,7 @@ import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; import seedu.address.testutil.ContactBuilder; public class AddCommandTest { @@ -148,6 +149,11 @@ public void setContact(Contact target, Contact editedContact) { throw new AssertionError("This method should not be called."); } + @Override + public Contact getContactById(ContactId id) { + throw new AssertionError("This method should not be called."); + } + @Override public ObservableList getFilteredContactList() { throw new AssertionError("This method should not be called."); From ad8194f67cbd5d06550caba57dc90409038b13cd Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 13:06:57 +0800 Subject: [PATCH 26/37] Nuke delete by id commands --- .../logic/commands/DeleteByIdCommand.java | 34 -------------- .../DeleteByIdWithChildrenCommand.java | 45 ------------------- 2 files changed, 79 deletions(-) delete mode 100644 src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java delete mode 100644 src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java deleted file mode 100644 index 092c4a0597d..00000000000 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package seedu.address.logic.commands; - -import seedu.address.model.Model; -import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; - -/** - * Deletes a contact identified using its ID from the addressbook. - */ -public class DeleteByIdCommand extends DeleteCommand { - - public static final String NO_SUCH_CONTACT_WITH_ID = "No such contact with id: %s"; - private final ContactId contactId; - - /** - * @param id of the contact to be deleted. - */ - public DeleteByIdCommand(ContactId id) { - // TODO: Might want to change this since null is dangerous - super(null); - this.contactId = id; - } - - @Override - public CommandResult execute(Model model) { - // TODO: Implement the get function based on id for the model - Contact c = model.getContactById(contactId); - if (c == null) { - return new CommandResult(String.format(NO_SUCH_CONTACT_WITH_ID, contactId)); - } - model.deleteContact(c); - return new CommandResult(String.format(MESSAGE_DELETE_CONTACT_SUCCESS, c)); - } -} diff --git a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java deleted file mode 100644 index bd731f5f16c..00000000000 --- a/src/main/java/seedu/address/logic/commands/DeleteByIdWithChildrenCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package seedu.address.logic.commands; - -import static seedu.address.logic.commands.DeleteByIdCommand.NO_SUCH_CONTACT_WITH_ID; - -import java.util.Arrays; - -import seedu.address.logic.Messages; -import seedu.address.model.Model; -import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; - -/** - * Deletes a contact identified with its id and also deletes its child contacts. - */ -public class DeleteByIdWithChildrenCommand extends DeleteCommand { - - private final ContactId contactId; - /** - * @param id of the contact to be deleted along with its child contacts. - */ - public DeleteByIdWithChildrenCommand(ContactId id) { - super(null); - this.contactId = id; - } - - @Override - public CommandResult execute(Model model) { - Contact contactToDelete = model.getContactById(contactId); - if (contactToDelete == null) { - return new CommandResult(String.format(NO_SUCH_CONTACT_WITH_ID, contactId)); - } - Contact[] childContacts = contactToDelete.getChildren(); - model.deleteContact(contactToDelete); - Arrays.stream(childContacts).forEach(contact -> { - model.deleteContact(contactToDelete); - }); - return new CommandResult(String.format( - DeleteWithChildrenCommand.MESSAGE_DELETE_CONTACT_SUCCESS, - Messages.format(contactToDelete), - Arrays.stream(childContacts) - .map(c -> Messages.format(c) + "\n") - .reduce((c1, c2) -> c1 + c2) - )); - } -} From 6b30a6ea5f716f79eceec78f6a0799567ba05e9f Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 14:06:18 +0800 Subject: [PATCH 27/37] Add no such contact exception message --- src/main/java/seedu/address/logic/Messages.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 35d2083a3e9..cbad7465828 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -15,6 +15,7 @@ public class Messages { public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_CONTACT_DISPLAYED_INDEX = "The contact index provided is invalid"; + public static final String MESSAGE_NO_SUCH_CONTACT = "No such contact"; public static final String MESSAGE_CONTACTS_LISTED_OVERVIEW = "%1$d contacts listed!"; public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; From 74baba9e4966557090294725fdba12a22002c55a Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 14:21:46 +0800 Subject: [PATCH 28/37] Implement delete by id in DeleteCommand classes --- .../address/logic/commands/DeleteCommand.java | 60 +++++++++++++++---- .../commands/DeleteWithChildrenCommand.java | 23 ++++--- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 4650ea15971..3539a92bc83 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import java.util.List; +import java.util.function.Function; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.ToStringBuilder; @@ -26,10 +27,36 @@ public class DeleteCommand extends Command { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = "Deleted Contact: %1$s"; - private final Index targetIndex; + private final Object selector; // TODO: This is very sus but this will only be used for equals comparison + private final Function contactFunction; + + private final CommandException commandException; + + /** + * @param targetIndex of the contact to be deleted + */ public DeleteCommand(Index targetIndex) { - this.targetIndex = targetIndex; + this.selector = targetIndex; + this.contactFunction = (Model model) -> { + List lastShownList = model.getFilteredContactList(); + + if (targetIndex.getZeroBased() >= lastShownList.size()) { + return null; + } + + return lastShownList.get(targetIndex.getZeroBased()); + }; + this.commandException = new CommandException(Messages.MESSAGE_INVALID_CONTACT_DISPLAYED_INDEX); + } + + /** + * @param targetId of the contact to be deleted + */ + public DeleteCommand(ContactId targetId) { + this.selector = targetId; + this.contactFunction = (Model model) -> model.getContactById(targetId); + this.commandException = new CommandException(Messages.MESSAGE_NO_SUCH_CONTACT); } /** @@ -40,6 +67,7 @@ public DeleteCommand(Index targetIndex) { */ public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteChildren) { // TODO: Add documentation to DG + requireNonNull(targetIndex); if (shouldDeleteChildren) { return new DeleteWithChildrenCommand(targetIndex); } @@ -54,22 +82,20 @@ public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteC */ public static DeleteCommand selectId(ContactId contactId, boolean shouldDeleteChildren) { // TODO: Add documentation to DG + requireNonNull(contactId); if (shouldDeleteChildren) { - return new DeleteByIdWithChildrenCommand(contactId); + return new DeleteWithChildrenCommand(contactId); } - return new DeleteByIdCommand(contactId); + return new DeleteCommand(contactId); } @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredContactList(); - - if (targetIndex.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_CONTACT_DISPLAYED_INDEX); + Contact contactToDelete = this.contactFunction.apply(model); + if (contactToDelete == null) { + throw commandException; } - - Contact contactToDelete = lastShownList.get(targetIndex.getZeroBased()); model.deleteContact(contactToDelete); return new CommandResult(String.format(MESSAGE_DELETE_CONTACT_SUCCESS, Messages.format(contactToDelete))); } @@ -86,13 +112,23 @@ public boolean equals(Object other) { } DeleteCommand otherDeleteCommand = (DeleteCommand) other; - return targetIndex.equals(otherDeleteCommand.targetIndex); + return selector.equals(otherDeleteCommand.selector); } @Override public String toString() { + // TODO: replace this toString method with sth better than targetIndex + // To not replace yet until we do the tests return new ToStringBuilder(this) - .add("targetIndex", targetIndex) + .add("targetIndex", selector) .toString(); } + + /** + * Gives the contact that the DeleteCommand is going to delete if a model is given. + * If such a contact does not exist, gives null. + */ + protected Contact getContact(Model model) { + return contactFunction.apply(model); + } } diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index 853bb081daa..61b72d938bd 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -3,13 +3,13 @@ import static java.util.Objects.requireNonNull; import java.util.Arrays; -import java.util.List; import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Contact; +import seedu.address.model.person.ContactId; /** * Deletes a contact identified with its displayed index and also deletes its child contacts. @@ -19,7 +19,6 @@ public class DeleteWithChildrenCommand extends DeleteCommand { public static final String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + "with" + ":\n%s"; - private final Index targetIndex; /** * @param targetIndex of the contact to be deleted in the current contact list @@ -27,21 +26,21 @@ public class DeleteWithChildrenCommand extends DeleteCommand { public DeleteWithChildrenCommand(Index targetIndex) { // TODO add documentation in DG super(targetIndex); - this.targetIndex = targetIndex; + } + + public DeleteWithChildrenCommand(ContactId targetId) { + super(targetId); } @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - List lastShownList = model.getFilteredContactList(); - - if (targetIndex.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_CONTACT_DISPLAYED_INDEX); - } - - Contact contactToDelete = lastShownList.get(targetIndex.getZeroBased()); + Contact contactToDelete = super.getContact(model); + super.execute(model); + // At this point if the contact is null, the superclass would have thrown exception. + // Superclass would have also deleted the contact from the list. + assert contactToDelete != null; Contact[] childContacts = contactToDelete.getChildren(); - model.deleteContact(contactToDelete); Arrays.stream(childContacts).forEach(contact -> { model.deleteContact(contactToDelete); }); @@ -50,7 +49,7 @@ public CommandResult execute(Model model) throws CommandException { Messages.format(contactToDelete), Arrays.stream(childContacts) .map(c -> Messages.format(c) + "\n") - .reduce((c1, c2) -> c1 + c2) + .reduce((c1, c2) -> c1 + c2) // I can't find a better method. )); } } From 59cc7726a44077e4592065d5da098dd58135f75c Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 14:30:37 +0800 Subject: [PATCH 29/37] Update javadocs for DeleteCommand classes --- src/main/java/seedu/address/logic/commands/DeleteCommand.java | 2 +- .../seedu/address/logic/commands/DeleteWithChildrenCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 3539a92bc83..c1238374d36 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -14,7 +14,7 @@ import seedu.address.model.person.ContactId; /** - * Deletes a contact identified using its displayed index from the address book. + * Deletes a contact identified using its displayed index or its contact id from the address book. */ public class DeleteCommand extends Command { diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index 61b72d938bd..71492bb8862 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -12,7 +12,7 @@ import seedu.address.model.person.ContactId; /** - * Deletes a contact identified with its displayed index and also deletes its child contacts. + * Deletes a contact and also deletes its child contacts. */ public class DeleteWithChildrenCommand extends DeleteCommand { From 70d7ca057909b3a5d0268ccc7608beb0a2461107 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 15:14:31 +0800 Subject: [PATCH 30/37] Add parseContactId method --- .../seedu/address/logic/parser/ParserUtil.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b117acb9c55..a9a2d3d36d3 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,6 +10,7 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.ContactId; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; @@ -95,6 +96,21 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } + /** + * Parses a {@code String contactId} into an {@code ContactId}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code contactId} is invalid. + */ + public static ContactId parseContactId(String contactId) throws ParseException { + requireNonNull(contactId); + String trimmedId = contactId.trim(); + if (ContactId.isValidId(trimmedId)) { + throw new ParseException(ContactId.MESSAGE_CONSTRAINTS); + } + return new ContactId(trimmedId); + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. From fc915f9eb0a5c9ea18eafdc401bad58ad18099e3 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 16:00:04 +0800 Subject: [PATCH 31/37] Change ContactId to Id --- .../address/logic/commands/DeleteCommand.java | 14 ++--- .../commands/DeleteWithChildrenCommand.java | 4 +- .../address/logic/parser/ParserUtil.java | 16 ----- .../java/seedu/address/model/AddressBook.java | 6 +- src/main/java/seedu/address/model/Model.java | 4 +- .../seedu/address/model/ModelManager.java | 4 +- .../seedu/address/model/person/Contact.java | 5 -- .../seedu/address/model/person/ContactId.java | 62 ------------------- .../logic/commands/AddCommandTest.java | 4 +- 9 files changed, 18 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/seedu/address/model/person/ContactId.java diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index c1238374d36..13e82dd4896 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -11,7 +11,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; /** * Deletes a contact identified using its displayed index or its contact id from the address book. @@ -53,7 +53,7 @@ public DeleteCommand(Index targetIndex) { /** * @param targetId of the contact to be deleted */ - public DeleteCommand(ContactId targetId) { + public DeleteCommand(Id targetId) { this.selector = targetId; this.contactFunction = (Model model) -> model.getContactById(targetId); this.commandException = new CommandException(Messages.MESSAGE_NO_SUCH_CONTACT); @@ -77,16 +77,16 @@ public static DeleteCommand selectIndex(Index targetIndex, boolean shouldDeleteC /** * Creates an executable DeleteCommand based on whether to delete recursively. * - * @param contactId of the contact to delete in the current list + * @param id of the contact to delete in the current list * @param shouldDeleteChildren specifies if child contacts should be deleted */ - public static DeleteCommand selectId(ContactId contactId, boolean shouldDeleteChildren) { + public static DeleteCommand selectId(Id id, boolean shouldDeleteChildren) { // TODO: Add documentation to DG - requireNonNull(contactId); + requireNonNull(id); if (shouldDeleteChildren) { - return new DeleteWithChildrenCommand(contactId); + return new DeleteWithChildrenCommand(id); } - return new DeleteCommand(contactId); + return new DeleteCommand(id); } @Override diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index 71492bb8862..2269567bed8 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -9,7 +9,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; /** * Deletes a contact and also deletes its child contacts. @@ -28,7 +28,7 @@ public DeleteWithChildrenCommand(Index targetIndex) { super(targetIndex); } - public DeleteWithChildrenCommand(ContactId targetId) { + public DeleteWithChildrenCommand(Id targetId) { super(targetId); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 1205d9997ab..311915ed6cb 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,7 +10,6 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; -import seedu.address.model.person.ContactId; import seedu.address.model.person.Email; import seedu.address.model.person.Id; import seedu.address.model.person.Name; @@ -160,21 +159,6 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } - /** - * Parses a {@code String contactId} into an {@code ContactId}. - * Leading and trailing whitespaces will be trimmed. - * - * @throws ParseException if the given {@code contactId} is invalid. - */ - public static ContactId parseContactId(String contactId) throws ParseException { - requireNonNull(contactId); - String trimmedId = contactId.trim(); - if (ContactId.isValidId(trimmedId)) { - throw new ParseException(ContactId.MESSAGE_CONSTRAINTS); - } - return new ContactId(trimmedId); - } - /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 6774a34c2b1..9e146fc1dbd 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -7,7 +7,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; import seedu.address.model.person.UniqueContactList; /** @@ -100,10 +100,10 @@ public void removeContact(Contact key) { * Gives null if a contact with such id does not exist. * Given id must not be null. */ - public Contact getContactById(ContactId id) { + public Contact getContactById(Id id) { requireNonNull(id); for (Contact c: contacts) { - if (id.equals(c.getContactId())) { + if (id.equals(c.getId())) { return c; } } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index bea4f0770cd..8298c8632b1 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -6,7 +6,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; /** * The API of the Model component. @@ -82,7 +82,7 @@ public interface Model { * Gives null if no such contact is found. * Given id must not be null. */ - Contact getContactById(ContactId id); + Contact getContactById(Id id); /** Returns an unmodifiable view of the filtered contact list */ ObservableList getFilteredContactList(); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index a0077884800..82f2bc4daa3 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -12,7 +12,7 @@ import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; /** * Represents the in-memory model of the address book data. @@ -113,7 +113,7 @@ public void setContact(Contact target, Contact editedContact) { } @Override - public Contact getContactById(ContactId id) { + public Contact getContactById(Id id) { return addressBook.getContactById(id); } diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index d907dfd6f10..66f83c093d6 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -20,7 +20,6 @@ public class Contact { private static String illegalOperationMessage = "Contact cannot have child contacts"; // Identity fields - private final ContactId contactId = null; private final Name name; private final Id id; private final Phone phone; @@ -45,10 +44,6 @@ public Contact(Name name, Id id, Phone phone, Email email, Url url, Address addr this.tags.addAll(tags); } - public ContactId getContactId() { - return contactId; - } - public Type getType() { // TODO: This should be an abstract method. return Type.UNKNOWN; diff --git a/src/main/java/seedu/address/model/person/ContactId.java b/src/main/java/seedu/address/model/person/ContactId.java deleted file mode 100644 index f5bcdd694e9..00000000000 --- a/src/main/java/seedu/address/model/person/ContactId.java +++ /dev/null @@ -1,62 +0,0 @@ -package seedu.address.model.person; - -import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - -/** - * Represents a Contact's ID in the address book. - * Guarantees: immutable, is valid as declared in {@link #isValidId(String)} - */ -public class ContactId { - - public static final String MESSAGE_CONSTRAINTS = - "Contact ID should not be blank"; - - // TODO: I need help with this part - public static final String VALIDATION_REGEX = "^[a-zA-Z0-9\\-_]+$"; - - public final String contactId; - - /** - * Constructs a {@code ContactId}. - * - * @param contactId A valid contact id. - */ - public ContactId(String contactId) { - requireNonNull(contactId); - checkArgument(isValidId(contactId), MESSAGE_CONSTRAINTS); - this.contactId = contactId; - } - - /** - * Returns true if a given string is a valid contact ID. - */ - public static boolean isValidId(String test) { - return test.matches(VALIDATION_REGEX); - } - - @Override - public String toString() { - return contactId; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - //instanceof handles nulls - if (!(other instanceof ContactId)) { - return false; - } - - ContactId otherId = (ContactId) other; - return contactId.equals(otherId.contactId); - } - - @Override - public int hashCode() { - return contactId.hashCode(); - } -} diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 554157348f2..2bb5265adf5 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -23,7 +23,7 @@ import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.person.Contact; -import seedu.address.model.person.ContactId; +import seedu.address.model.person.Id; import seedu.address.testutil.ContactBuilder; public class AddCommandTest { @@ -150,7 +150,7 @@ public void setContact(Contact target, Contact editedContact) { } @Override - public Contact getContactById(ContactId id) { + public Contact getContactById(Id id) { throw new AssertionError("This method should not be called."); } From 667451d349060977bf12eb422a87e18954bcfbf0 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 21:32:22 +0800 Subject: [PATCH 32/37] Add recursive flag to CliSyntax --- src/main/java/seedu/address/logic/parser/CliSyntax.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 8fc31f1f171..a8bad2a8dee 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -17,6 +17,7 @@ public class CliSyntax { public static final Flag FLAG_STATUS = new Flag("stat"); public static final Flag FLAG_POSITION = new Flag("pos"); public static final Flag FLAG_ID = new Flag("id"); + public static final Flag FLAG_RECURSIVE = new Flag("recursive"); From 91d7f6fc86563533190166b7a9332f11dcd1a79d Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 21:39:05 +0800 Subject: [PATCH 33/37] Update DeleteCommandParser to delete id --- .../logic/parser/DeleteCommandParser.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 3527fe76a3e..7d86d6f59d1 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -1,10 +1,13 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.FLAG_ID; +import static seedu.address.logic.parser.CliSyntax.FLAG_RECURSIVE; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.DeleteCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Id; /** * Parses input arguments and creates a new DeleteCommand object @@ -17,13 +20,45 @@ public class DeleteCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public DeleteCommand parse(String args) throws ParseException { + ArgumentMultimap argumentMultimap = + ArgumentTokenizer.tokenize(args, + FLAG_ID, FLAG_RECURSIVE); + + boolean hasIndex = !argumentMultimap.getPreamble().isEmpty(); + boolean hasId = argumentMultimap.getValue(FLAG_ID).isPresent(); + boolean isRecursive = argumentMultimap.getValue(FLAG_RECURSIVE).isPresent(); + + if (hasIndex) { + return parseDeleteIndexCommand(argumentMultimap.getPreamble(), isRecursive); + } + + if (hasId) { + return parseDeleteIdCommand(argumentMultimap.getValue(FLAG_ID).get(), isRecursive); + } + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE)); + } + + private static DeleteCommand parseDeleteIdCommand(String idString, boolean isRecursive) throws ParseException { + Id id; try { - Index index = ParserUtil.parseIndex(args); - return new DeleteCommand(index); + // We are guaranteed that there is something by + id = ParserUtil.parseId(idString); + return DeleteCommand.selectId(id, isRecursive); } catch (ParseException pe) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe); } } + private static DeleteCommand parseDeleteIndexCommand(String indexStr, boolean isRecursive) throws ParseException { + Index index; + try { + index = ParserUtil.parseIndex(indexStr); + return DeleteCommand.selectIndex(index, isRecursive); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe); + } + } } From df0eeeabcab2439f11cd2a6100653ae546d41af0 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 21:51:53 +0800 Subject: [PATCH 34/37] Fix wrong recursive delete message --- .../address/logic/commands/DeleteWithChildrenCommand.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java index 2269567bed8..087a1cc2a4b 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java @@ -16,8 +16,8 @@ */ public class DeleteWithChildrenCommand extends DeleteCommand { - public static final String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + "with" - + ":\n%s"; + public static final String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + " with" + + ":\n%2$s"; /** @@ -49,7 +49,8 @@ public CommandResult execute(Model model) throws CommandException { Messages.format(contactToDelete), Arrays.stream(childContacts) .map(c -> Messages.format(c) + "\n") - .reduce((c1, c2) -> c1 + c2) // I can't find a better method. + .reduce((c1, c2) -> c1 + c2) + .orElse("No other contacts found") // I can't find a better method. )); } } From 8dc9d581ef741ecafec4467712d773d30e367915 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 22:22:05 +0800 Subject: [PATCH 35/37] Remove unncessary comment --- .../java/seedu/address/logic/parser/DeleteCommandParser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 7d86d6f59d1..51e60b28f97 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -42,7 +42,6 @@ public DeleteCommand parse(String args) throws ParseException { private static DeleteCommand parseDeleteIdCommand(String idString, boolean isRecursive) throws ParseException { Id id; try { - // We are guaranteed that there is something by id = ParserUtil.parseId(idString); return DeleteCommand.selectId(id, isRecursive); } catch (ParseException pe) { From 2e72dc43a27d03721b14fd4f0630d491ed66f1b2 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 23:24:08 +0800 Subject: [PATCH 36/37] Fix name for static field in Contact --- src/main/java/seedu/address/model/person/Contact.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Contact.java b/src/main/java/seedu/address/model/person/Contact.java index 66f83c093d6..8c969bec340 100644 --- a/src/main/java/seedu/address/model/person/Contact.java +++ b/src/main/java/seedu/address/model/person/Contact.java @@ -17,7 +17,7 @@ */ public class Contact { - private static String illegalOperationMessage = "Contact cannot have child contacts"; + private static final String ILLEGAL_OPERATION_MESSAGE = "Contact cannot have child contacts"; // Identity fields private final Name name; @@ -110,7 +110,7 @@ public Contact[] getChildren() { public void addChild(Contact childContact) throws IllegalOperationException { // Should throw exception if the type of contact cannot have child contacts. // TODO add to DG, do JavaDocs - throw new IllegalOperationException(illegalOperationMessage); + throw new IllegalOperationException(ILLEGAL_OPERATION_MESSAGE); } /** From 91974fef19cfc9dad56baf5d929a67e125378746 Mon Sep 17 00:00:00 2001 From: CJ-Lee01 Date: Tue, 17 Oct 2023 23:24:58 +0800 Subject: [PATCH 37/37] Add todo for Organization --- src/main/java/seedu/address/model/person/Organization.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/address/model/person/Organization.java b/src/main/java/seedu/address/model/person/Organization.java index ea1700ea02a..e2e53202903 100644 --- a/src/main/java/seedu/address/model/person/Organization.java +++ b/src/main/java/seedu/address/model/person/Organization.java @@ -13,6 +13,7 @@ * validated, immutable. */ public class Organization extends Contact { + // TODO: Override the getChildren method private final Status status; private final Position position;