forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from notnotmax/v1.3-unabstract-find-command
Revert abstraction of FindCommand
- Loading branch information
Showing
6 changed files
with
46 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
src/main/java/seedu/address/logic/commands/FindNameCommand.java
This file was deleted.
Oops, something went wrong.
35 changes: 10 additions & 25 deletions
35
src/main/java/seedu/address/logic/parser/FindCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,32 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import java.util.Arrays; | ||
|
||
import seedu.address.logic.commands.FindCommand; | ||
import seedu.address.logic.commands.FindNameCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.student.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new FindNameCommand object | ||
* Parses input arguments and creates a new FindCommand object | ||
*/ | ||
public class FindCommandParser implements Parser<FindCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FindNameCommand | ||
* and returns a FindNameCommand object for execution. | ||
* 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 FindCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME); | ||
|
||
if (!argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindNameCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME)) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindNameCommand.MESSAGE_USAGE)); | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
List<String> nameKeywords = argMultimap.getAllValues(PREFIX_NAME); | ||
String[] nameKeywords = trimmedArgs.split("\\s+"); | ||
|
||
return new FindNameCommand(new NameContainsKeywordsPredicate(nameKeywords)); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters