Skip to content

Commit

Permalink
Merge pull request #538 from AY2324S1-CS2103T-T13-3/534-code-quality-…
Browse files Browse the repository at this point in the history
…final

534 code quality final
  • Loading branch information
juliusgambe authored Nov 13, 2023
2 parents bf48900 + eac339c commit 6355fcf
Show file tree
Hide file tree
Showing 44 changed files with 494 additions and 445 deletions.
8 changes: 1 addition & 7 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class LogicManager implements Logic {
public static final String FILE_OPS_ERROR_FORMAT = "Could not save data due to the following error: %s";

public static final String FILE_OPS_PERMISSION_ERROR_FORMAT =
"Could not save data to file %s due to insufficient permissions to write to the file or the folder.";
"Could not save data to file %s due to insufficient permissions to write to the file or the folder.";

private final Logger logger = LogsCenter.getLogger(LogicManager.class);

Expand All @@ -53,12 +53,6 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

try {
storage.saveAddressBook(model.getAddressBook());
} catch (AccessDeniedException e) {
throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
} catch (IOException ioe) {
throw new CommandException(String.format(FILE_OPS_ERROR_FORMAT, ioe.getMessage()), ioe);
}
try {
storage.saveDeliveryBook(model.getDeliveryBook());
} catch (AccessDeniedException e) {
throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_USER_NOT_AUTHENTICATED;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CUSTOMERS;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
Expand All @@ -29,7 +28,7 @@ public CommandResult execute(Model model) throws CommandException {

model.setAddressBook(new AddressBook());
model.setDeliveryBook(new DeliveryBook());
model.updateFilteredCustomerList(PREDICATE_SHOW_ALL_CUSTOMERS);
model.showAllFilteredCustomerList();
return new CommandResult(MESSAGE_SUCCESS, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author {zhonghan721}
package seedu.address.logic.commands.customer;

import static java.util.Objects.requireNonNull;
Expand All @@ -24,16 +25,16 @@ public class CustomerAddCommand extends CustomerCommand {
public static final String COMMAND_WORD = CustomerCommand.COMMAND_WORD + " " + "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a customer to the HomeBoss database."
+ "\n\nParameters: "
+ PREFIX_NAME + " NAME "
+ PREFIX_PHONE + " PHONE "
+ PREFIX_EMAIL + " EMAIL "
+ PREFIX_ADDRESS + " ADDRESS\n\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + " John Doe "
+ PREFIX_PHONE + " 98765432 "
+ PREFIX_EMAIL + " [email protected] "
+ PREFIX_ADDRESS + " 311, Clementi Ave 2, #02-25";
+ "\n\nParameters: "
+ PREFIX_NAME + " NAME "
+ PREFIX_PHONE + " PHONE "
+ PREFIX_EMAIL + " EMAIL "
+ PREFIX_ADDRESS + " ADDRESS\n\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + " John Doe "
+ PREFIX_PHONE + " 98765432 "
+ PREFIX_EMAIL + " [email protected] "
+ PREFIX_ADDRESS + " 311, Clementi Ave 2, #02-25";

public static final String MESSAGE_SUCCESS = "New customer added:\n\n%1$s";
public static final String MESSAGE_DUPLICATE_CUSTOMER = "This customer already exists in HomeBoss";
Expand All @@ -53,10 +54,10 @@ public CustomerAddCommand(Customer customer) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
logger.info("Executing CustomerAddCommand: name "
+ toAdd.getName() + ", phone "
+ toAdd.getPhone() + ", email "
+ toAdd.getEmail() + ", address "
+ toAdd.getAddress());
+ toAdd.getName() + ", phone "
+ toAdd.getPhone() + ", email "
+ toAdd.getEmail() + ", address "
+ toAdd.getAddress());

// User cannot perform this operation before logging in
if (!model.getUserLoginStatus()) {
Expand Down Expand Up @@ -95,7 +96,8 @@ public boolean equals(Object other) {
@Override
public String toString() {
return new ToStringBuilder(this)
.add("toAdd", toAdd)
.toString();
.add("toAdd", toAdd)
.toString();
}
}
//@@author {zhonghan721}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author {jianyangg}
package seedu.address.logic.commands.customer;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -126,3 +127,4 @@ public String toString() {
.toString();
}
}
//@@author {jianyangg}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author {Gabriel4357}
package seedu.address.logic.commands.customer;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -45,16 +46,16 @@ public class CustomerEditCommand extends CustomerCommand {
* The text displayed to show what the command does and how to use it.
*/
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
+ "by the customer ID used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n\n"
+ "Parameters: CUSTOMER_ID (must be a positive integer and less than 2147483648) "
+ "[" + PREFIX_NAME + " NAME] "
+ "[" + PREFIX_PHONE + " PHONE] "
+ "[" + PREFIX_EMAIL + " EMAIL] "
+ "[" + PREFIX_ADDRESS + " ADDRESS]\n\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + " 91234567 "
+ PREFIX_EMAIL + " [email protected]";
+ "by the customer ID used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n\n"
+ "Parameters: CUSTOMER_ID (must be a positive integer and less than 2147483648) "
+ "[" + PREFIX_NAME + " NAME] "
+ "[" + PREFIX_PHONE + " PHONE] "
+ "[" + PREFIX_EMAIL + " EMAIL] "
+ "[" + PREFIX_ADDRESS + " ADDRESS]\n\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + " 91234567 "
+ PREFIX_EMAIL + " [email protected]";

/**
* The text to the message displayed when the Customer is edited successfuly.
Expand Down Expand Up @@ -120,7 +121,13 @@ public CommandResult execute(Model model) throws CommandException {
Customer customerToEdit = targetCustomer.get();
Customer editedCustomer = createEditedCustomer(customerToEdit, customerEditDescriptor);

if (!customerToEdit.hasSamePhone(editedCustomer) && model.hasCustomerWithSamePhone(editedCustomer)) {
logger.info("Customer to be edited: " + customerToEdit.toString() + "\n");
logger.info("Edited Customer: " + editedCustomer.toString() + "\n");

boolean isExistingCustomer = !customerToEdit.hasSamePhone(editedCustomer)
&& model.hasCustomerWithSamePhone(editedCustomer);

if (isExistingCustomer) {
logger.warning("Customer to be edited already exist.(has the same phone number as another customer)."
+ "\n");
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
Expand All @@ -129,17 +136,12 @@ public CommandResult execute(Model model) throws CommandException {
assert customerToEdit != null : "Customer to be edited should exist.";
assert editedCustomer != null : "Edited Customer should exist.";

logger.info("Customer to be edited: " + customerToEdit.toString() + "\n");
logger.info("Edited Customer: " + editedCustomer.toString() + "\n");

model.setCustomer(customerToEdit, editedCustomer);
updateDelivery(model, editedCustomer);
model.showAllFilteredCustomerList();

return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS,
Messages.format(editedCustomer)), true);


}

/**
Expand Down Expand Up @@ -178,11 +180,14 @@ protected static void updateDelivery(Model model, Customer editedCustomer) {
});
}


//@@author {zhonghan721}

/**
* Creates and returns a {@code Delivery} with the customer details edited.
*
* @param deliveryToEdit {@code Delivery} which the command edits.
* @param editedCustomer {@code Customer} which the delivery is associated with.
* @param deliveryToEdit {@code Delivery} which the command edits.
* @param editedCustomer {@code Customer} which the delivery is associated with.
*/
private static Delivery createEditedDelivery(Delivery deliveryToEdit, Customer editedCustomer) {

Expand All @@ -205,6 +210,7 @@ private static Delivery createEditedDelivery(Delivery deliveryToEdit, Customer e
return new Delivery(deliveryToEdit.getDeliveryId(), deliveryName, editedCustomer, orderDate,
deliveryDate, deliveryStatus, note);
}
//@@author {zhonghan721}

@Override
public boolean equals(Object other) {
Expand Down Expand Up @@ -333,3 +339,4 @@ public String toString() {
}
}
}
//@@author {Gabriel4357}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author {zhonghan721}
package seedu.address.logic.commands.customer;

import static java.util.Objects.requireNonNull;
Expand All @@ -22,9 +23,9 @@ public class CustomerFindCommand extends Command {
public static final String COMMAND_WORD = CustomerCommand.COMMAND_WORD + " find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";

private static final Logger logger = Logger.getLogger(CustomerFindCommand.class.getName());

Expand All @@ -38,7 +39,7 @@ public CustomerFindCommand(NameContainsKeywordsPredicate predicate) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
logger.info("Executing CustomerFindCommand: keyword "
+ predicate.getKeywordsAsString());
+ predicate.getKeywordsAsString());

// User cannot perform this operation before logging in
if (!model.getUserLoginStatus()) {
Expand All @@ -48,8 +49,8 @@ public CommandResult execute(Model model) throws CommandException {

model.updateFilteredCustomerList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_CUSTOMERS_MATCHED_LISTED,
model.getFilteredCustomerListSize()), true);
String.format(Messages.MESSAGE_CUSTOMERS_MATCHED_LISTED,
model.getFilteredCustomerListSize()), true);

}

Expand All @@ -71,7 +72,8 @@ public boolean equals(Object other) {
@Override
public String toString() {
return new ToStringBuilder(this)
.add("predicate", predicate)
.toString();
.add("predicate", predicate)
.toString();
}
}
//@@author {zhonghan721}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_USER_NOT_AUTHENTICATED;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CUSTOMERS;

import java.util.logging.Logger;

Expand Down Expand Up @@ -32,12 +31,13 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_USER_NOT_AUTHENTICATED);
}

model.updateFilteredCustomerList(PREDICATE_SHOW_ALL_CUSTOMERS);
model.showAllFilteredCustomerList();

if (model.getFilteredCustomerListSize() == 0) {
if (model.isFilteredCustomerListEmpty()) {
return new CommandResult(MESSAGE_EMPTY, true);
}

return new CommandResult(MESSAGE_SUCCESS, true);
}
}
//@@author {B-enguin}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@@author {B-enguin}
package seedu.address.logic.commands.customer;

import static java.util.Objects.requireNonNull;
Expand All @@ -20,10 +21,10 @@ public class CustomerViewCommand extends CustomerCommand {

public static final String COMMAND_WORD = CustomerCommand.COMMAND_WORD + " view";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Displays a single customer.\n\n"
+ "Parameters: "
+ "CUSTOMER_ID\n\n"
+ "Example: " + COMMAND_WORD + " "
+ "1";
+ "Parameters: "
+ "CUSTOMER_ID\n\n"
+ "Example: " + COMMAND_WORD + " "
+ "1";

public static final String MESSAGE_SUCCESS = "Customer displayed: %1$s";

Expand Down Expand Up @@ -64,7 +65,8 @@ public CommandResult execute(Model model) throws CommandException {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof CustomerViewCommand // instanceof handles nulls
&& customerId == ((CustomerViewCommand) other).customerId); // state check
|| (other instanceof CustomerViewCommand // instanceof handles nulls
&& customerId == ((CustomerViewCommand) other).customerId); // state check
}
}
//@@author {B-enguin}
Loading

0 comments on commit 6355fcf

Please sign in to comment.