forked from nus-cs2103-AY2324S1/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 branch 'master' into lingxi/shorten-commands
- Loading branch information
Showing
23 changed files
with
1,051 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
src/main/java/seedu/address/logic/commands/FindTagCommand.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,67 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.PersonContainsTagsPredicate; | ||
import seedu.address.model.task.TaskContainsTagsPredicate; | ||
|
||
/** | ||
* Finds and lists all persons and tasks in address book whose tag contains any of the argument keywords. | ||
*/ | ||
public class FindTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "findTag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons and tasks whose tag contain any of " | ||
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" | ||
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n" | ||
+ "Example: " + COMMAND_WORD + " agenda"; | ||
private final PersonContainsTagsPredicate personPredicate; | ||
private final TaskContainsTagsPredicate taskPredicate; | ||
|
||
/** | ||
* Creates a FindTagCommand to find the specified {@code TaskContainsTagsPredicate} and | ||
* {@code PersonContainsTagsPredicate} | ||
*/ | ||
public FindTagCommand(PersonContainsTagsPredicate personPredicate, TaskContainsTagsPredicate taskPredicate) { | ||
this.taskPredicate = taskPredicate; | ||
this.personPredicate = personPredicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredTaskList(taskPredicate); | ||
model.updateFilteredPersonList(personPredicate); | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSONS_TASKS_LISTED_OVERVIEW, | ||
model.getFilteredPersonList().size(), model.getFilteredTaskList().size())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof FindTagCommand)) { | ||
return false; | ||
} | ||
|
||
FindTagCommand otherFindTagCommand = (FindTagCommand) other; | ||
return taskPredicate.equals(otherFindTagCommand.taskPredicate) | ||
&& personPredicate.equals(otherFindTagCommand.personPredicate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("personPredicate", personPredicate) | ||
.add("taskPredicate", taskPredicate) | ||
.toString(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/seedu/address/logic/commands/ListTagCommand.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,25 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.tag.TagFrequencyTable; | ||
|
||
/** | ||
* Lists all tags in CoordiMate to the user. | ||
*/ | ||
public class ListTagCommand extends Command { | ||
public static final String COMMAND_WORD = "listTag"; | ||
|
||
public static final String MESSAGE_NO_TAGS_FOUND = "No tags found!"; | ||
public static final String MESSAGE_SUCCESS = "Listed all tags: \n%s\n"; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
TagFrequencyTable tagFrequencyTable = model.getTagFrequencyTable(); | ||
|
||
if (tagFrequencyTable.isEmpty()) { | ||
return new CommandResult(MESSAGE_NO_TAGS_FOUND); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, tagFrequencyTable.format())); | ||
} | ||
} |
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/FindTagCommandParser.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.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import java.util.Arrays; | ||
|
||
import seedu.address.logic.commands.FindTagCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.PersonContainsTagsPredicate; | ||
import seedu.address.model.task.TaskContainsTagsPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new FindTagCommand object | ||
*/ | ||
public class FindTagCommandParser implements Parser<FindTagCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FindTagCommand | ||
* and returns a FindTagCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public FindTagCommand parse(String args) throws ParseException { | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindTagCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
String[] tagKeywords = trimmedArgs.split("\\s+"); | ||
|
||
return new FindTagCommand(new PersonContainsTagsPredicate(Arrays.asList(tagKeywords)), | ||
new TaskContainsTagsPredicate(Arrays.asList(tagKeywords)) | ||
); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/main/java/seedu/address/model/person/PersonContainsTagsPredicate.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,58 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import seedu.address.commons.util.StringUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Tags} matches any of the keywords given. | ||
*/ | ||
public class PersonContainsTagsPredicate implements Predicate<Person> { | ||
private final List<String> keywords; | ||
|
||
public PersonContainsTagsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
// Returns true if person's tags contain any of the keywords | ||
@Override | ||
public boolean test(Person person) { | ||
|
||
// Convert each tag of the person to its string representation and then concatenate them using spaces. | ||
// The square brackets encapsulate each tag to ensure distinctiveness when checking against keywords. | ||
// For example, tags such as [[Engineer], [Developer]] will translate to the string "[Engineer] [Developer]". | ||
String personTags = person.getTags() | ||
.stream() | ||
.map(Object::toString) | ||
.collect(Collectors.joining(" ")); | ||
|
||
// Match against the concatenated string of tags. | ||
// The square brackets ensure that keywords match against full tags rather than partial matches. | ||
// This way, a keyword like "[Eng]" won't match with the tag "[Engineer]". | ||
return keywords.stream() | ||
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(personTags, "[" + keyword + "]")); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof PersonContainsTagsPredicate)) { | ||
return false; | ||
} | ||
|
||
PersonContainsTagsPredicate otherPersonContainsTagsPredicate = (PersonContainsTagsPredicate) other; | ||
return keywords.equals(otherPersonContainsTagsPredicate.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
Oops, something went wrong.