Skip to content

Commit

Permalink
Merge pull request #214 from ziyi105/184-encode-pantrt-stock-with-regex
Browse files Browse the repository at this point in the history
Debug encoding pantry stock cannot add more than one ingredient
  • Loading branch information
DextheChik3n authored Nov 1, 2023
2 parents 17d681a + 2b6b642 commit d80103e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/cafectrl/command/AddDishCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AddDishCommand extends Command {
public static final String MESSAGE_USAGE = "To add a new dish to the menu: \n"
+ COMMAND_WORD + " name/DISH_NAME price/DISH_PRICE ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY"
+ "[, ingredient/INGREDIENT2_NAME, qty/INGREDIENT2_QTY...]\n"
+ "Example:\n"
+ "Example:"
+ COMMAND_WORD + " name/chicken rice price/3.00 ingredient/rice qty/200g, ingredient/chicken qty/100g";

protected Menu menu;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/cafectrl/command/AddOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AddOrderCommand extends Command {
public static final String COMMAND_WORD = "add_order";
public static final String MESSAGE_USAGE = "To add a new order: \n"
+ COMMAND_WORD
+ "name/DISH_NAME qty/QUANTITY\n"
+ " name/DISH_NAME qty/QUANTITY\n"
+ "Example: " + COMMAND_WORD
+ "name/chicken rice qty/2";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BuyIngredientCommand extends Command {
public static final String MESSAGE_USAGE = "\nTo buy ingredient:\n"
+ COMMAND_WORD + " ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY"
+ "[, ingredient/INGREDIENT2_NAME, qty/INGREDIENT2_QTY...]\n"
+ "Example:\n"
+ "Example:"
+ COMMAND_WORD + " ingredient/rice qty/200g, ingredient/chicken qty/100g";

protected Ui ui;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/cafectrl/command/EditPriceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class EditPriceCommand extends Command {
public static final String COMMAND_WORD = "edit_price";
public static final String MESSAGE_USAGE = COMMAND_WORD + "To edit price of a menu item: \n"
public static final String MESSAGE_USAGE = "To edit price of a menu item: \n"
+ "edit_price index/DISH_INDEX price/NEW_PRICE\n"
+ "Example: edit_price index/1 price/4.50";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class ViewTotalStockCommand extends Command {

public static final String COMMAND_WORD = "view_stock";
public static final String MESSAGE_USAGE = "To view pantry stock:\n " + COMMAND_WORD;
public static final String MESSAGE_USAGE = "To view pantry stock:\n" + COMMAND_WORD;
protected Ui ui;
protected Pantry pantry;
private ArrayList<Ingredient> pantryStock;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/cafectrl/storage/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static Pantry decodePantryStockData(ArrayList<String> encodedPantryStock)
ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA);
} else {
Ingredient ingredient = new Ingredient(decodedData[0],
Integer.parseInt(decodedData[1]), decodedData[2]);
Integer.parseInt(decodedData[1].trim()), decodedData[2]);
pantryStock.add(ingredient);
}
}
Expand All @@ -99,7 +99,7 @@ private static boolean isValidPantryStockFormat(String[] decodedPantryStock) {
return false;
} else {
try {
Integer.parseInt(decodedPantryStock[1]);
Integer.parseInt(decodedPantryStock[1].trim());
} catch (NumberFormatException e) {
ui.showToUser(ErrorMessages.ERROR_IN_PANTRY_STOCK_DATA);
return false;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/seedu/cafectrl/storage/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ public static ArrayList<String> encodePantryStock(Pantry pantry) {
ArrayList<String> pantryStockInString = new ArrayList<>();
ArrayList<Ingredient> pantryStock = pantry.getPantryStock();
for (Ingredient ingredient : pantryStock) {
String encodedIngredient = ingredient.getName() + DIVIDER
+ ingredient.getQty() + DIVIDER + ingredient.getUnit();
pantryStockInString.add(encodedIngredient);
StringBuilder encodedIngredient = new StringBuilder();
encodedIngredient.append(ingredient.getName());
encodedIngredient.append(DIVIDER);
encodedIngredient.append(ingredient.getQty());
encodedIngredient.append(DIVIDER);
encodedIngredient.append(ingredient.getUnit());
encodedIngredient.append(System.lineSeparator());
pantryStockInString.add(encodedIngredient.toString());
}
return pantryStockInString;
}
Expand Down

0 comments on commit d80103e

Please sign in to comment.