From 5b12e7937f49d39a0c2c9d9ad8df9621c631929c Mon Sep 17 00:00:00 2001 From: AriellaCallista Date: Fri, 27 Oct 2023 09:00:14 +0800 Subject: [PATCH] Refactor class name again to avoid conflicts in v1.3 --- .../{SearchCommand.java => FindCommand.java} | 10 ++++---- .../logic/parser/AddressBookParser.java | 6 ++--- ...mandParser.java => FindCommandParser.java} | 10 ++++---- .../address/logic/parser/ParserUtil.java | 4 ++-- ...hCommandTest.java => FindCommandTest.java} | 20 ++++++++-------- .../logic/parser/AddressBookParserTest.java | 8 +++---- ...erTest.java => FindCommandParserTest.java} | 24 +++++++++---------- 7 files changed, 41 insertions(+), 41 deletions(-) rename src/main/java/seedu/address/logic/commands/{SearchCommand.java => FindCommand.java} (87%) rename src/main/java/seedu/address/logic/parser/{SearchCommandParser.java => FindCommandParser.java} (93%) rename src/test/java/seedu/address/logic/commands/{SearchCommandTest.java => FindCommandTest.java} (88%) rename src/test/java/seedu/address/logic/parser/{SearchCommandParserTest.java => FindCommandParserTest.java} (63%) diff --git a/src/main/java/seedu/address/logic/commands/SearchCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java similarity index 87% rename from src/main/java/seedu/address/logic/commands/SearchCommand.java rename to src/main/java/seedu/address/logic/commands/FindCommand.java index 974d552ade4..60b92604e0b 100644 --- a/src/main/java/seedu/address/logic/commands/SearchCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -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"; @@ -29,7 +29,7 @@ public class SearchCommand extends Command { /** * Creates an FindCommand to find the specified {@code Person} */ - public SearchCommand(List> predicatesList) { + public FindCommand(List> predicatesList) { this.predicatesList = predicatesList; } @@ -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> otherPredicates = otherSearchCommand.predicatesList; + List> otherPredicates = otherFindCommand.predicatesList; if (predicatesList.size() != otherPredicates.size()) { return false; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 9439b448fda..203e6475355 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -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; @@ -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); diff --git a/src/main/java/seedu/address/logic/parser/SearchCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java similarity index 93% rename from src/main/java/seedu/address/logic/parser/SearchCommandParser.java rename to src/main/java/seedu/address/logic/parser/FindCommandParser.java index 1ca95dd8f4c..22786fe7789 100644 --- a/src/main/java/seedu/address/logic/parser/SearchCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -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; @@ -21,14 +21,14 @@ /** * Parses input arguments and creates a new FindCommand object */ -public class SearchCommandParser implements Parser { +public class FindCommandParser implements Parser { /** * 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 nameKeywords = new ArrayList<>(); List statusKeywords = new ArrayList<>(); List tagKeywords = new ArrayList<>(); @@ -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); @@ -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)); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b44b39a277c..f246bd5a8be 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -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; @@ -235,7 +235,7 @@ private static String[] parseSearchParams(Collection 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)); } } return searchParams; diff --git a/src/test/java/seedu/address/logic/commands/SearchCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java similarity index 88% rename from src/test/java/seedu/address/logic/commands/SearchCommandTest.java rename to src/test/java/seedu/address/logic/commands/FindCommandTest.java index a236abcdfca..18cb690f529 100644 --- a/src/test/java/seedu/address/logic/commands/SearchCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -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()); @@ -50,14 +50,14 @@ public void equals() { List> firstPredicatesList = Arrays.asList(firstNamePredicate, firstStatusPredicate); List> 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 @@ -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()); @@ -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()); @@ -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()); @@ -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()); } /** diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 59620f74ee7..5536b0065ce 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -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; @@ -76,9 +76,9 @@ public void parseCommand_exit() throws Exception { @Test public void parseCommand_find() throws Exception { List 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 diff --git a/src/test/java/seedu/address/logic/parser/SearchCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java similarity index 63% rename from src/test/java/seedu/address/logic/parser/SearchCommandParserTest.java rename to src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index f0d37994789..ccd870cfc61 100644 --- a/src/test/java/seedu/address/logic/parser/SearchCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -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); } }