Skip to content

Commit f8a20e7

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#86 from luo-git/Branch-TagCommand
Modify AddCommand AddCommandParser to TagCommand and TagCommandParser
2 parents ade0a6b + 45acc72 commit f8a20e7

File tree

14 files changed

+91
-85
lines changed

14 files changed

+91
-85
lines changed

src/main/java/seedu/address/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
*/
2121
public class Main {
2222
public static void main(String[] args) {
23-
Application.launch(MainApp.class, args);
23+
Application.launch(NewMainApp.class, args);
2424
}
2525
}

src/main/java/seedu/address/logic/commands/AddCommand.java renamed to src/main/java/seedu/address/logic/commands/TagCommand.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,54 @@
1111
/**
1212
* Adds a person to the address book.
1313
*/
14-
public class AddCommand extends Command {
14+
public class TagCommand extends Command {
1515

16-
public static final String COMMAND_WORD = "add";
16+
public static final String COMMAND_WORD = "tag";
1717

18-
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a tag to the hello file. "
18+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a tag to the HelleFile's address book. "
1919
+ "Parameters: "
20-
+ PREFIX_TAG_NAME + "NAME "
21-
+ PREFIX_FILE_ADDRESS + "ADDRESS "
20+
+ PREFIX_TAG_NAME + "TAG_NAME "
21+
+ PREFIX_FILE_ADDRESS + "FILE_ADDRESS "
2222
+ "Example: " + COMMAND_WORD + " "
23-
+ PREFIX_TAG_NAME + "John Doe "
24-
+ PREFIX_FILE_ADDRESS + "311, Clementi Ave 2, #02-25 ";
23+
+ PREFIX_TAG_NAME + "cs2103 "
24+
+ PREFIX_FILE_ADDRESS + "F:\\OneDrive\\CS2013T ";
2525

2626
public static final String MESSAGE_SUCCESS = "New tag added: %1$s";
27-
public static final String MESSAGE_DUPLICATE_TAG = "Tag duplicated!";
27+
public static final String MESSAGE_DUPLICATE_TAG = "Duplicate tag name!";
2828

29-
private final Tag toAdd;
29+
private final Tag toTag;
3030

3131
/**
3232
* Creates an AddCommand to add the specified {@code Tag}
3333
*/
34-
public AddCommand(Tag tag) {
34+
public TagCommand(Tag tag) {
3535
requireNonNull(tag);
36-
toAdd = tag;
36+
toTag = tag;
3737
}
3838

39+
/**
40+
* Executes the command and add the tag to model.
41+
*
42+
* @param model {@code Model} which the command should operate on.
43+
* @return A Command result of executing tag command.
44+
* @throws CommandException
45+
*/
3946
@Override
4047
public CommandResult execute(Model model) throws CommandException {
4148
requireNonNull(model);
4249

43-
if (model.hasTag(toAdd)) {
50+
if (model.hasTag(toTag)) {
4451
throw new CommandException(MESSAGE_DUPLICATE_TAG);
4552
}
4653

47-
model.addTag(toAdd);
48-
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
54+
model.addTag(toTag);
55+
return new CommandResult(String.format(MESSAGE_SUCCESS, toTag));
4956
}
5057

5158
@Override
5259
public boolean equals(Object other) {
5360
return other == this // short circuit if same object
54-
|| (other instanceof AddCommand // instanceof handles nulls
55-
&& toAdd.equals(((AddCommand) other).toAdd));
61+
|| (other instanceof TagCommand // instanceof handles nulls
62+
&& toTag.equals(((TagCommand) other).toTag));
5663
}
5764
}

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

9-
import seedu.address.logic.commands.AddCommand;
109
import seedu.address.logic.commands.ClearCommand;
1110
import seedu.address.logic.commands.Command;
1211
import seedu.address.logic.commands.ExitCommand;
1312
import seedu.address.logic.commands.FindCommand;
1413
import seedu.address.logic.commands.HelpCommand;
1514
import seedu.address.logic.commands.ListCommand;
15+
import seedu.address.logic.commands.TagCommand;
1616
import seedu.address.logic.commands.UntagCommand;
1717
import seedu.address.logic.parser.exceptions.ParseException;
1818

@@ -43,8 +43,8 @@ public Command parseCommand(String userInput) throws ParseException {
4343
final String arguments = matcher.group("arguments");
4444
switch (commandWord) {
4545

46-
case AddCommand.COMMAND_WORD:
47-
return new AddCommandParser().parse(arguments);
46+
case TagCommand.COMMAND_WORD:
47+
return new TagCommandParser().parse(arguments);
4848

4949
case UntagCommand.COMMAND_WORD:
5050
return new UntagCommandParser().parse(arguments);

src/main/java/seedu/address/logic/parser/Prefix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* A prefix that marks the beginning of an argument in an arguments string.
5-
* E.g. 't/' in 'add James t/ friend'.
5+
* E.g. 't/' in 'tag f/C:/abc.txt t/myFile'.
66
*/
77
public class Prefix {
88
private final String prefix;

src/main/java/seedu/address/logic/parser/AddCommandParser.java renamed to src/main/java/seedu/address/logic/parser/TagCommandParser.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package seedu.address.logic.parser;
22

33
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4-
import static seedu.address.logic.parser.CliSyntax.PREFIX_COMMAND;
54
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILE_ADDRESS;
6-
import static seedu.address.logic.parser.CliSyntax.PREFIX_OLD_TAG_NAME;
75
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG_NAME;
86

97
import java.util.stream.Stream;
108

11-
import seedu.address.logic.commands.AddCommand;
9+
import seedu.address.logic.commands.TagCommand;
1210
import seedu.address.logic.parser.exceptions.ParseException;
1311
import seedu.address.model.tag.FileAddress;
1412
import seedu.address.model.tag.Tag;
@@ -17,32 +15,28 @@
1715
/**
1816
* Parses input arguments and creates a new AddCommand object
1917
*/
20-
public class AddCommandParser implements Parser<AddCommand> {
18+
public class TagCommandParser implements Parser<TagCommand> {
2119

2220
/**
23-
* Parses the given {@code String} of arguments in the context of the AddCommand
24-
* and returns an AddCommand object for execution.
21+
* Parses the given {@code String} of arguments in the context of the TagCommand
22+
* and returns an TagCommand object for execution.
2523
* @throws ParseException if the user input does not conform the expected format
2624
*/
27-
public AddCommand parse(String args) throws ParseException {
25+
public TagCommand parse(String args) throws ParseException {
2826
ArgumentMultimap argMultimap =
29-
ArgumentTokenizer.tokenize(args, PREFIX_TAG_NAME, PREFIX_FILE_ADDRESS,
30-
PREFIX_OLD_TAG_NAME, PREFIX_COMMAND);
27+
ArgumentTokenizer.tokenize(args, PREFIX_TAG_NAME, PREFIX_FILE_ADDRESS);
3128

3229
if (!arePrefixesPresent(argMultimap, PREFIX_TAG_NAME, PREFIX_FILE_ADDRESS)
3330
|| !argMultimap.getPreamble().isEmpty()) {
34-
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
31+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagCommand.MESSAGE_USAGE));
3532
}
3633

37-
38-
3934
TagName tagName = ParserUtil.parseTagName(argMultimap.getValue(PREFIX_TAG_NAME).get());
4035
FileAddress fileAddress = ParserUtil.parseFileAddress(argMultimap.getValue(PREFIX_FILE_ADDRESS).get());
4136

4237
Tag tag = new Tag(tagName, fileAddress);
4338

44-
45-
return new AddCommand(tag);
39+
return new TagCommand(tag);
4640
}
4741

4842
/**

src/main/java/seedu/address/model/tag/FileAddress.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
public class FileAddress {
1111

12+
// TODO change message to be more understandable
1213
public static final String MESSAGE_CONSTRAINTS = "File addresses can take any values, and it should not be blank";
1314

1415
/*

src/test/java/seedu/address/logic/LogicManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import org.junit.jupiter.api.Test;
1616
import org.junit.jupiter.api.io.TempDir;
1717

18-
import seedu.address.logic.commands.AddCommand;
1918
import seedu.address.logic.commands.CommandResult;
2019
import seedu.address.logic.commands.ListCommand;
20+
import seedu.address.logic.commands.TagCommand;
2121
import seedu.address.logic.commands.exceptions.CommandException;
2222
import seedu.address.logic.parser.exceptions.ParseException;
2323
import seedu.address.model.Model;
@@ -76,14 +76,14 @@ public void execute_storageThrowsIoException_throwsCommandException() {
7676
StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage);
7777
logic = new LogicManager(model, storage);
7878

79-
// Execute add command
80-
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY
79+
// Execute tag command
80+
String tagCommand = TagCommand.COMMAND_WORD + NAME_DESC_AMY
8181
+ FILE_ADDRESS_DESC_AMY;
8282
Tag expectedTag = new TagBuilder(AMY).build();
8383
ModelManager expectedModel = new ModelManager();
8484
expectedModel.addTag(expectedTag);
8585
String expectedMessage = LogicManager.FILE_OPS_ERROR_MESSAGE + DUMMY_IO_EXCEPTION;
86-
assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel);
86+
assertCommandFailure(tagCommand, CommandException.class, expectedMessage, expectedModel);
8787
}
8888

8989
@Test

src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java renamed to src/test/java/seedu/address/logic/commands/TagCommandIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Contains integration tests (interaction with the Model) for {@code AddCommand}.
1818
*/
19-
public class AddCommandIntegrationTest {
19+
public class TagCommandIntegrationTest {
2020

2121
private Model model;
2222

@@ -27,19 +27,19 @@ public void setUp() {
2727

2828
@Test
2929
public void execute_newTag_success() {
30-
Tag validPerson = new TagBuilder().build();
30+
Tag validTag = new TagBuilder().build();
3131

3232
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
33-
expectedModel.addTag(validPerson);
33+
expectedModel.addTag(validTag);
3434

35-
assertCommandSuccess(new AddCommand(validPerson), model,
36-
String.format(AddCommand.MESSAGE_SUCCESS, validPerson), expectedModel);
35+
assertCommandSuccess(new TagCommand(validTag), model,
36+
String.format(TagCommand.MESSAGE_SUCCESS, validTag), expectedModel);
3737
}
3838

3939
@Test
4040
public void execute_duplicateTag_throwsCommandException() {
41-
Tag personInList = model.getAddressBook().getTagList().get(0);
42-
assertCommandFailure(new AddCommand(personInList), model, AddCommand.MESSAGE_DUPLICATE_TAG);
41+
Tag tagInList = model.getAddressBook().getTagList().get(0);
42+
assertCommandFailure(new TagCommand(tagInList), model, TagCommand.MESSAGE_DUPLICATE_TAG);
4343
}
4444

4545
}

src/test/java/seedu/address/logic/commands/AddCommandTest.java renamed to src/test/java/seedu/address/logic/commands/TagCommandTest.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Arrays;
1212
import java.util.function.Predicate;
1313

14+
import org.junit.jupiter.api.Disabled;
1415
import org.junit.jupiter.api.Test;
1516

1617
import javafx.collections.ObservableList;
@@ -23,55 +24,57 @@
2324
import seedu.address.model.tag.Tag;
2425
import seedu.address.testutil.TagBuilder;
2526

26-
public class AddCommandTest {
27+
public class TagCommandTest {
2728

2829
@Test
2930
public void constructor_nullTag_throwsNullPointerException() {
30-
assertThrows(NullPointerException.class, () -> new AddCommand(null));
31+
assertThrows(NullPointerException.class, () -> new TagCommand(null));
3132
}
3233

3334
@Test
34-
public void execute_tagAcceptedByModel_addSuccessful() throws Exception {
35+
@Disabled
36+
// This test is using the original idea of tagging person.
37+
public void execute_tagAcceptedByModel_tagSuccessful() throws Exception {
3538
ModelStubAcceptingTagAdded modelStub = new ModelStubAcceptingTagAdded();
36-
Tag validPerson = new TagBuilder().build();
39+
Tag validTag = new TagBuilder().build();
3740

38-
CommandResult commandResult = new AddCommand(validPerson).execute(modelStub);
41+
CommandResult commandResult = new TagCommand(validTag).execute(modelStub);
3942

40-
assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, validPerson), commandResult.getFeedbackToUser());
41-
assertEquals(Arrays.asList(validPerson), modelStub.tagsAdded);
43+
assertEquals(String.format(TagCommand.MESSAGE_SUCCESS, validTag), commandResult.getFeedbackToUser());
44+
assertEquals(Arrays.asList(validTag), modelStub.tagsAdded);
4245
}
4346

4447
@Test
45-
public void execute_duplicateTag_throwsCommandException() {
46-
Tag validPerson = new TagBuilder().build();
47-
AddCommand addCommand = new AddCommand(validPerson);
48-
ModelStub modelStub = new ModelStubWithTag(validPerson);
48+
public void execute_duplicateTagName_throwsCommandException() {
49+
Tag validTag = new TagBuilder().build();
50+
TagCommand tagCommand = new TagCommand(validTag);
51+
ModelStub modelStub = new ModelStubWithTag(validTag);
4952

50-
assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_TAG, () -> addCommand.execute(modelStub));
53+
assertThrows(CommandException.class, TagCommand.MESSAGE_DUPLICATE_TAG, () -> tagCommand.execute(modelStub));
5154
}
5255

5356
@Test
5457
public void equals() {
55-
Tag alice = new TagBuilder().withTagName("Alice").build();
56-
Tag bob = new TagBuilder().withTagName("Bob").build();
57-
AddCommand addAliceCommand = new AddCommand(alice);
58-
AddCommand addBobCommand = new AddCommand(bob);
58+
Tag t1 = new TagBuilder().withTagName("cs2101").build();
59+
Tag t2 = new TagBuilder().withTagName("cs2103").build();
60+
TagCommand tagT1Command = new TagCommand(t1);
61+
TagCommand tagT2Command = new TagCommand(t2);
5962

6063
// same object -> returns true
61-
assertTrue(addAliceCommand.equals(addAliceCommand));
64+
assertTrue(tagT1Command.equals(tagT1Command));
6265

6366
// same values -> returns true
64-
AddCommand addAliceCommandCopy = new AddCommand(alice);
65-
assertTrue(addAliceCommand.equals(addAliceCommandCopy));
67+
TagCommand tagT1CommandCopy = new TagCommand(t1);
68+
assertTrue(tagT1Command.equals(tagT1CommandCopy));
6669

6770
// different types -> returns false
68-
assertFalse(addAliceCommand.equals(1));
71+
assertFalse(tagT1Command.equals(1));
6972

7073
// null -> returns false
71-
assertFalse(addAliceCommand.equals(null));
74+
assertFalse(tagT1Command.equals(null));
7275

7376
// different person -> returns false
74-
assertFalse(addAliceCommand.equals(addBobCommand));
77+
assertFalse(tagT1Command.equals(tagT2Command));
7578
}
7679

7780
/**
@@ -150,7 +153,7 @@ public void updateFilteredTagList(Predicate<Tag> predicate) {
150153
}
151154

152155
/**
153-
* A Model stub that contains a single person.
156+
* A Model stub that contains a single tag.
154157
*/
155158
private class ModelStubWithTag extends ModelStub {
156159
private final Tag tag;
@@ -168,8 +171,9 @@ public boolean hasTag(Tag tag) {
168171
}
169172

170173
/**
171-
* A Model stub that always accept the person being added.
174+
* A Model stub that always accept the tag being added.
172175
*/
176+
@Deprecated
173177
private class ModelStubAcceptingTagAdded extends ModelStub {
174178
final ArrayList<Tag> tagsAdded = new ArrayList<>();
175179

src/test/java/seedu/address/logic/parser/AddressBookParserTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
import org.junit.jupiter.api.Test;
1515

16-
import seedu.address.logic.commands.AddCommand;
1716
import seedu.address.logic.commands.ClearCommand;
1817
import seedu.address.logic.commands.ExitCommand;
1918
import seedu.address.logic.commands.FindCommand;
2019
import seedu.address.logic.commands.HelpCommand;
2120
import seedu.address.logic.commands.ListCommand;
21+
import seedu.address.logic.commands.TagCommand;
2222
import seedu.address.logic.commands.UntagCommand;
2323
import seedu.address.logic.parser.exceptions.ParseException;
2424
import seedu.address.model.tag.Tag;
@@ -33,8 +33,8 @@ public class AddressBookParserTest {
3333
@Test
3434
public void parseCommand_add() throws Exception {
3535
Tag person = new TagBuilder().build();
36-
AddCommand command = (AddCommand) parser.parseCommand(TagUtil.getAddCommand(person));
37-
assertEquals(new AddCommand(person), command);
36+
TagCommand command = (TagCommand) parser.parseCommand(TagUtil.getTagCommand(person));
37+
assertEquals(new TagCommand(person), command);
3838
}
3939

4040
@Test

0 commit comments

Comments
 (0)