Skip to content

Commit 3c43ddf

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#80 from GeNiaaz/refactor-project-tags
Refactor project tags
2 parents fb37946 + 3829c17 commit 3c43ddf

35 files changed

+497
-431
lines changed

src/main/java/seedu/address/logic/commands/AddCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_DESCRIPTION;
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME;
8-
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
8+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TAG;
99
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK;
1010

1111
import seedu.address.logic.commands.exceptions.CommandException;
@@ -25,15 +25,15 @@ public class AddCommand extends Command {
2525
+ PREFIX_DEADLINE + "DEADLINE "
2626
+ PREFIX_EMAIL + "EMAIL "
2727
+ PREFIX_PROJECT_DESCRIPTION + "PROJECT DESCRIPTION "
28-
+ "[" + PREFIX_TAG + "TAG]...\n"
28+
+ "[" + PREFIX_PROJECT_TAG + "TAG]...\n"
2929
+ "[" + PREFIX_TASK + "TASK]...\n"
3030
+ "Example: " + COMMAND_WORD + " "
3131
+ PREFIX_PROJECT_NAME + "John Doe "
3232
+ PREFIX_DEADLINE + "29-02-2020 00:00:00"
3333
+ PREFIX_EMAIL + "[email protected] "
3434
+ PREFIX_PROJECT_DESCRIPTION + "311, Clementi Ave 2, #02-25 "
35-
+ PREFIX_TAG + "friends "
36-
+ PREFIX_TAG + "owesMoney"
35+
+ PREFIX_PROJECT_TAG + "friends "
36+
+ PREFIX_PROJECT_TAG + "owesMoney"
3737
+ PREFIX_TASK + "Write User Guide";
3838

3939
public static final String MESSAGE_SUCCESS = "New project added: %1$s";

src/main/java/seedu/address/logic/commands/EditCommand.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_DESCRIPTION;
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME;
8-
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
8+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TAG;
99
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK;
1010
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PROJECTS;
1111

@@ -26,7 +26,7 @@
2626
import seedu.address.model.project.Project;
2727
import seedu.address.model.project.ProjectDescription;
2828
import seedu.address.model.project.ProjectName;
29-
import seedu.address.model.tag.Tag;
29+
import seedu.address.model.tag.ProjectTag;
3030
import seedu.address.model.task.Task;
3131
/**
3232
* Edits the details of an existing project in the main catalogue.
@@ -43,7 +43,7 @@ public class EditCommand extends Command {
4343
+ "[" + PREFIX_DEADLINE + "DEADLINE] "
4444
+ "[" + PREFIX_EMAIL + "EMAIL] "
4545
+ "[" + PREFIX_PROJECT_DESCRIPTION + "PROJECTDESCRIPTION] "
46-
+ "[" + PREFIX_TAG + "TAG]...\n"
46+
+ "[" + PREFIX_PROJECT_TAG + "PROJECT TAG]...\n"
4747
+ "[" + PREFIX_TASK + "TASK]...\n"
4848
+ "Example: " + COMMAND_WORD + " 1 "
4949
+ PREFIX_DEADLINE + "29-02-2020 00:00:00 "
@@ -101,11 +101,12 @@ private static Project createEditedProject(Project projectToEdit, EditProjectDes
101101
Email updatedEmail = editProjectDescriptor.getEmail().orElse(projectToEdit.getEmail());
102102
ProjectDescription updatedProjectDescription = editProjectDescriptor.getProjectDescription()
103103
.orElse(projectToEdit.getProjectDescription());
104-
Set<Tag> updatedTags = editProjectDescriptor.getTags().orElse(projectToEdit.getTags());
104+
Set<ProjectTag> updatedProjectTags = editProjectDescriptor.getProjectTags().orElse(
105+
projectToEdit.getProjectTags());
105106
Set<Task> updatedTasks = editProjectDescriptor.getTasks().orElse(projectToEdit.getTasks());
106107

107108
return new Project(updatedProjectName, updatedDeadline, updatedEmail, updatedProjectDescription,
108-
updatedTags, new HashMap<>(), updatedTasks);
109+
updatedProjectTags, new HashMap<>(), updatedTasks);
109110
}
110111

111112
@Override
@@ -135,29 +136,29 @@ public static class EditProjectDescriptor {
135136
private Deadline deadline;
136137
private Email email;
137138
private ProjectDescription projectDescription;
138-
private Set<Tag> tags;
139+
private Set<ProjectTag> projectTags;
139140
private Set<Task> tasks;
140141

141142
public EditProjectDescriptor() {}
142143

143144
/**
144145
* Copy constructor.
145-
* A defensive copy of {@code tags} is used internally.
146+
* A defensive copy of {@code projectTags} is used internally.
146147
*/
147148
public EditProjectDescriptor(EditProjectDescriptor toCopy) {
148149
setProjectName(toCopy.projectName);
149150
setDeadline(toCopy.deadline);
150151
setEmail(toCopy.email);
151152
setProjectDescription(toCopy.projectDescription);
152-
setTags(toCopy.tags);
153+
setTags(toCopy.projectTags);
153154
setTasks(toCopy.tasks);
154155
}
155156

156157
/**
157158
* Returns true if at least one field is edited.
158159
*/
159160
public boolean isAnyFieldEdited() {
160-
return CollectionUtil.isAnyNonNull(projectName, deadline, email, projectDescription, tags, tasks);
161+
return CollectionUtil.isAnyNonNull(projectName, deadline, email, projectDescription, projectTags, tasks);
161162
}
162163

163164
public void setProjectName(ProjectName projectName) {
@@ -193,20 +194,20 @@ public Optional<ProjectDescription> getProjectDescription() {
193194
}
194195

195196
/**
196-
* Sets {@code tags} to this object's {@code tags}.
197-
* A defensive copy of {@code tags} is used internally.
197+
* Sets {@code projectTags} to this object's {@code projectTags}.
198+
* A defensive copy of {@code projectTags} is used internally.
198199
*/
199-
public void setTags(Set<Tag> tags) {
200-
this.tags = (tags != null) ? new HashSet<>(tags) : null;
200+
public void setTags(Set<ProjectTag> projectTags) {
201+
this.projectTags = (projectTags != null) ? new HashSet<>(projectTags) : null;
201202
}
202203

203204
/**
204-
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
205+
* Returns an unmodifiable project tag set, which throws {@code UnsupportedOperationException}
205206
* if modification is attempted.
206-
* Returns {@code Optional#empty()} if {@code tags} is null.
207+
* Returns {@code Optional#empty()} if {@code projectTags} is null.
207208
*/
208-
public Optional<Set<Tag>> getTags() {
209-
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
209+
public Optional<Set<ProjectTag>> getProjectTags() {
210+
return (projectTags != null) ? Optional.of(Collections.unmodifiableSet(projectTags)) : Optional.empty();
210211
}
211212

212213
/**
@@ -245,7 +246,7 @@ public boolean equals(Object other) {
245246
&& getDeadline().equals(e.getDeadline())
246247
&& getEmail().equals(e.getEmail())
247248
&& getProjectDescription().equals(e.getProjectDescription())
248-
&& getTags().equals(e.getTags())
249+
&& getProjectTags().equals(e.getProjectTags())
249250
&& getTasks().equals(e.getTasks());
250251
}
251252
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_DESCRIPTION;
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME;
8-
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
8+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TAG;
99
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK;
1010

1111
import java.util.HashMap;
@@ -19,7 +19,7 @@
1919
import seedu.address.model.project.Project;
2020
import seedu.address.model.project.ProjectDescription;
2121
import seedu.address.model.project.ProjectName;
22-
import seedu.address.model.tag.Tag;
22+
import seedu.address.model.tag.ProjectTag;
2323
import seedu.address.model.task.Task;
2424

2525
/**
@@ -35,7 +35,7 @@ public class AddCommandParser implements Parser<AddCommand> {
3535
public AddCommand parse(String args) throws ParseException {
3636
ArgumentMultimap argMultimap =
3737
ArgumentTokenizer.tokenize(args, PREFIX_PROJECT_NAME, PREFIX_DEADLINE, PREFIX_EMAIL,
38-
PREFIX_PROJECT_DESCRIPTION, PREFIX_TAG, PREFIX_TASK);
38+
PREFIX_PROJECT_DESCRIPTION, PREFIX_PROJECT_TAG, PREFIX_TASK);
3939

4040
if (!arePrefixesPresent(argMultimap, PREFIX_PROJECT_NAME,
4141
PREFIX_PROJECT_DESCRIPTION, PREFIX_DEADLINE, PREFIX_EMAIL)
@@ -48,10 +48,10 @@ public AddCommand parse(String args) throws ParseException {
4848
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
4949
ProjectDescription projectDescription = ParserUtil.projectDescription(argMultimap.getValue(
5050
PREFIX_PROJECT_DESCRIPTION).get());
51-
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
51+
Set<ProjectTag> projectTagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_PROJECT_TAG));
5252
Set<Task> taskList = ParserUtil.parseTasks(argMultimap.getAllValues(PREFIX_TASK));
5353

54-
Project project = new Project(projectName, deadline, email, projectDescription, tagList,
54+
Project project = new Project(projectName, deadline, email, projectDescription, projectTagList,
5555
new HashMap<>(), taskList);
5656

5757
return new AddCommand(project);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CliSyntax {
1010
public static final Prefix PREFIX_DEADLINE = new Prefix("dl/");
1111
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
1212
public static final Prefix PREFIX_PROJECT_DESCRIPTION = new Prefix("d/");
13-
public static final Prefix PREFIX_TAG = new Prefix("tg/");
13+
public static final Prefix PREFIX_PROJECT_TAG = new Prefix("tg/");
1414
public static final Prefix PREFIX_TASK = new Prefix("tk/");
1515

1616
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_DESCRIPTION;
88
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME;
9-
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
9+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TAG;
1010
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK;
1111

1212
import java.util.Collection;
@@ -18,7 +18,7 @@
1818
import seedu.address.logic.commands.EditCommand;
1919
import seedu.address.logic.commands.EditCommand.EditProjectDescriptor;
2020
import seedu.address.logic.parser.exceptions.ParseException;
21-
import seedu.address.model.tag.Tag;
21+
import seedu.address.model.tag.ProjectTag;
2222
import seedu.address.model.task.Task;
2323

2424
/**
@@ -35,7 +35,7 @@ public EditCommand parse(String args) throws ParseException {
3535
requireNonNull(args);
3636
ArgumentMultimap argMultimap =
3737
ArgumentTokenizer.tokenize(args, PREFIX_PROJECT_NAME, PREFIX_DEADLINE, PREFIX_EMAIL,
38-
PREFIX_PROJECT_DESCRIPTION, PREFIX_TAG, PREFIX_TASK);
38+
PREFIX_PROJECT_DESCRIPTION, PREFIX_PROJECT_TAG, PREFIX_TASK);
3939

4040
Index index;
4141

@@ -60,7 +60,7 @@ public EditCommand parse(String args) throws ParseException {
6060
editProjectDescriptor.setProjectDescription(ParserUtil.projectDescription(argMultimap
6161
.getValue(PREFIX_PROJECT_DESCRIPTION).get()));
6262
}
63-
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editProjectDescriptor::setTags);
63+
parseTagsForEdit(argMultimap.getAllValues(PREFIX_PROJECT_TAG)).ifPresent(editProjectDescriptor::setTags);
6464
parseTasksForEdit(argMultimap.getAllValues(PREFIX_TASK)).ifPresent(editProjectDescriptor::setTasks);
6565

6666
if (!editProjectDescriptor.isAnyFieldEdited()) {
@@ -71,11 +71,11 @@ public EditCommand parse(String args) throws ParseException {
7171
}
7272

7373
/**
74-
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if {@code tags} is non-empty.
74+
* Parses {@code Collection<String> tags} into a {@code Set<ProjectTag>} if {@code tags} is non-empty.
7575
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
76-
* {@code Set<Tag>} containing zero tags.
76+
* {@code Set<ProjectTag>} containing zero tags.
7777
*/
78-
private Optional<Set<Tag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
78+
private Optional<Set<ProjectTag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
7979
assert tags != null;
8080

8181
if (tags.isEmpty()) {

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import seedu.address.model.project.Email;
1414
import seedu.address.model.project.ProjectDescription;
1515
import seedu.address.model.project.ProjectName;
16-
import seedu.address.model.tag.Tag;
16+
import seedu.address.model.tag.ProjectTag;
1717
import seedu.address.model.task.Task;
1818

1919
/**
@@ -97,30 +97,30 @@ public static Email parseEmail(String email) throws ParseException {
9797
}
9898

9999
/**
100-
* Parses a {@code String tag} into a {@code Tag}.
100+
* Parses a {@code String projectTag} into a {@code ProjectTag}.
101101
* Leading and trailing whitespaces will be trimmed.
102102
*
103-
* @throws ParseException if the given {@code tag} is invalid.
103+
* @throws ParseException if the given {@code projectTag} is invalid.
104104
*/
105-
public static Tag parseTag(String tag) throws ParseException {
106-
requireNonNull(tag);
107-
String trimmedTag = tag.trim();
108-
if (!Tag.isValidTagName(trimmedTag)) {
109-
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
105+
public static ProjectTag parseProjectTag(String projectTag) throws ParseException {
106+
requireNonNull(projectTag);
107+
String trimmedTag = projectTag.trim();
108+
if (!ProjectTag.isValidProjectTagName(trimmedTag)) {
109+
throw new ParseException(ProjectTag.MESSAGE_CONSTRAINTS);
110110
}
111-
return new Tag(trimmedTag);
111+
return new ProjectTag(trimmedTag);
112112
}
113113

114114
/**
115-
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
115+
* Parses {@code Collection<String> projectTags} into a {@code Set<ProjectTag>}.
116116
*/
117-
public static Set<Tag> parseTags(Collection<String> tags) throws ParseException {
118-
requireNonNull(tags);
119-
final Set<Tag> tagSet = new HashSet<>();
120-
for (String tagName : tags) {
121-
tagSet.add(parseTag(tagName));
117+
public static Set<ProjectTag> parseTags(Collection<String> projectTags) throws ParseException {
118+
requireNonNull(projectTags);
119+
final Set<ProjectTag> projectTagSet = new HashSet<>();
120+
for (String tagName : projectTags) {
121+
projectTagSet.add(parseProjectTag(tagName));
122122
}
123-
return tagSet;
123+
return projectTagSet;
124124
}
125125

126126
/**

src/main/java/seedu/address/model/person/Person.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import seedu.address.model.project.Participation;
1212
import seedu.address.model.project.Project;
1313
import seedu.address.model.project.ProjectName;
14-
import seedu.address.model.tag.Tag;
14+
import seedu.address.model.tag.ProjectTag;
1515

1616
/**
1717
* Represents a Teammate in the team.
@@ -26,19 +26,19 @@ public class Person {
2626

2727
// Data fields
2828
private Address address;
29-
private final Set<Tag> tags = new HashSet<>();
29+
private final Set<ProjectTag> projectTags = new HashSet<>();
3030
private HashMap<ProjectName, Participation> listOfParticipations = new HashMap<>();
3131

3232
/**
3333
* Every field must be present and not null.
3434
*/
35-
public Person(PersonName personName, Phone phone, Email email, Address address, Set<Tag> tags) {
36-
requireAllNonNull(personName, phone, email, address, tags);
35+
public Person(PersonName personName, Phone phone, Email email, Address address, Set<ProjectTag> projectTags) {
36+
requireAllNonNull(personName, phone, email, address, projectTags);
3737
this.personName = personName;
3838
this.phone = phone;
3939
this.email = email;
4040
this.address = address;
41-
this.tags.addAll(tags);
41+
this.projectTags.addAll(projectTags);
4242
}
4343

4444
public PersonName getPersonName() {
@@ -81,8 +81,8 @@ public void addProject(Project p) {
8181
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
8282
* if modification is attempted.
8383
*/
84-
public Set<Tag> getTags() {
85-
return Collections.unmodifiableSet(tags);
84+
public Set<ProjectTag> getTags() {
85+
return Collections.unmodifiableSet(projectTags);
8686
}
8787

8888
/**
@@ -126,7 +126,7 @@ public boolean equals(Object other) {
126126
@Override
127127
public int hashCode() {
128128
// use this method for custom fields hashing instead of implementing your own
129-
return Objects.hash(personName, phone, email, address, tags);
129+
return Objects.hash(personName, phone, email, address, projectTags);
130130
}
131131

132132
@Override

0 commit comments

Comments
 (0)