Skip to content

Commit e85fb6f

Browse files
Merge pull request #130 from PhongTran98/branch-priority
Implement Bug Priority feature and write relevant tests
2 parents 76291c6 + 6c07e57 commit e85fb6f

28 files changed

Lines changed: 565 additions & 100 deletions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.Objects.requireNonNull;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
67
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATE;
78
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
89

@@ -22,11 +23,13 @@ public class AddCommand extends Command {
2223
+ PREFIX_NAME + "NAME "
2324
+ "[" + PREFIX_STATE + "STATE] "
2425
+ PREFIX_DESCRIPTION + "DESCRIPTION "
26+
+ PREFIX_PRIORITY + "PRIORITY] "
2527
+ "[" + PREFIX_TAG + "TAG]...\n"
2628
+ "Example: " + COMMAND_WORD + " "
2729
+ PREFIX_NAME + "Array size error "
2830
+ PREFIX_STATE + "backlog "
2931
+ PREFIX_DESCRIPTION + "ArrayStoreException due to array being too small "
32+
+ PREFIX_PRIORITY + "medium "
3033
+ PREFIX_TAG + "Array "
3134
+ PREFIX_TAG + "Size ";
3235

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static java.util.Objects.requireNonNull;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
67
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATE;
78
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
89
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_BUGS;
@@ -21,6 +22,7 @@
2122
import seedu.address.model.bug.Bug;
2223
import seedu.address.model.bug.Description;
2324
import seedu.address.model.bug.Name;
25+
import seedu.address.model.bug.Priority;
2426
import seedu.address.model.bug.State;
2527
import seedu.address.model.tag.Tag;
2628

@@ -39,6 +41,7 @@ public class EditCommand extends Command {
3941
+ "[" + PREFIX_NAME + "NAME] "
4042
+ "[" + PREFIX_STATE + "STATE] "
4143
+ "[" + PREFIX_DESCRIPTION + "DESCRIPTION] "
44+
+ "[" + PREFIX_PRIORITY + "PRIORITY] "
4245
+ "[" + PREFIX_TAG + "TAG]...\n"
4346
+ "Example: " + COMMAND_WORD + " 1 "
4447
+ PREFIX_STATE + "johndoe@example.com";
@@ -94,8 +97,9 @@ private static Bug createEditedBug(Bug bugToEdit, EditBugDescriptor editBugDescr
9497
State updatedState = editBugDescriptor.getState().orElse(bugToEdit.getState());
9598
Description updatedDescription = editBugDescriptor.getDescription().orElse(bugToEdit.getDescription());
9699
Set<Tag> updatedTags = editBugDescriptor.getTags().orElse(bugToEdit.getTags());
100+
Priority updatedPriority = editBugDescriptor.getPriority().orElse(bugToEdit.getPriority());
97101

98-
return new Bug(updatedName, updatedState, updatedDescription, updatedTags);
102+
return new Bug(updatedName, updatedState, updatedDescription, updatedTags, updatedPriority);
99103
}
100104

101105
@Override
@@ -125,6 +129,7 @@ public static class EditBugDescriptor {
125129
private State state;
126130
private Description description;
127131
private Set<Tag> tags;
132+
private Priority priority;
128133

129134
public EditBugDescriptor() {}
130135

@@ -137,13 +142,14 @@ public EditBugDescriptor(EditBugDescriptor toCopy) {
137142
setState(toCopy.state);
138143
setDescription(toCopy.description);
139144
setTags(toCopy.tags);
145+
setPriority(toCopy.priority);
140146
}
141147

142148
/**
143149
* Returns true if at least one field is edited.
144150
*/
145151
public boolean isAnyFieldEdited() {
146-
return CollectionUtil.isAnyNonNull(name, state, description, tags);
152+
return CollectionUtil.isAnyNonNull(name, state, description, tags, priority);
147153
}
148154

149155
public void setName(Name name) {
@@ -170,6 +176,14 @@ public Optional<Description> getDescription() {
170176
return Optional.ofNullable(description);
171177
}
172178

179+
public void setPriority(Priority priority) {
180+
this.priority = priority;
181+
}
182+
183+
public Optional<Priority> getPriority() {
184+
return Optional.ofNullable(priority);
185+
}
186+
173187
/**
174188
* Sets {@code tags} to this object's {@code tags}.
175189
* A defensive copy of {@code tags} is used internally.
@@ -205,6 +219,7 @@ public boolean equals(Object other) {
205219
return getName().equals(e.getName())
206220
&& getState().equals(e.getState())
207221
&& getDescription().equals(e.getDescription())
222+
&& getPriority().equals(e.getPriority())
208223
&& getTags().equals(e.getTags());
209224
}
210225
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public CommandResult execute(Model model) throws CommandException {
5959

6060
private static Bug createMovedBug(Bug bugToMove, State destination) {
6161
assert bugToMove != null;
62-
return new Bug(bugToMove.getName(), destination, bugToMove.getDescription(), bugToMove.getTags());
62+
return new Bug(bugToMove.getName(), destination, bugToMove.getDescription(),
63+
bugToMove.getTags(), bugToMove.getPriority());
6364
}
6465

6566
@Override

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
67
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATE;
78
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
89

@@ -14,6 +15,7 @@
1415
import seedu.address.model.bug.Bug;
1516
import seedu.address.model.bug.Description;
1617
import seedu.address.model.bug.Name;
18+
import seedu.address.model.bug.Priority;
1719
import seedu.address.model.bug.State;
1820
import seedu.address.model.tag.Tag;
1921

@@ -23,15 +25,16 @@
2325
public class AddCommandParser implements Parser<AddCommand> {
2426

2527
public static final State DEFAULT_STATE = new State("backlog");
28+
public static final Priority DEFAULT_PRIORITY = new Priority();
2629

2730
/**
2831
* Parses the given {@code String} of arguments in the context of the AddCommand
2932
* and returns an AddCommand object for execution.
3033
* @throws ParseException if the user input does not conform the expected format
3134
*/
3235
public AddCommand parse(String args) throws ParseException {
33-
ArgumentMultimap argMultimap =
34-
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STATE, PREFIX_DESCRIPTION, PREFIX_TAG);
36+
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STATE,
37+
PREFIX_DESCRIPTION, PREFIX_TAG, PREFIX_PRIORITY);
3538

3639
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DESCRIPTION)
3740
|| !argMultimap.getPreamble().isEmpty()) {
@@ -43,6 +46,7 @@ public AddCommand parse(String args) throws ParseException {
4346
Description description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get());
4447
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
4548
State state;
49+
Priority priority;
4650

4751
if (arePrefixesPresent(argMultimap, PREFIX_STATE)) {
4852
assert argMultimap.getValue(PREFIX_STATE).isPresent();
@@ -52,7 +56,13 @@ public AddCommand parse(String args) throws ParseException {
5256
state = DEFAULT_STATE;
5357
}
5458

55-
Bug bug = new Bug(name, state, description, tagList);
59+
if (arePrefixesPresent(argMultimap, PREFIX_PRIORITY)) {
60+
priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY).get());
61+
} else {
62+
priority = DEFAULT_PRIORITY;
63+
}
64+
65+
Bug bug = new Bug(name, state, description, tagList, priority);
5666
return new AddCommand(bug);
5767
}
5868

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public class CliSyntax {
1111
public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/");
1212
public static final Prefix PREFIX_TAG = new Prefix("t/");
1313
public static final Prefix PREFIX_QUERYSTRING = new Prefix("q/");
14+
public static final Prefix PREFIX_PRIORITY = new Prefix("pr/");
1415

1516
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
66
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
7+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
78
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATE;
89
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
910

@@ -16,6 +17,7 @@
1617
import seedu.address.logic.commands.EditCommand;
1718
import seedu.address.logic.commands.EditCommand.EditBugDescriptor;
1819
import seedu.address.logic.parser.exceptions.ParseException;
20+
import seedu.address.model.bug.Priority;
1921
import seedu.address.model.tag.Tag;
2022

2123
/**
@@ -30,8 +32,8 @@ public class EditCommandParser implements Parser<EditCommand> {
3032
*/
3133
public EditCommand parse(String args) throws ParseException {
3234
requireNonNull(args);
33-
ArgumentMultimap argMultimap =
34-
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STATE, PREFIX_DESCRIPTION, PREFIX_TAG);
35+
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STATE,
36+
PREFIX_DESCRIPTION, PREFIX_TAG, PREFIX_PRIORITY);
3537

