[CS2113-W13-1] Your Mother’s Favorite CookBook (YMFC)#5
[CS2113-W13-1] Your Mother’s Favorite CookBook (YMFC)#5gskang-22 wants to merge 422 commits intonus-cs2113-AY2425S1:masterfrom
Conversation
src/main/java/ymfc/YMFC.java
Outdated
|
|
||
| public class YMFC { | ||
| public static Logger logger = Logger.getLogger(YMFC.class.getName()); | ||
| private static final String saveFilePath = "./data/recipes.txt"; |
There was a problem hiding this comment.
Constant names must be all uppercase using underscore to separate words
src/main/java/ymfc/YMFC.java
Outdated
| saidBye = true; | ||
| logger.log(Level.INFO, "User said bye"); | ||
| } | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Is the variable name "e" informative enough?
|
|
||
| /** | ||
| * Parses user input commands and return a <code>Command</code> object | ||
| * @param commandString Input command as <code>String</code> |
There was a problem hiding this comment.
There should be punctuation after every parameter description
| */ | ||
| public final class Parser { | ||
| // First word <command> before the first white space, then all the arguments <args> | ||
| // static final Pattern GENERIC_FORMAT = Pattern.compile("(?<command>\\S+)\\s+(?<args>.*)"); |
There was a problem hiding this comment.
Do not leave code commented in your program. If unused, just remove it
| private static SortCommand getSortCommand(String args) throws InvalidArgumentException { | ||
| final Pattern sortCommandFormat = | ||
| Pattern.compile("(?<name>[sS]/[^/]+)"); | ||
| args = args.trim(); |
There was a problem hiding this comment.
Do not reuse formal parameters as local variables inside the method
| private static AddRecipeCommand getAddRecipeCommand(String args) throws InvalidArgumentException { | ||
|
|
||
|
|
||
| final Pattern addRecipeCommandFormat = | ||
| // <n or N>/<String without forward slash> | ||
| Pattern.compile("(?<name>[nN]/[^/]+)" | ||
| // Match ingredients: at least one i/ or I/ followed by any characters except '/' | ||
| + "(?<ingreds>(\\s+[iI]/[^/]+)+)" | ||
| // Match steps: at least one sX/ or SX/ (X is a number) followed by any characters except '/' | ||
| + "(?<steps>(\\s+[sS][0-9]+/[^/]+)+)" | ||
| // Match optional cuisine: c/ or C/ followed by any characters except '/' | ||
| + "(\\s+(?<cuisine>[cC]/[^/]+))?" | ||
| // Match optional time taken: t/ or T/ followed by digits | ||
| + "(\\s+(?<time>[tT]/[0-9]+))?"); | ||
|
|
||
| args = args.trim(); | ||
| Matcher m = addRecipeCommandFormat.matcher(args); | ||
| if (!m.matches()) { | ||
| throw new InvalidArgumentException("Invalid argument(s): " + args + "\n" + AddRecipeCommand.USAGE_EXAMPLE); | ||
| } | ||
|
|
||
| String name = m.group("name").trim().substring(2); // n/ or N/ are 2 chars | ||
| String ingredString = m.group("ingreds"); | ||
| String stepString = m.group("steps"); | ||
| ArrayList<String> ingreds = Arrays.stream(ingredString.split("\\s+[iI]/")) | ||
| .filter(s -> !s.isEmpty()) | ||
| .collect(Collectors.toCollection(ArrayList::new)); | ||
| ArrayList<String> steps = Arrays.stream(stepString.split("\\s+[sS][0-9]+/")) | ||
| .filter(s -> !s.isEmpty()) | ||
| .collect(Collectors.toCollection(ArrayList::new)); | ||
|
|
||
| String cuisine = m.group("cuisine") != null ? m.group("cuisine").trim().substring(2) : null; | ||
| String timeTakenString = m.group("time"); | ||
|
|
||
| Integer timeTaken = null; | ||
|
|
||
| if (timeTakenString != null) { | ||
| try { | ||
| timeTaken = Integer.parseInt(timeTakenString.trim().substring(2)); | ||
| if (timeTaken <= 0) { | ||
| throw new InvalidArgumentException("Invalid time: " + timeTakenString); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| throw new InvalidArgumentException("Invalid time: " + timeTakenString); | ||
| } | ||
| } | ||
|
|
||
| if (cuisine != null && timeTaken != null) { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, cuisine, timeTaken)); | ||
| } else if (cuisine != null){ | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, cuisine)); | ||
| } else if (timeTaken != null) { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, timeTaken)); | ||
| } else { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Try to avoid long methods. Perhaps you could extract some of the functionality into another method
| if (cuisine != null && timeTaken != null) { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, cuisine, timeTaken)); | ||
| } else if (cuisine != null){ | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, cuisine)); | ||
| } else if (timeTaken != null) { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps, timeTaken)); | ||
| } else { | ||
| return new AddRecipeCommand(new Recipe(name, ingreds, steps)); | ||
| } |
| } | ||
|
|
||
| public boolean removeRecipeByName(String name) { | ||
| assert counter > 0 : "List should not be empty when deleting recipe"; |
There was a problem hiding this comment.
Is this intended to be an assertion or exception?
| if (isEmpty) { | ||
| return; | ||
| } | ||
| ListCommand c = new ListCommand(); |
There was a problem hiding this comment.
Highly recommend using more informative variable names, "c" doesn't give much context on what the variable refers to
# Conflicts: # docs/DeveloperGuide.md # docs/puml/AddRecipes.puml
Command part for DG
Update attributes to be private instead of public
Fix visibility of attributes in Recipe class
Add and improve JavaDoc comments
Add UML for EditCommand
Add ingredients class diagram
docs: Update `Recipe` and `RecipeList` sections of DG
Make recommend command ignore case for ingredients
Update seanngja's PPP, claim authorship of lines in DG, UG
Add hyperlinks to seanngja PPP
Add KSanjith authorship to DG and UG
Add page breaks in PPP
Finalise PPP
…iagram.png` Changes: - Manually remove redundant part of lifelines - Reposition return arrow of `command:EditCommand` in `EditRecipeSequenceDiagram.png`
Update PPP and DG
Finalize DG
Format UG to support PDF printing
Claiming authorship UG, DG and finalizing PPP
Fix language error in DG
Cooks these days have more recipes than they know how to handle, and our product will help them store, retrieve and search through their recipes with ease. Prompts, tags and ingredients can be used to search a curated database, and recommend random recipes that closely match the criteria