Skip to content

Commit

Permalink
Add error message with blank search in find
Browse files Browse the repository at this point in the history
Key Changes:
* The find command with prefix and no keywords show error message
  • Loading branch information
PateShin committed Apr 10, 2024
1 parent 82fc4e9 commit 27d572e
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/main/java/seedu/address/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,48 @@ public class FindCommandParser implements Parser<FindCommand> {
* @throws ParseException if the user input does not conform the expected format
*/
public FindCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_PHONE,
CliSyntax.PREFIX_EMAIL, CliSyntax.PREFIX_ID, CliSyntax.PREFIX_YEAR_JOINED, CliSyntax.PREFIX_TAG);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args,
CliSyntax.PREFIX_NAME, CliSyntax.PREFIX_PHONE,
CliSyntax.PREFIX_EMAIL, CliSyntax.PREFIX_ID,
CliSyntax.PREFIX_YEAR_JOINED, CliSyntax.PREFIX_TAG);

if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent()) {
if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_NAME).get().isEmpty()) {
List<String> keywords = Arrays.asList(
argMultimap.getValue(CliSyntax.PREFIX_NAME).get().split("\\s+"));
return new FindCommand(new NameContainsKeywordsPredicate(keywords));
} else if (argMultimap.getValue(CliSyntax.PREFIX_PHONE).isPresent()) {
} else if (argMultimap.getValue(CliSyntax.PREFIX_PHONE).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_PHONE).get().isEmpty()) {
return new FindCommand(new PhoneContainsKeywordsPredicate(
argMultimap.getAllValues(CliSyntax.PREFIX_PHONE)));
} else if (argMultimap.getValue(CliSyntax.PREFIX_EMAIL).isPresent()) {
} else if (argMultimap.getValue(CliSyntax.PREFIX_EMAIL).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_EMAIL).get().isEmpty()) {
return new FindCommand(new EmailContainsKeywordsPredicate(
argMultimap.getAllValues(CliSyntax.PREFIX_EMAIL)));
} else if (argMultimap.getValue(CliSyntax.PREFIX_ID).isPresent()) {
} else if (argMultimap.getValue(CliSyntax.PREFIX_ID).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_ID).get().isEmpty()) {
return new FindCommand(new IdEqualsPredicate(
argMultimap.getValue(CliSyntax.PREFIX_ID).get()));
} else if (argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).isPresent()) {
} else if (argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).get().isEmpty()) {
return new FindCommand(new YearJoinedEqualsPredicate(
argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).get()));
} else if (argMultimap.getValue(CliSyntax.PREFIX_TAG).isPresent()) {
} else if (argMultimap.getValue(CliSyntax.PREFIX_TAG).isPresent() &&
!argMultimap.getValue(CliSyntax.PREFIX_TAG).get().isEmpty()) {
return new FindCommand(new TagEqualsPredicate(
argMultimap.getValue(CliSyntax.PREFIX_TAG).get()));
} else if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent()) {
throw new ParseException("Name to find cannot be empty");
} else if (argMultimap.getValue(CliSyntax.PREFIX_PHONE).isPresent()) {
throw new ParseException("Phone number to find cannot be empty");
} else if (argMultimap.getValue(CliSyntax.PREFIX_EMAIL).isPresent()) {
throw new ParseException("Email to find cannot be empty");
} else if (argMultimap.getValue(CliSyntax.PREFIX_ID).isPresent()) {
throw new ParseException("ID to find cannot be empty");
} else if (argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).isPresent()) {
throw new ParseException("Year joined to find cannot be empty");
} else if (argMultimap.getValue(CliSyntax.PREFIX_TAG).isPresent()) {
throw new ParseException("Tag to find cannot be empty");
} else {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}
Expand Down

0 comments on commit 27d572e

Please sign in to comment.