3638
Index index;
3739
try {
@@ -48,10 +50,14 @@ public EditCommand parse(String args) throws ParseException {
4850
if (argMultimap.getValue(PREFIX_STATE).isPresent()) {
4951
editBugDescriptor.setState(ParserUtil.parseState(argMultimap.getValue(PREFIX_STATE).get()));
5052
}
53+
if (argMultimap.getValue(PREFIX_PRIORITY).isPresent()) {
54+
editBugDescriptor.setPriority(parsePriorityForEdit(argMultimap.getValue(PREFIX_PRIORITY).get()));
55+
}
5156
if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) {
5257
editBugDescriptor.setDescription(
5358
ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()));
5459
}
60+
5561
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editBugDescriptor::setTags);
5662

5763
if (!editBugDescriptor.isAnyFieldEdited()) {
@@ -78,4 +84,16 @@ private Optional<Set<Tag>> parseTagsForEdit(Collection<String> tags) throws Pars
7884
return Optional.of(ParserUtil.parseTags(tagSet));
7985
}
8086

87+
/**
88+
* Parses {@code String priority} into a {@code Priority} if {@conde priority} is a non-empty string.
89+
* If {@code priority} is an empty string, it will be parsed into a 'null' priority.
90+
*/
91+
private Priority parsePriorityForEdit(String priority) throws ParseException {
92+
assert priority != null;
93+
if (priority.equals("")) {
94+
return new Priority();
95+
}
96+
return ParserUtil.parsePriority(priority);
97+
}
98+
8199
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import seedu.address.logic.parser.exceptions.ParseException;
1212
import seedu.address.model.bug.Description;
1313
import seedu.address.model.bug.Name;
14+
import seedu.address.model.bug.Priority;
1415
import seedu.address.model.bug.State;
1516
import seedu.address.model.tag.Tag;
1617

