forked from nus-cs2103-AY2223S1/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 #39 from dr-arrgghh/filter-branch
Filter branch
- Loading branch information
Showing
7 changed files
with
264 additions
and
111 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
35 changes: 35 additions & 0 deletions
35
src/main/java/seedu/address/logic/commands/FilterCommand.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Filters and list all persons in the address book | ||
*/ | ||
public class FilterCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "filter"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters all persons whose names contain any of " | ||
+ "the specified alphabets (case-insensitive) and displays them as a list with index numbers.\n" | ||
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n" | ||
+ "Example: " + COMMAND_WORD + " alex"; | ||
|
||
private final NameContainsKeywordsPredicate predicate; | ||
|
||
public FilterCommand(NameContainsKeywordsPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(predicate); | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/java/seedu/address/logic/parser/FilterCommandParser.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import java.util.Arrays; | ||
|
||
import seedu.address.logic.commands.FilterCommand; | ||
import seedu.address.logic.commands.FindCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
|
||
/** | ||
* Parses input arguments and create a new FilterCommand object | ||
*/ | ||
public class FilterCommandParser implements Parser<FilterCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FilterCommand | ||
* and returns a FilterCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
@Override | ||
public FilterCommand parse(String args) throws ParseException { | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
String[] nameKeywords = trimmedArgs.split("\\s+"); | ||
|
||
return new FilterCommand(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