Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS2113-W13-1] Your Mother’s Favorite CookBook (YMFC) #5

Open
wants to merge 422 commits into
base: master
Choose a base branch
from

Conversation

gskang-22
Copy link

@gskang-22 gskang-22 commented Sep 18, 2024

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


public class YMFC {
public static Logger logger = Logger.getLogger(YMFC.class.getName());
private static final String saveFilePath = "./data/recipes.txt";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant names must be all uppercase using underscore to separate words

saidBye = true;
logger.log(Level.INFO, "User said bye");
}
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>.*)");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not reuse formal parameters as local variables inside the method

Comment on lines 79 to 135
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));
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid long methods. Perhaps you could extract some of the functionality into another method

Comment on lines 126 to 134
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));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these conditions really necessary?

}

public boolean removeRecipeByName(String name) {
assert counter > 0 : "List should not be empty when deleting recipe";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to be an assertion or exception?

if (isEmpty) {
return;
}
ListCommand c = new ListCommand();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highly recommend using more informative variable names, "c" doesn't give much context on what the variable refers to

gskang and others added 29 commits October 29, 2024 20:57
# Conflicts:
#	docs/DeveloperGuide.md
#	docs/puml/AddRecipes.puml
Update attributes to be private instead of public
Fix visibility of attributes in Recipe class
Add and improve JavaDoc comments
docs: Update `Recipe` and `RecipeList` sections of DG
3CCLY and others added 30 commits November 11, 2024 23:16
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
…iagram.png`

Changes:
- Manually remove redundant part of lifelines
- Reposition return arrow of `command:EditCommand` in `EditRecipeSequenceDiagram.png`
Format UG to support PDF printing
Claiming authorship UG, DG and finalizing PPP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.