Skip to content

Commit

Permalink
Merge pull request #67 from ZhangH795/1.3_Enhancement
Browse files Browse the repository at this point in the history
1.3 enhancement
  • Loading branch information
dalessr authored Oct 25, 2017
2 parents e320366 + 50e48a4 commit 0f032f8
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 75 deletions.
19 changes: 13 additions & 6 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,33 +205,36 @@ Format: `t-add [TAG] INDEX`
* Adds tag to the person(s) at the specified `INDEX`.
* The index refers to the index number shown in the most recent listing, multiple indices are allowed.
* The index *must be a positive integer* 1, 2, 3, ...
* The [TAG] *must not have its first word as number*
****

Examples:

* `list` +
`t-add friends 2 3` +
`t-add 2 3 friends` +
Adds the tag friends to the 2nd and 3rd person in the address book

=== Removing a tag to a person(s) : `t-remove` _[Since v1.2]_

Removes a tag from specified person(s) from the address book. +
Format: `t-remove [TAG] INDEX`
Format: `t-remove INDEX... [TAG]`

****
* Removes a tag from the person(s) at the specified `INDEX`.
* The index refers to the index number shown in the most recent listing, multiple indices are allowed.
* The index *must be a positive integer* 1, 2, 3, ...
* The [TAG] *must not have its first word as number*
****

Examples:

* `list` +
`t-remove friends 2 3` +
`t-remove 2 3 friends` +
Removes the tag friends from the 2nd and 3rd person in the address book

=== Find the person(s) with given tags: `t-find` _[Since v1.3]_
Format: `t-find TAG TAG..`

Format: `t-find TAG`