@@ -106,6 +107,21 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
106107
return tagSet;
107108
}
108109

110+
/**
111+
* Parses {@code String priority} into a {@code Priority}.
112+
* Leading and trailing whitespaces will be trimmed.
113+
*
114+
* @throws ParseException if the given {@code priority} is invalid.
115+
*/
116+
public static Priority parsePriority(String priority) throws ParseException {
117+
requireNonNull(priority);
118+
String trimmedPriority = priority.trim();
119+
if (!Priority.isValidPriority(trimmedPriority)) {
120+
throw new ParseException(Priority.MESSAGE_CONSTRAINTS);
121+
}
122+
return new Priority(trimmedPriority);
123+
}
124+
109125
/**
110126
* Parses a {@code String queryString}.
111127
* Leading and trailing whitespaces will be trimmed.

src/main/java/seedu/address/model/bug/Bug.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ public class Bug {
2222
// Data fields
2323
private final Description description;
2424
private final Set<Tag> tags = new HashSet<>();
25+
private final Priority priority;
2526

2627
/**
2728
* Every field must be present and not null.
2829
*/
29-
public Bug(Name name, State state, Description description, Set<Tag> tags) {
30+
public Bug(Name name, State state, Description description, Set<Tag> tags, Priority priority) {
3031
requireAllNonNull(name, state, description, tags);
3132
this.name = name;
3233
this.state = state;
3334
this.description = description;
3435
this.tags.addAll(tags);
36+
this.priority = priority;
3537
}
3638

3739
public Name getName() {
@@ -54,6 +56,10 @@ public Set<Tag> getTags() {
5456
return Collections.unmodifiableSet(tags);
5557
}
5658

59+
public Priority getPriority() {
60+
return priority;
61+
}
62+
5763
/**
5864
* Returns true if both bugs of the same name have at least one other identity field that is the same.
5965
* This defines a weaker notion of equality between two bugs.
@@ -86,13 +92,14 @@ public boolean equals(Object other) {
8692
return otherBug.getName().equals(getName())
8793
&& otherBug.getState().equals(getState())
8894
&& otherBug.getDescription().equals(getDescription())
89-
&& otherBug.getTags().equals(getTags());
95+
&& otherBug.getTags().equals(getTags())
96+
&& otherBug.getPriority().equals(getPriority());
9097
}
9198

9299
@Override
93100
public int hashCode() {
94101
// use this method for custom fields hashing instead of implementing your own
95-
return Objects.hash(name, state, description, tags);
102+
return Objects.hash(name, state, description, tags, priority);
96103
}
97104

98105
@Override
@@ -103,6 +110,7 @@ public String toString() {
103110
.append(getState())
104111
.append(" Description: ")
105112
.append(getDescription())
113+
.append(getPriority().isNull() ? "" : " Priority: " + getPriority())
106114
.append(" Tags: ");
107115
getTags().forEach(builder::append);
108116
return builder.toString();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package seedu.address.model.bug;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.commons.util.AppUtil.checkArgument;
5+
6+
/**
7+
* Represents a bug's priority (low, medium or high)
8+
* Guarantees: immutable; is valid as declared in {@link #isValidPriority(String)} (String)}
9+
*/
10+
public class Priority {
11+
public static final String MESSAGE_CONSTRAINTS = "Priority level should only be either low, medium or high.";
12+
public static final String EMPTY_PRIORITY = "";
13+
14+
private static final String LOW_REGEX = "((?i)\\blow\\b)";
15+
private static final String MEDIUM_REGEX = "((?i)\\bmedium\\b)";
16+
private static final String HIGH_REGEX = "((?i)\\bhigh\\b)";
17+
public static final String VALIDATION_REGEX =
18+
LOW_REGEX + "|" + MEDIUM_REGEX + "|" + HIGH_REGEX;
19+
20+
private final String priority;
21+
22+
/**
23+
* Construct a (@code Priority} object (low, medium or high priority)
24+
* @param priority
25+
*/
26+
public Priority(String priority) {
27+
requireNonNull(priority);
28+
checkArgument(isValidPriority(priority), MESSAGE_CONSTRAINTS);
29+
this.priority = priority.toLowerCase();
30+
}
31+
32+
/**
33+
* Construct a {@code Priority} object (priority not indicated)
34+
*/
35+
public Priority() {
36+
priority = Priority.EMPTY_PRIORITY;
37+
}
38+
39+
public boolean isNull() {
40+
return priority.equals(Priority.EMPTY_PRIORITY);
41+
}
42+
43+
public static boolean isValidPriority(String test) {
44+
return test.matches(VALIDATION_REGEX);
45+
}
46+
47+
public String getValue() {
48+
return isNull() ? "" : priority;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return priority;
54+
}
55+
56+
@Override
57+
public boolean equals(Object other) {
58+
return other == this
59+
|| (other instanceof Priority)
60+
&& this.priority.equals(((Priority) other).priority);
61+
}
62+
63+
@Override
64+
public int hashCode() {
65+
return priority.hashCode();
66+
}
67+
}

0 commit comments

Comments
 (0)