This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
forked from nus-cs2103-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into branch-SortEvent
# Conflicts: # src/main/java/ezschedule/logic/Logic.java # src/main/java/ezschedule/logic/LogicManager.java # src/main/java/ezschedule/model/Model.java # src/test/java/ezschedule/logic/commands/AddCommandTest.java
- Loading branch information
Showing
36 changed files
with
853 additions
and
171 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
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
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
31 changes: 24 additions & 7 deletions
31
src/main/java/ezschedule/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,32 +1,49 @@ | ||
package ezschedule.logic.parser; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
import ezschedule.commons.core.Messages; | ||
import ezschedule.logic.commands.FindCommand; | ||
import ezschedule.logic.commands.FindCommand.FindEventDescriptor; | ||
import ezschedule.logic.parser.exceptions.ParseException; | ||
import ezschedule.model.event.EventContainsKeywordsPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new FindCommand object | ||
*/ | ||
public class FindCommandParser implements Parser<FindCommand> { | ||
|
||
/** | ||
* Returns true if any of the prefixes contains empty {@code Optional} values | ||
* in the given {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean areAnyPrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).anyMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
/** | ||
* 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 { | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_DATE); | ||
|
||
if (!areAnyPrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_DATE) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException( | ||
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
String[] nameKeywords = trimmedArgs.split("\\s+"); | ||
FindEventDescriptor findEventDescriptor = new FindEventDescriptor(); | ||
if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent()) { | ||
findEventDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(CliSyntax.PREFIX_NAME).get())); | ||
} | ||
if (argMultimap.getValue(CliSyntax.PREFIX_DATE).isPresent()) { | ||
findEventDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(CliSyntax.PREFIX_DATE).get())); | ||
} | ||
|
||
return new FindCommand(new EventContainsKeywordsPredicate(Arrays.asList(nameKeywords))); | ||
return new FindCommand(findEventDescriptor); | ||
} | ||
} |
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
Oops, something went wrong.