forked from AY2425S1-CS2103T-T11-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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-handle-grades-error
- Loading branch information
Showing
17 changed files
with
554 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,19 +135,40 @@ Examples: | |
* `find alex david` returns `Alex Yeoh`, `David Li`<br> | ||
![result for 'find alex david'](images/findAlexDavidResult.png) | ||
|
||
|
||
### Locating persons by tag: `filter` | ||
|
||
Finds persons whose names contain any of the given keywords. | ||
|
||
Format: `filter t/TAG [t/MORE_TAG]...` | ||
|
||
* The search is case-sensitive. e.g `friends` will not match `Friends` | ||
* At least one tag must be provided. | ||
* The order of the keywords does not matter. e.g. `t/friends t/family` will match `t/family t/friends` | ||
* Only the tags is searched. | ||
* Only full tag name will be matched e.g. `friend` will not match `friends` | ||
* Persons matching at least one keyword will be returned (i.e. `OR` search). | ||
e.g. `t/friends t/family` will return any contact tagged with `friend` or `family`. | ||
|
||
Examples: | ||
* `filter t/friend t/family` returns any contact tagged with `friend` or `family`<br> | ||
![result for 'filter t/friend t/family'](images/findAlexDavidResult.png) | ||
|
||
|
||
### Deleting a person : `delete` | ||
|
||
Deletes the specified person from the address book. | ||
|
||
Format: `delete INDEX` | ||
Format: `delete n/NAME` | ||
|
||
* Deletes the person at the specified `INDEX`. | ||
* The index refers to the index number shown in the displayed person list. | ||
* The index **must be a positive integer** 1, 2, 3, … | ||
* Deletes the person with the specified name. | ||
* The name refers to the full name of the person shown in the displayed person list. | ||
* If a person matches the name but is not shown in the list, it will not be deleted. | ||
|
||
Examples: | ||
* `list` followed by `delete 2` deletes the 2nd person in the address book. | ||
* `find Betsy` followed by `delete 1` deletes the 1st person in the results of the `find` command. | ||
* `list` followed by `delete n/Betsy` deletes the person with the name `Betsy`. | ||
* `find Betsy` followed by `delete Alex` will not delete the person named `Alex`. | ||
* `delete n/Betsy` deletes the person named `Betsy` if it is shown on the filtered list. | ||
|
||
### Clearing all entries : `clear` | ||
|
||
|
@@ -202,8 +223,9 @@ Action | Format, Examples | |
-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
**Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS telegram/TELEGRAM [t/TAG]… github/GITHUB` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 telegram/@James t/friend t/colleague github/james-cool` | ||
**Clear** | `clear` | ||
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Delete** | `delete n/NAME`<br> e.g., `delete n/James` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [telegram/TELEGRAM] [t/TAG]… [github/GITHUB]`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake` | ||
**Filter** | `filter t/[TAG] t/[MORE_TAG]…`<br> e.g., `filter t/friends t/family` | ||
**List** | `list` | ||
**Help** | `help` |
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
63 changes: 63 additions & 0 deletions
63
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,63 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.TagContainsKeywordsPredicate; | ||
|
||
/** | ||
* Finds and lists all persons in address book whose tag equals to any of the specified tag. | ||
* Tag name must be the same (case sensitive). | ||
*/ | ||
public class FilterCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "filter"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filter the list to show all contacts whose tag " | ||
+ "contain any of the specified keywords (case-insensitive) and displays them as a list with index " | ||
+ "numbers.\n" | ||
+ "Parameters: " + PREFIX_TAG + "TAG" + "[" + PREFIX_TAG + "MORE_TAG]... " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_TAG + "student " | ||
+ PREFIX_TAG + "T02"; | ||
|
||
private final TagContainsKeywordsPredicate predicate; | ||
|
||
public FilterCommand(TagContainsKeywordsPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(predicate); | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof FilterCommand)) { | ||
return false; | ||
} | ||
|
||
FilterCommand otherFilterCommand = (FilterCommand) other; | ||
return predicate.equals(otherFilterCommand.predicate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("predicate", predicate) | ||
.toString(); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.FilterCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.TagContainsKeywordsPredicate; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates 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 | ||
*/ | ||
public FilterCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_TAG); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_TAG) || !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE)); | ||
} | ||
Set<Tag> taglist = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
|
||
return new FilterCommand(new TagContainsKeywordsPredicate(taglist)); | ||
} | ||
|
||
|
||
|
||
/** | ||
* 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()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/seedu/address/model/person/TagContainsKeywordsPredicate.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,47 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Tag} matches any of the given tag. | ||
*/ | ||
public class TagContainsKeywordsPredicate implements Predicate<Person> { | ||
|
||
private final Set<Tag> keywords; | ||
|
||
public TagContainsKeywordsPredicate(Set<Tag> keywords) { | ||
this.keywords = keywords; | ||
} | ||
@Override | ||
public boolean test(Person person) { | ||
return keywords.stream().anyMatch(keyword -> person.getTags().contains(keyword)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof TagContainsKeywordsPredicate)) { | ||
return false; | ||
} | ||
|
||
TagContainsKeywordsPredicate otherTagContainsKeywordsPredicate = (TagContainsKeywordsPredicate) other; | ||
return keywords.equals(otherTagContainsKeywordsPredicate.keywords); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("keywords", keywords).toString(); | ||
} | ||
|
||
|
||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
"email" : "[email protected]", | ||
"address" : "4th street", | ||
"telegram": "@George", | ||
"tags" : [ ], | ||
"tags" : [ "husband" ], | ||
"github" : "George" | ||
} ] | ||
} |
Oops, something went wrong.