forked from nus-cs2103-AY2223S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserTask.java
74 lines (65 loc) · 2.2 KB
/
UserTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package meggy.task;
import meggy.Resource;
import meggy.Util;
import meggy.exception.MeggyException;
import meggy.exception.MeggyNoArgException;
/** Entries to be recorded by the chatbot. */
public abstract class UserTask {
/** Task description. */
public final String desc;
/** The line (command and extra space removed) that created this task. Stored to avoid repeated regeneration. */
final String args;
/** Task completion status. */
private boolean isDone;
/**
* Sets description and args value to the task.
*
* @param desc Non-null. Description string of task with command removed.
* @param args Non-null. The line (command and extra space removed) that created this task.
*/
UserTask(String desc, String args) throws MeggyException {
assert desc != null;
assert args != null;
if (desc.isEmpty()) { // No arguments
throw new MeggyNoArgException();
}
this.desc = desc;
this.args = args;
isDone = false;
}
/**
* Get ask type label from their names.
*
* @param taskType Non-null, non-empty. Name of task type.
* @return Task-type-specific label.
*/
public static String getTaskTypeLabel(String taskType) {
assert taskType != null;
return Util.parenthesize(Character.toUpperCase(taskType.charAt(0)));
}
/**
* Formats the time keywords used to indicate date-time in user input.
*
* @param keyword Non-null. Raw time keyword.
* @return Command-syntax-marking time keyword.
*/
public static String fmtKeyword(String keyword) {
assert keyword != null;
return '/' + keyword + ' ';
}
/** Gets task completion status. */
public boolean isDone() {
return isDone;
}
/** Updates task completion status. */
public void setDone(boolean done) {
isDone = done;
}
/** @return Re-create the entry line that would create the task. */
public abstract String recreateCmd();
/** @return The string representation of this task in text UI. */
@Override
public String toString() {
return Util.parenthesize(isDone ? Resource.DONE_MK : ' ') + ' ' + desc;
}
}