Skip to content

Commit

Permalink
Refactor class name again to avoid conflicts in v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
AriellaCallista committed Oct 27, 2023
1 parent 87f2971 commit 5b12e79
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class SearchCommand extends Command {
public class FindCommand extends Command {

public static final String COMMAND_WORD = "search";

Expand All @@ -29,7 +29,7 @@ public class SearchCommand extends Command {
/**
* Creates an FindCommand to find the specified {@code Person}
*/
public SearchCommand(List<Predicate<Person>> predicatesList) {
public FindCommand(List<Predicate<Person>> predicatesList) {
this.predicatesList = predicatesList;
}

Expand All @@ -50,13 +50,13 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof SearchCommand)) {
if (!(other instanceof FindCommand)) {
return false;
}

SearchCommand otherSearchCommand = (SearchCommand) other;
FindCommand otherFindCommand = (FindCommand) other;
Boolean isListEqual = false;
List<Predicate<Person>> otherPredicates = otherSearchCommand.predicatesList;
List<Predicate<Person>> otherPredicates = otherFindCommand.predicatesList;

if (predicatesList.size() != otherPredicates.size()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.ExportCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.GithubCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.LinkedInCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -73,8 +73,8 @@ public Command parseCommand(String userInput) throws ParseException {
case ClearCommand.COMMAND_WORD:
return new ClearCommand();

case SearchCommand.COMMAND_WORD:
return new SearchCommandParser().parse(arguments);
case FindCommand.COMMAND_WORD:
return new FindCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommandParser().parse(arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.function.Predicate;
import java.util.stream.Stream;

import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
Expand All @@ -21,14 +21,14 @@
/**
* Parses input arguments and creates a new FindCommand object
*/
public class SearchCommandParser implements Parser<SearchCommand> {
public class FindCommandParser implements Parser<FindCommand> {

/**
* Parses the given {@code String} of arguments in the context of the FindCommand
* and returns a FindCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public SearchCommand parse(String args) throws ParseException {
public FindCommand parse(String args) throws ParseException {
List<String> nameKeywords = new ArrayList<>();
List<String> statusKeywords = new ArrayList<>();
List<String> tagKeywords = new ArrayList<>();
Expand All @@ -40,7 +40,7 @@ public SearchCommand parse(String args) throws ParseException {
if (!(arePrefixesPresent(argMultimap, PREFIX_NAME) || arePrefixesPresent(argMultimap, PREFIX_STATUS)
|| arePrefixesPresent(argMultimap, PREFIX_TAG))
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SearchCommand.MESSAGE_USAGE));
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}
if (arePrefixesPresent(argMultimap, PREFIX_NAME)) {
setKeywords(nameKeywords, statusKeywords, tagKeywords, argMultimap, PREFIX_NAME);
Expand All @@ -57,7 +57,7 @@ public SearchCommand parse(String args) throws ParseException {
StatusContainsKeywordsPredicate statusPredicate = new StatusContainsKeywordsPredicate(statusKeywords);
TagContainsKeywordsPredicate tagPredicate = new TagContainsKeywordsPredicate(tagKeywords);

return new SearchCommand(getPredicatesList(nameKeywords, statusKeywords, tagKeywords,
return new FindCommand(getPredicatesList(nameKeywords, statusKeywords, tagKeywords,
namePredicate, statusPredicate, tagPredicate));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand Down Expand Up @@ -235,7 +235,7 @@ private static String[] parseSearchParams(Collection<String> keywordsList) throw
Pattern pattern = Pattern.compile("[^a-zA-Z0-9]");
Matcher matcher = pattern.matcher(searchParam);
if (matcher.find()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SearchCommand.MESSAGE_USAGE));
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));

Check warning on line 238 in src/main/java/seedu/address/logic/parser/ParserUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/ParserUtil.java#L238

Added line #L238 was not covered by tests
}
}
return searchParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class SearchCommandTest {
public class FindCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());

Expand All @@ -50,14 +50,14 @@ public void equals() {
List<Predicate<Person>> firstPredicatesList = Arrays.asList(firstNamePredicate, firstStatusPredicate);
List<Predicate<Person>> secondPredicatesList = Arrays.asList(secondNamePredicate, secondStatusPredicate);

SearchCommand findFirstCommand = new SearchCommand(firstPredicatesList);
SearchCommand findSecondCommand = new SearchCommand(secondPredicatesList);
FindCommand findFirstCommand = new FindCommand(firstPredicatesList);
FindCommand findSecondCommand = new FindCommand(secondPredicatesList);

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

// same values -> returns true
SearchCommand findFirstCommandCopy = new SearchCommand(firstPredicatesList);
FindCommand findFirstCommandCopy = new FindCommand(firstPredicatesList);
assertTrue(findFirstCommand.equals(findFirstCommandCopy));

// different types -> returns false
Expand All @@ -75,7 +75,7 @@ public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
NameContainsKeywordsPredicate namePredicate = prepareNamePredicate(" ");
StatusContainsKeywordsPredicate statusPredicate = prepareStatusPredicate("");
SearchCommand command = new SearchCommand(Arrays.asList(namePredicate, statusPredicate));
FindCommand command = new FindCommand(Arrays.asList(namePredicate, statusPredicate));
expectedModel.updateFilteredPersonList(namePredicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredPersonList());
Expand All @@ -84,7 +84,7 @@ public void execute_zeroKeywords_noPersonFound() {
@Test
public void execute_multipleNameKeywords_multiplePersonsFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3);
SearchCommand command = new SearchCommand(preparePredicateList("Kurz Elle Kunz", ""));
FindCommand command = new FindCommand(preparePredicateList("Kurz Elle Kunz", ""));
expectedModel.updateFilteredPersonList(preparePredicateList("Kurz Elle Kunz", ""));
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList());
Expand All @@ -93,7 +93,7 @@ public void execute_multipleNameKeywords_multiplePersonsFound() {
@Test
public void execute_multipleStatusKeywords_multiplePersonsFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 7);
SearchCommand command = new SearchCommand(preparePredicateList("", "preliminary"));
FindCommand command = new FindCommand(preparePredicateList("", "preliminary"));
expectedModel.updateFilteredPersonList(preparePredicateList("", "preliminary"));
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE), model.getFilteredPersonList());
Expand All @@ -104,10 +104,10 @@ public void execute_multipleStatusKeywords_multiplePersonsFound() {
public void toStringMethod() {
NameContainsKeywordsPredicate namePredicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword"));
StatusContainsKeywordsPredicate statusPredicate = new StatusContainsKeywordsPredicate(Arrays.asList("keyword"));
SearchCommand searchCommand = new SearchCommand(Arrays.asList(namePredicate, statusPredicate));
String expected = SearchCommand.class.getCanonicalName() + "{predicates list=[" + namePredicate + ", "
FindCommand findCommand = new FindCommand(Arrays.asList(namePredicate, statusPredicate));
String expected = FindCommand.class.getCanonicalName() + "{predicates list=[" + namePredicate + ", "
+ statusPredicate + "]}";
assertEquals(expected, searchCommand.toString());
assertEquals(expected, findCommand.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.ExportCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.NameContainsKeywordsPredicate;
Expand Down Expand Up @@ -76,9 +76,9 @@ public void parseCommand_exit() throws Exception {
@Test
public void parseCommand_find() throws Exception {
List<String> keywords = Arrays.asList("foo", "bar", "baz");
SearchCommand command = (SearchCommand) parser.parseCommand(
SearchCommand.COMMAND_WORD + " " + "n/" + keywords.stream().collect(Collectors.joining(" ")));
assertEquals(new SearchCommand(Arrays.asList(new NameContainsKeywordsPredicate(keywords))), command);
FindCommand command = (FindCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " " + "n/" + keywords.stream().collect(Collectors.joining(" ")));
assertEquals(new FindCommand(Arrays.asList(new NameContainsKeywordsPredicate(keywords))), command);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.SearchCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.StatusContainsKeywordsPredicate;

public class SearchCommandParserTest {
public class FindCommandParserTest {

private SearchCommandParser parser = new SearchCommandParser();
private FindCommandParser parser = new FindCommandParser();

@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, SearchCommand.MESSAGE_USAGE));
assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

@Test
public void parse_validArgs_returnsFindCommand() {
// no leading and trailing whitespaces
SearchCommand expectedSearchCommand =
new SearchCommand(Arrays.asList(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")),
FindCommand expectedFindCommand =
new FindCommand(Arrays.asList(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")),
new StatusContainsKeywordsPredicate(Arrays.asList("Interviewed"))));
assertParseSuccess(parser, " n/Alice Bob st/Interviewed", expectedSearchCommand);
assertParseSuccess(parser, " n/Alice Bob st/Interviewed", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t st/Interviewed", expectedSearchCommand);
assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t st/Interviewed", expectedFindCommand);
}

@Test
public void parse_validArgsWithNoStatus_returnsFindCommand() {
// no leading and trailing whitespaces
SearchCommand expectedSearchCommand =
new SearchCommand(Arrays.asList(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))));
assertParseSuccess(parser, " n/Alice Bob", expectedSearchCommand);
FindCommand expectedFindCommand =
new FindCommand(Arrays.asList(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))));
assertParseSuccess(parser, " n/Alice Bob", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t ", expectedSearchCommand);
assertParseSuccess(parser, " n/ \n Alice \n \t Bob \t ", expectedFindCommand);
}

}

0 comments on commit 5b12e79

Please sign in to comment.