-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathParser.java
More file actions
72 lines (46 loc) · 1.84 KB
/
Parser.java
File metadata and controls
72 lines (46 loc) · 1.84 KB
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
public class Parser {
private String fullText;
public Parser(String fullText) {
this.fullText = fullText;
}
public String checkCommand() throws JustinException {
try {
validate(fullText);
if (fullText.equals("bye")) {
return "BYE";
} else if (fullText.equals("list")) {
return "LIST";
} else if (fullText.contains("done")) {
return "DONE";
} else if (fullText.contains("deadline")) {
return "DEADLINE";
} else if (fullText.contains("todo")) {
return "TODO";
} else if (fullText.contains("event")) {
return "EVENT";
}
else if (fullText.contains("delete")) {
return "DELETE";
} else if (fullText.contains("find")) {
return "FIND";
}
else {
return "ADD";
}
} catch (JustinException m) {
throw new JustinException(m.getMessage());
}
}
static void validate(String text) throws JustinException {
if (text.length() < 5 && text.contains("todo") ) { // case 1
throw new JustinException("☹ OOPS!!! The description of a todo cannot be empty.");
}
else if (text.contains("blah")) { // case 2
throw new JustinException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
} else if (text.length() < 10 && text.contains("deadline")) { // case 3
throw new JustinException("☹ OOPS!!! The description of a deadline cannot be empty.");
} else if (text.length() < 6 && text.contains("event")) { // case 4
throw new JustinException("☹ OOPS!!! The description of a event cannot be empty.");
}
}
}