****
* Find the person(s) with given tags.
Expand Down Expand Up @@ -421,8 +424,12 @@ e.g. `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 123466
e.g. `delete 3 4`
* *Edit* : `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]...` +
e.g. `edit 2 n/James Lee e/[email protected]`
* *TagAdd* : `t-add [TAG] INDEX INDEX...` +
e.g. `t-add friends 3 4`
* *TagAdd* : `t-add INDEX INDEX... [TAG]` +
e.g. `t-add 3 4 friends`
* *TagFind* : `t-find [TAG]` +
e.g. `t-find friends`
* *TagRemove* : `t-remove INDEX INDEX... [TAG]` +
e.g. `t-remove 3 4 friends`
* *Find* : `find KEYWORD [MORE_KEYWORDS]` +
e.g. `find James Jake`
* *Sort* : `sort [n/(ASC/DSC)] [p/(ASC/DSC)] [e/(ASC/DSC)] [a/(ASC/DSC)]` +
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/TagAddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class TagAddCommand extends UndoableCommand {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add tag to the person(s) identified "
+ "by the index number used in the last person listing. "
+ "Input tag will append to the existing tags.\n"
+ "Parameters: [TAG] "
+ "INDEX1 INDEX2... (must be a positive integer)"
+ "Example: " + COMMAND_WORD + " [friends] "
+ "1 2 3 ";
+ "Parameters: INDEX1 INDEX2... (must be a positive integer) "
+ "[TAG] (TAG Should not start with a number).\n"
+ "Example: " + COMMAND_WORD + " 1 2 3 "
+ "[friends]";

public static final String MESSAGE_ADD_TAG_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/commands/TagFindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.commands;

import seedu.address.model.tag.TagMatchingKeywordPredicate;

/**
* Finds and lists all persons in address book whose name contains a certain tag.
* Keyword matching is case insensitive.
*/
public class TagFindCommand extends Command {

public static final String COMMAND_WORD = "t-find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose tags contain any of "
+ "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n"
+ "Parameters: [TAG] \n"
+ "Example: " + COMMAND_WORD + " " + "friends";

private final TagMatchingKeywordPredicate predicate;

public TagFindCommand(TagMatchingKeywordPredicate keywordPredicate) {
this.predicate = keywordPredicate;
}

@Override
public CommandResult execute() {
model.updateFilteredPersonList(predicate);
return new CommandResult(getMessageForPersonListShownSummary(model.getFilteredPersonList().size()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof TagFindCommand // instanceof handles nulls
&& this.predicate.equals(((TagFindCommand) other).predicate)); // state check
}
}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/TagRemoveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public class TagRemoveCommand extends UndoableCommand {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Remove tag to the person(s) identified "
+ "by the index number used in the last person listing.\n"
+ "Parameters: [TAG] "
+ "INDEX1 INDEX2... (must be a positive integer).\n"
+ "Parameters: INDEX1 INDEX2... (must be a positive integer) "
+ "[TAG] (TAG should not start with a number).\n"
+ "If no index is provided, remove the tag from all people. "
+ "Example: " + COMMAND_WORD + " [friends] "
+ "1 2 3 ";
+ "Example: " + COMMAND_WORD + " 1 2 3 "
+ "[friends]";

public static final String MESSAGE_REMOVE_TAG_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down Expand Up @@ -164,7 +164,7 @@ public void checkIndexInRange(ObservableList<ReadOnlyPerson> lastShownList) thro
* Creates and returns a {@code Person} with the details of {@code personToEdit}
* edited with {@code editPersonDescriptor}.
*/
private static Person createEditedPerson(ReadOnlyPerson personToEdit,
public Person createEditedPerson(ReadOnlyPerson personToEdit,
TagRemoveDescriptor tagRemoveDescriptor) {
assert personToEdit != null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.SortCommand;
import seedu.address.logic.commands.TagAddCommand;
import seedu.address.logic.commands.TagFindCommand;
import seedu.address.logic.commands.TagRemoveCommand;
import seedu.address.logic.commands.UndoCommand;

import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -70,6 +70,9 @@ public Command parseCommand(String userInput) throws ParseException {
case TagAddCommand.COMMAND_WORD:
return new TagAddCommandParser().parse(arguments);

case TagFindCommand.COMMAND_WORD:
return new TagFindCommandParser().parse(arguments);

case TagRemoveCommand.COMMAND_WORD:
return new TagRemoveCommandParser().parse(arguments);

Expand Down
38 changes: 19 additions & 19 deletions src/main/java/seedu/address/logic/parser/TagAddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ public class TagAddCommandParser implements Parser<TagAddCommand> {
*/
public TagAddCommand parse(String args) throws ParseException {
requireNonNull(args);
String newTag;
int lastIndex = 0;
String newTag = "";
int lastIndex = -1;
String[] argsArray;
if (args.isEmpty() || (argsArray = args.trim().split(" ")).length < 2) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagAddCommand.MESSAGE_USAGE));
}
newTag = argsArray[0];
for (int i = 1; i < argsArray.length; i++) {
if (!argsArray[i].matches("\\d?")) {
newTag = newTag.concat(" " + argsArray[i]);
lastIndex = i;
}
}
HashSet<String> tagSet = new HashSet<>();
tagSet.add(newTag);
ArrayList<Index> index = new ArrayList<>();

if (lastIndex == argsArray.length - 1) {
if (args.isEmpty() || (argsArray = args.trim().split(" ")).length < 2) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagAddCommand.MESSAGE_USAGE));
}

try {
for (int i = lastIndex + 1; i < argsArray.length; i++) {
index.add(ParserUtil.parseIndex(argsArray[i]));
for (int i = 0; i < argsArray.length; i++) {
if (argsArray[i].matches("\\d?")) {
index.add(ParserUtil.parseIndex(argsArray[i]));
lastIndex = i;
} else {
break;
}
}
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagAddCommand.MESSAGE_USAGE));
}

if (lastIndex == -1 || lastIndex == (argsArray.length - 1)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagAddCommand.MESSAGE_USAGE));
}
HashSet<String> tagSet = new HashSet<>();
for (int i = lastIndex + 1; i < argsArray.length; i++) {
newTag = newTag.concat(argsArray[i] + " ");
}
newTag = newTag.trim();
tagSet.add(newTag);
TagAddDescriptor tagAddDescriptor = new TagAddDescriptor();
try {
parseTagsForEdit(tagSet).ifPresent(tagAddDescriptor::setTags);
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/seedu/address/logic/parser/TagFindCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.logic.commands.TagFindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.TagMatchingKeywordPredicate;

/**
* Parses input arguments and creates a new TagFindCommand object
*/
public class TagFindCommandParser implements Parser<TagFindCommand> {
/**
* Parses the given {@code String} of arguments in the context of the TagFindCommand
* and returns an TagFindCommand object for execution.
* @throws ParseException if the user does not provide any input
*/
public TagFindCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
//Throw an error if there is no argument followed by the command word
if (trimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagFindCommand.MESSAGE_USAGE));
}
TagMatchingKeywordPredicate predicate = new TagMatchingKeywordPredicate(trimmedArgs);
return new TagFindCommand(predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.TagAddCommand;
import seedu.address.logic.commands.TagRemoveCommand.TagRemoveDescriptor;
import seedu.address.logic.commands.TagRemoveCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -26,38 +25,39 @@ public class TagRemoveCommandParser implements Parser<TagRemoveCommand> {
/**
* Parses the given {@code String} of arguments in the context of the TagRemoveCommand
* and returns an TagRemoveCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public TagRemoveCommand parse(String args) throws ParseException {
requireNonNull(args);
String newTag;
int lastIndex = 0;
String newTag = "";
int lastIndex = -1;
ArrayList<Index> index = new ArrayList<>();
String[] argsArray;
if (args.trim().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagRemoveCommand.MESSAGE_USAGE));
}
argsArray = args.trim().split(" ");
newTag = argsArray[0];
for (int i = 1; i < argsArray.length; i++) {
if (!argsArray[i].matches("\\d?")) {
newTag = newTag.concat(" " + argsArray[i]);
lastIndex = i;
}
}
HashSet<String> tagSet = new HashSet<>();
tagSet.add(newTag);
ArrayList<Index> index = new ArrayList<>();

if (lastIndex != argsArray.length) {
try {
for (int i = lastIndex + 1; i < argsArray.length; i++) {
try {
for (int i = 0; i < argsArray.length; i++) {
if (argsArray[i].matches("\\d?")) {
index.add(ParserUtil.parseIndex(argsArray[i]));
lastIndex = i;
} else {
break;
}
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagAddCommand.MESSAGE_USAGE));
}
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagRemoveCommand.MESSAGE_USAGE));
}

if (lastIndex == argsArray.length - 1) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagRemoveCommand.MESSAGE_USAGE));
}
for (int i = lastIndex + 1; i < argsArray.length; i++) {
newTag = newTag.concat(" " + argsArray[i]);
}
HashSet<String> tagSet = new HashSet<>();
tagSet.add(newTag);
TagRemoveDescriptor tagRemoveDescriptor = new TagRemoveDescriptor();
try {
parseTagsForEdit(tagSet).ifPresent(tagRemoveDescriptor::setTags);
Expand All @@ -68,7 +68,6 @@ public TagRemoveCommand parse(String args) throws ParseException {
if (!tagRemoveDescriptor.isAnyFieldEdited()) {
throw new ParseException(TagRemoveCommand.MESSAGE_NOT_EDITED);
}

return new TagRemoveCommand(index, tagRemoveDescriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public TagMatchingKeywordPredicate(String keyword) {
public boolean test(ReadOnlyPerson person) {
Set<Tag> tagList = person.getTags();
for (Tag tag : tagList) {
if (tag.tagName.equalsIgnoreCase(keyword)) {
String current = tag.tagName;
if (current.equalsIgnoreCase(keyword)) {
return true;
} else if (keyword.trim().isEmpty()) {
return false;
} else if (current.toLowerCase().contains(keyword.toLowerCase())
|| keyword.toLowerCase().contains(current.toLowerCase())) {
return true;
}
}
Expand All @@ -32,4 +38,8 @@ public boolean equals(Object other) {
|| (other instanceof TagMatchingKeywordPredicate // instanceof handles nulls
&& this.keyword.equalsIgnoreCase(((TagMatchingKeywordPredicate) other).keyword)); // state check
}

public String getKeyword() {
return keyword;
}
}
Loading

0 comments on commit 0f032f8

Please sign in to comment.