Skip to content

Commit

Permalink
UpdateCommandParser.java: Rename method to sound more 'verb'-like
Browse files Browse the repository at this point in the history
  • Loading branch information
nur-haziq committed Apr 15, 2024
1 parent 5f0b9ba commit 57dbf6a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/seedu/binbash/parser/UpdateCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ public UpdateCommand parse(String[] commandArgs) throws ParseException {
UpdateCommand updateCommand = getUpdateCommand(commandLine);

if (commandLine.hasOption("description")) {
hasDescriptionOption(commandLine, updateCommand);
applyDescriptionOption(commandLine, updateCommand);
}
if (commandLine.hasOption("quantity")) {
hasQuantityOption(commandLine, updateCommand);
applyQuantityOption(commandLine, updateCommand);
}
if (commandLine.hasOption("cost-price")) {
hasCostPriceOption(commandLine, updateCommand);
applyCostPriceOption(commandLine, updateCommand);
}
if (commandLine.hasOption("sale-price")) {
hasSalePriceOption(commandLine, updateCommand);
applySalePriceOption(commandLine, updateCommand);
}
if (commandLine.hasOption("expiry-date")) {
hasExpirationDateOption(commandLine, updateCommand);
applyExpirationDateOption(commandLine, updateCommand);
}
if (commandLine.hasOption("threshold")) {
hasThresholdOption(commandLine, updateCommand);
applyThresholdOption(commandLine, updateCommand);
}
if (!hasOption) {
throw new ParseException("At least one of -d, -q, -c, -s, -e, -t option required");
}
return updateCommand;
}

private void hasThresholdOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
private void applyThresholdOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
String threshold = commandLine.getOptionValue("threshold");
int itemThreshold = Parser.parseIntOptionValue(threshold, "threshold");
if (itemThreshold < 0) {
Expand All @@ -77,14 +77,14 @@ private void hasThresholdOption(CommandLine commandLine, UpdateCommand updateCom
hasOption = true;
}

private void hasExpirationDateOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
private void applyExpirationDateOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
LocalDate itemExpiryDate = Parser.parseDateOptionValue(commandLine.getOptionValue("expiry-date"),
"expiry date");
updateCommand.setItemExpirationDate(itemExpiryDate);
hasOption = true;
}

private void hasSalePriceOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
private void applySalePriceOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
String salePrice = commandLine.getOptionValue("sale-price");
double itemSalePrice = Parser.parseDoubleOptionValue(salePrice, "sale price");
if (itemSalePrice < 0) {
Expand All @@ -94,7 +94,7 @@ private void hasSalePriceOption(CommandLine commandLine, UpdateCommand updateCom
hasOption = true;
}

private void hasCostPriceOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
private void applyCostPriceOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
String costPrice = commandLine.getOptionValue("cost-price");
double itemCostPrice = Parser.parseDoubleOptionValue(costPrice, "cost price");
if (itemCostPrice < 0) {
Expand All @@ -104,7 +104,7 @@ private void hasCostPriceOption(CommandLine commandLine, UpdateCommand updateCom
hasOption = true;
}

private void hasQuantityOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
private void applyQuantityOption(CommandLine commandLine, UpdateCommand updateCommand) throws ParseException {
String quantity = commandLine.getOptionValue("quantity");
int itemQuantity = Parser.parseIntOptionValue(quantity, "quantity");
if (itemQuantity < 0) {
Expand All @@ -114,7 +114,7 @@ private void hasQuantityOption(CommandLine commandLine, UpdateCommand updateComm
hasOption = true;
}

private void hasDescriptionOption(CommandLine commandLine, UpdateCommand updateCommand) {
private void applyDescriptionOption(CommandLine commandLine, UpdateCommand updateCommand) {
String itemDescription = String.join(" ", commandLine.getOptionValues("description"));
updateCommand.setItemDescription(itemDescription);
hasOption = true;
Expand Down

0 comments on commit 57dbf6a

Please sign in to comment.