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

[W5][W17-3]Jeremy Loye #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public ViewAllCommand(int targetVisibleIndex) {
public CommandResult execute() {
try {
final ReadOnlyPerson target = getTargetPerson();
if (!addressBook.containsPerson(target)) {
Copy link

Choose a reason for hiding this comment

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

This here is not an example of double negative. Double negative refers to having multiple negations in the conditional (e.g. !isNotFound), and does not refer to the case of using a negated condition to represent an unusual branch.

Instead, this is a guard clause, which is used here to detect an unusual condition (i.e. the target not being found in the address book). The reason for doing this is to make the 'happy path' prominent (i.e. the target being found). You can refer to the textbook chapter: https://nus-cs2103-ay1819s2.github.io/cs2103-website/se-book-adapted/chapters/codeQuality.html.

return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
if (addressBook.containsPerson(target)) {
return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowAll()));
}
return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowAll()));
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public class Messages {

public static final String MESSAGE_GOODBYE = "Good bye!";
public static final String MESSAGE_GOODBYE = "Good bye! We Hope to see you again soon!";
public static final String MESSAGE_INIT_FAILED = "Failed to initialise address book application. Exiting...";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
Expand Down
14 changes: 7 additions & 7 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ private int parseArgsAsDisplayedIndex(String args) throws ParseException, Number
*/
private Command prepareFind(String args) {
final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim());
if (!matcher.matches()) {
Copy link

Choose a reason for hiding this comment

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

No need to refactor this. Refer to the other comment about guard clauses.

return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
FindCommand.MESSAGE_USAGE));
if (matcher.matches()) {
// keywords delimited by whitespace
final String[] keywords = matcher.group("keywords").split("\\s+");
final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
return new FindCommand(keywordSet);
}
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
FindCommand.MESSAGE_USAGE));

// keywords delimited by whitespace
final String[] keywords = matcher.group("keywords").split("\\s+");
final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
return new FindCommand(keywordSet);
}


Expand Down
2 changes: 1 addition & 1 deletion test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@
|| Enter command: || [Command entered: exit]
|| Exiting Address Book as requested ...
|| ===================================================
|| Good bye!
|| Good bye! We Hope to see you again soon!
|| ===================================================
|| ===================================================