forked from nus-cs2103-AY2021S1/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' of https://github.com/AY2021S1-CS2103T-F12-1/tp …
…into branch-improve-task-list-view
- Loading branch information
Showing
18 changed files
with
356 additions
and
52 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
57 changes: 57 additions & 0 deletions
57
src/main/java/seedu/address/logic/commands/ShowCommand.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,57 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_TAG_INPUT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG_NAME; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.tag.TagNameEqualsKeywordPredicate; | ||
|
||
/** | ||
* Shows a Tag's file path identified using it's tag name. | ||
*/ | ||
public class ShowCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "show"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows a tag's file address. " | ||
+ "Parameters: " | ||
+ PREFIX_TAG_NAME + "TAG_NAME " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_TAG_NAME + "cs2103 "; | ||
|
||
public static final String MESSAGE_SUCCESS = "%s's file path: %s"; | ||
|
||
private final TagNameEqualsKeywordPredicate predicate; | ||
|
||
/** | ||
* Creates an ShowCommand to show the specified {@code Tag}'s file path | ||
*/ | ||
public ShowCommand(TagNameEqualsKeywordPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Tag> tags = model.findFilteredTagList(predicate); | ||
|
||
if (tags.isEmpty()) { | ||
throw new CommandException(MESSAGE_INVALID_TAG_INPUT); | ||
} | ||
|
||
Tag tag = tags.get(0); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, tag.getTagName(), tag.getFileAddress())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ShowCommand // instanceof handles nulls | ||
&& predicate.equals(((ShowCommand) other).predicate)); | ||
} | ||
} |
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/parser/ShowCommandParser.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.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG_NAME; | ||
|
||
import seedu.address.logic.commands.ShowCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.TagName; | ||
import seedu.address.model.tag.TagNameEqualsKeywordPredicate; | ||
|
||
/** | ||
* Parses input arguments and creates a new ShowCommand object | ||
*/ | ||
public class ShowCommandParser implements Parser<ShowCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ShowCommand | ||
* and returns an ShowCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
@Override | ||
public ShowCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_TAG_NAME); | ||
|
||
if (!argMultimap.getValue(PREFIX_TAG_NAME).isPresent()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ShowCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
TagName tagName = new TagName(argMultimap.getValue(PREFIX_TAG_NAME).orElse("")); | ||
|
||
return new ShowCommand(new TagNameEqualsKeywordPredicate(tagName)); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/seedu/address/model/tag/TagNameEqualsKeywordPredicate.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,26 @@ | ||
package seedu.address.model.tag; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Tests that a {@code Tag}'s {@code TagName} equals to the tag name given. | ||
*/ | ||
public class TagNameEqualsKeywordPredicate implements Predicate<Tag> { | ||
private final TagName tagNameToFind; | ||
|
||
public TagNameEqualsKeywordPredicate(TagName tagNameToFind) { | ||
this.tagNameToFind = tagNameToFind; | ||
} | ||
|
||
@Override | ||
public boolean test(Tag tag) { | ||
return tagNameToFind.equals(tag.getTagName()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof TagNameEqualsKeywordPredicate // instanceof handles nulls | ||
&& tagNameToFind.equals(((TagNameEqualsKeywordPredicate) other).tagNameToFind)); // state check | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
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
74 changes: 74 additions & 0 deletions
74
src/test/java/seedu/address/logic/commands/ShowCommandTest.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,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_TAG; | ||
import static seedu.address.testutil.TypicalTags.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.tag.TagName; | ||
import seedu.address.model.tag.TagNameEqualsKeywordPredicate; | ||
|
||
public class ShowCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
TagName firstPredicateTagName = new TagName("first"); | ||
TagName secondPredicateTagName = new TagName("second"); | ||
|
||
TagNameEqualsKeywordPredicate firstPredicate = new TagNameEqualsKeywordPredicate( | ||
firstPredicateTagName); | ||
TagNameEqualsKeywordPredicate secondPredicate = new TagNameEqualsKeywordPredicate( | ||
secondPredicateTagName); | ||
|
||
ShowCommand showFirstCommand = new ShowCommand(firstPredicate); | ||
ShowCommand showSecondCommand = new ShowCommand(secondPredicate); | ||
|
||
// same object -> returns true | ||
assertTrue(showFirstCommand.equals(showFirstCommand)); | ||
|
||
// same values -> returns true | ||
ShowCommand showFirstCommandCopy = new ShowCommand(firstPredicate); | ||
assertTrue(showFirstCommand.equals(showFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(showFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(showFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(showFirstCommand.equals(showSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void execute_invalidTagName_throwsCommandException() { | ||
TagNameEqualsKeywordPredicate predicate = new TagNameEqualsKeywordPredicate(new TagName("Invalid Tag Name")); | ||
ShowCommand showCommand = new ShowCommand(predicate); | ||
|
||
assertCommandFailure(showCommand, model, Messages.MESSAGE_INVALID_TAG_INPUT); | ||
} | ||
|
||
@Test | ||
public void execute_validTagName_throwsCommandException() { | ||
Tag tagToBeShown = model.getFilteredTagList().get(INDEX_FIRST_TAG.getZeroBased()); | ||
TagNameEqualsKeywordPredicate predicate = new TagNameEqualsKeywordPredicate(tagToBeShown.getTagName()); | ||
ShowCommand showCommand = new ShowCommand(predicate); | ||
|
||
String expectedMessage = String.format(showCommand.MESSAGE_SUCCESS, | ||
tagToBeShown.getTagName(), tagToBeShown.getFileAddress()); | ||
|
||
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); | ||
|
||
assertCommandSuccess(showCommand, model, expectedMessage, expectedModel); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/test/java/seedu/address/logic/parser/ShowCommandParserTest.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,32 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.ShowCommand; | ||
import seedu.address.model.tag.TagName; | ||
import seedu.address.model.tag.TagNameEqualsKeywordPredicate; | ||
|
||
public class ShowCommandParserTest { | ||
private ShowCommandParser parser = new ShowCommandParser(); | ||
|
||
@Test | ||
public void parse_invalidArgs_throwsParseException() { | ||
// No prefix | ||
assertParseFailure(parser, "noprefix", | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ShowCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
@Test | ||
public void parse_validArgs_throwsParseException() { | ||
ShowCommand expectedFindCommand = | ||
new ShowCommand(new TagNameEqualsKeywordPredicate(new TagName(VALID_NAME_AMY))); | ||
|
||
assertParseSuccess(parser, NAME_DESC_AMY, expectedFindCommand); | ||
} | ||
} |
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.