Skip to content

Commit

Permalink
Handle invalid unit data in menu.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaniceTang committed Nov 11, 2023
1 parent 05d1c87 commit 8e90c37
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/seedu/cafectrl/storage/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,26 @@ private static void decodeDishString(String dishString, ArrayList<Dish> menuDish
* @param ingredientsStringArray An array of strings containing encoded ingredient data.
* @return An ArrayList of Ingredient objects containing the decoded ingredient information.
*/
private static ArrayList<Ingredient> decodeIngredientData(String[] ingredientsStringArray) {
private static ArrayList<Ingredient> decodeIngredientData(String[] ingredientsStringArray) throws Exception{
ArrayList<Ingredient> ingredientList = new ArrayList<>();
for(String ingredientString : ingredientsStringArray) {
logger.info("Ingredient to decode: " + ingredientString);
String[] array = ingredientString.split(INGREDIENT_DIVIDER);
String name = array[0].trim();
int qty = Integer.parseInt(array[1].trim());
String unit = array[2].trim();
checkUnitValidity(unit);
ingredientList.add(new Ingredient(name, qty, unit));
}
return ingredientList;
}

private static void checkUnitValidity(String unit) throws Exception {
if (!Parser.isValidUnit(unit) || Parser.isEmptyUnit(unit)) {
throw new Exception();
}
}

//@@author ziyi105
/**
* Decodes raw string from pantry stock data file and create ingredient object from the data
Expand Down

0 comments on commit 8e90c37

Please sign in to comment.