Skip to content

Commit

Permalink
Implement FindEmailCommand class
Browse files Browse the repository at this point in the history
  • Loading branch information
yooplo committed Oct 10, 2024
1 parent 286cf1e commit cc41ca1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class AbstractFindCommand extends Command {
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";

private final ContainsKeywordsPredicate predicate;
protected final ContainsKeywordsPredicate predicate;

public AbstractFindCommand(ContainsKeywordsPredicate predicate) {
this.predicate = predicate;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/seedu/address/logic/commands/FindEmailCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.address.logic.commands;

import seedu.address.model.person.EmailContainsKeywordsPredicate;

public class FindEmailCommand extends AbstractFindCommand {

public static final String COMMAND_WORD = "find /e";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose emails "
+ "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";

public FindEmailCommand(EmailContainsKeywordsPredicate predicate) {
super(predicate);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof FindEmailCommand otherFindCommand)) {
return false;
}
return super.predicate.equals(otherFindCommand.predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public EmailContainsKeywordsPredicate(List<String> keywords) {
super(keywords);
}

// checks if the person contains the keyword
@Override
public boolean test(Person person) {
return super.getKeywords().stream()
Expand All @@ -27,11 +28,10 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof EmailContainsKeywordsPredicate)) {
if (!(other instanceof EmailContainsKeywordsPredicate otherNameContainsKeywordsPredicate)) {
return false;
}

EmailContainsKeywordsPredicate otherNameContainsKeywordsPredicate = (EmailContainsKeywordsPredicate) other;
return this.getKeywords().equals(otherNameContainsKeywordsPredicate.getKeywords());
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof Person)) {
if (!(other instanceof Person otherPerson)) {
return false;
}

Person otherPerson = (Person) other;
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
Expand Down

0 comments on commit cc41ca1

Please sign in to comment.