Skip to content

Commit

Permalink
Merge pull request #96 from cheeseong2001/branch-Parser
Browse files Browse the repository at this point in the history
Add javadoc for Parser and DeleteCommand
  • Loading branch information
NgYaoDong authored Apr 3, 2024
2 parents 7a40bd6 + 98d984e commit 54863d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/main/java/seedu/stockpal/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import seedu.stockpal.common.Messages;
import seedu.stockpal.data.ProductList;
import seedu.stockpal.data.product.Pid;
import seedu.stockpal.exceptions.StockPalException;
import seedu.stockpal.exceptions.PidNotFoundException;
import seedu.stockpal.ui.Ui;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* DeleteCommand class is responsible for setting up and executing the delete feature to delete a particular product
* of a specific PID from the product list of StockPal.
*/
public class DeleteCommand extends ListActionCommand {

public static final String COMMAND_KEYWORD = "delete";
Expand All @@ -30,8 +34,13 @@ public DeleteCommand(Integer pid) {
this.pid = new Pid(pid);
}

/**
* Deletes a product with specific PID from the product list of StockPal.
* @param productList The product list that StockPal is mainly using to store product details.
* @throws PidNotFoundException If product with PID that user specified cannot be found in productList
*/
@Override
public void execute(ProductList productList) throws StockPalException {
public void execute(ProductList productList) throws PidNotFoundException {
productList.deleteProduct(pid);
Ui.printDeleteSuccessMessage();
LOGGER.log(Level.INFO, Messages.MESSAGE_DELETE_SUCCESS);
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/seedu/stockpal/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import static seedu.stockpal.common.Messages.MESSAGE_ERROR_INVALID_FORMAT;
import static seedu.stockpal.common.Messages.MESSAGE_ERROR_NAME_ONLY_SPACES;


/**
* The Parser class is responsible for parsing user input into its respective command's relevant fields.
*/
public class Parser {
public static final String DIVIDER = " ";
public static final Pattern NEW_COMMAND_PATTERN =
Expand Down Expand Up @@ -199,8 +201,17 @@ private static ArrayList<String> matchAndParseInput(String input, Pattern patter
return parsed;
}

/**
* Parses the input string supplied by the user to the UI of StockPal into its respective command fields.
*
* @param input The input string to be parsed
* @return A specific Command object containing parsed components of input
* @throws InvalidFormatException If input string is not matched with its respective command regex pattern.
* @throws UnsignedIntegerExceededException If parsed PID or quantity exceeds Integer.MAX_VALUE
* @throws InvalidCommandException If input's first word (which is command word) is not a legal command word
*/
public Command parseInput(String input)
throws InvalidFormatException, InvalidCommandException, UnsignedIntegerExceededException {
throws InvalidCommandException, InvalidFormatException, UnsignedIntegerExceededException {
ArrayList<String> parsed;
input = input.stripLeading();
String command = getCommandFromInput(input);
Expand Down

0 comments on commit 54863d9

Please sign in to comment.