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

Update findby command with new fields #62

Merged
Merged
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
22 changes: 18 additions & 4 deletions src/main/java/seedu/address/logic/commands/FindByCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEVICEINFO;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ORGID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Arrays;
import java.util.stream.Collectors;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.parser.Prefix;
Expand All @@ -26,12 +32,20 @@ public class FindByCommand extends Command {
PREFIX_PHONE,
PREFIX_EMAIL,
PREFIX_ADDRESS,
PREFIX_TAG
PREFIX_TAG,
PREFIX_STATUS,
PREFIX_ORGID,
PREFIX_DEVICEINFO,
};

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons by specifying attributes that "
+ "should contain any of the specified keywords (case-insensitive) and displays them as a list with index"
+ " numbers.\nParameters: KEYWORD [MORE_KEYWORDS]...\n"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons by specifying an attribute that"
+ " should contain any of the specified keywords (case-insensitive) and displays them as a list with index"
+ " numbers.\n"
+ "Supported prefixes: "
+ Arrays.stream(FINDBY_PREFIXES)
.map(Prefix::toString)
.collect(Collectors.joining(", "))
+ "\nParameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " e/ alice";

private final AttributeContainsKeywordsPredicate predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import seedu.address.logic.Messages;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.AttributeContainsKeywordsPredicate;

/**
* Stores mapping of prefixes to their respective arguments.
Expand Down Expand Up @@ -84,7 +83,7 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof AttributeContainsKeywordsPredicate)) {
if (!(other instanceof ArgumentMultimap)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package seedu.address.model.person;

import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEVICEINFO;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ORGID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.function.Predicate;
Expand Down Expand Up @@ -36,6 +39,12 @@ public boolean test(Person person) {
return StringUtil.containsSubstringIgnoreCase(person.getPhone().value, keyword);
} else if (prefix == PREFIX_ADDRESS) {
return StringUtil.containsSubstringIgnoreCase(person.getAddress().value, keyword);
} else if (prefix == PREFIX_STATUS) {
return StringUtil.containsSubstringIgnoreCase(person.getStatus().toString(), keyword);
} else if (prefix == PREFIX_ORGID) {
return StringUtil.containsSubstringIgnoreCase(person.getOrgID().value, keyword);
} else if (prefix == PREFIX_DEVICEINFO) {
return StringUtil.containsSubstringIgnoreCase(person.getDeviceInfo().deviceInfo, keyword);
} else if (prefix == PREFIX_TAG) {
return person.getTags().stream()
.anyMatch(tag -> StringUtil.containsSubstringIgnoreCase(tag.tagName, keyword));
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/seedu/address/logic/commands/FindByCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.fail;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.Test;

import seedu.address.logic.parser.FindByCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;

/**
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class FindByCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@Test
public void equals() {

try {
FindByCommand findFirstCommand = new FindByCommandParser().parse(" n/first");
FindByCommand findSecondCommand = new FindByCommandParser().parse(" n/second");

// same object -> returns true
findFirstCommand.equals(findFirstCommand);

// same values -> returns true
FindByCommand findFirstCommandCopy = new FindByCommandParser().parse(" n/first");
findFirstCommand.equals(findFirstCommandCopy);

// different types -> returns false
findFirstCommand.equals(1);

// null -> returns false
findFirstCommand.equals(null);

// different person -> returns false
findFirstCommand.equals(findSecondCommand);

} catch (ParseException e) {
fail("ParseException was thrown: " + e.getMessage());
}
}
}