diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 7dd284d97a1..cae2785ab1d 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -25,28 +25,48 @@ public class FindCommandParser implements Parser { * @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 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)); }