Skip to content

Commit 7d27c17

Browse files
committed
Merge branch 'branch-A-Release'
# Conflicts: # src/test/java/model/TaskListTest.java
2 parents 4caf917 + 1d644c2 commit 7d27c17

24 files changed

+260
-100
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id 'java'
33
id 'application'
4-
// id 'checkstyle'
4+
id 'checkstyle'
55
id 'com.github.johnrengelman.shadow' version '5.1.0'
66
}
77

@@ -25,9 +25,9 @@ run {
2525
standardInput = System.in
2626
}
2727

28-
//checkstyle {
29-
// toolVersion = '8.23'
30-
//}
28+
checkstyle {
29+
toolVersion = '8.23'
30+
}
3131

3232
test {
3333
useJUnitPlatform()

src/main/java/Duke.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
//package java;
22

3-
import exceptions.*;
3+
import exceptions.IllegalPositionException;
4+
import exceptions.IllegalDateTimeFormatException;
5+
import exceptions.InvalidStorageFilePathException;
6+
import exceptions.NoCommandException;
7+
import exceptions.NoDescriptionException;
8+
import exceptions.StorageOperationException;
9+
410
import parser.Command;
511
import parser.Parser;
612
import parser.HelpCommand;
@@ -27,21 +33,30 @@ public Duke() {
2733
}
2834

2935
/**
30-
* Load the storage from file into internal task list.
31-
* Initiate other components.
36+
* Checks does a user input match an exit key.
37+
* @param input user input in string.
38+
* @return true if user input matches exit key.
3239
*/
33-
public Duke(String userName) {
34-
this.userName = userName;
35-
}
36-
3740
public static boolean isExitKey(String input) {
3841
return Parser.isExitKey(input);
3942
}
4043

44+
/**
45+
* Returns greeting string to the screen.
46+
* @return greet text.
47+
*/
4148
public String greet() {
4249
return HelpCommand.HELP_TEXT;
4350
}
4451

52+
/**
53+
* Initializes components.
54+
* @throws InvalidStorageFilePathException If default storage path is invalid.
55+
* @throws IllegalDateTimeFormatException If datetime strings of loaded tasks are invalid.
56+
* @throws NoDescriptionException If loaded tasks do not have description.
57+
* @throws StorageOperationException If there is error decoding tasks.
58+
* @throws IOException If there is error reading files.
59+
*/
4560
public void start() throws
4661
InvalidStorageFilePathException, IllegalDateTimeFormatException,
4762
NoDescriptionException, StorageOperationException, IOException {
@@ -53,17 +68,16 @@ public void start() throws
5368
/**
5469
* Listen to the user input and take actions.
5570
*/
56-
public String getResponse(String input) throws RuntimeException{
71+
public String getResponse(String input) throws RuntimeException {
5772
Command command = null;
58-
// assert false: "this is for testing";
5973
try {
6074
command = parser.parseCommand(input);
6175
command.setTaskList(taskList);
6276
String commandResult = command.execute();
6377
storage.save(taskList);
6478

65-
assert commandResult != null: "The response message is null";
66-
assert commandResult.length() > 0: "The response message is empty";
79+
assert commandResult != null : "The response message is null";
80+
assert commandResult.length() > 0 : "The response message is empty";
6781

6882
return commandResult;
6983
} catch (NoDescriptionException

src/main/java/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414
public class Main extends Application {
1515

16-
private final String APP_NAME = "Duke";
17-
private final Image APP_ICON = new Image(
16+
private final String appName = "Duke";
17+
private final Image appIcon = new Image(
1818
this.getClass().getResourceAsStream("/images/DukeIcon.png"),
1919
80,
2020
80,
@@ -36,8 +36,8 @@ public void start(Stage stage) {
3636
mainWindow.setDuke(duke);
3737
mainWindow.dukeSpeak(duke.greet());
3838

39-
stage.setTitle(APP_NAME);
40-
stage.getIcons().add(APP_ICON);
39+
stage.setTitle(appName);
40+
stage.getIcons().add(appIcon);
4141
stage.show();
4242
} catch (IOException e) {
4343
e.printStackTrace();

src/main/java/MainWindow.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public void initialize() {
4545
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
4646
}
4747

48+
/**
49+
* assign a Duke object to the variable duke.
50+
* @param d a duke instance.
51+
*/
4852
public void setDuke(Duke d) {
4953
try {
5054
duke = d;
@@ -56,6 +60,10 @@ public void setDuke(Duke d) {
5660
}
5761
}
5862

63+
/**
64+
* Generates duke dialog box.
65+
* @param input String to be displayed on screen.
66+
*/
5967
public void dukeSpeak(String input) {
6068
dialogContainer.getChildren().add(
6169
DialogBox.getDukeDialog(input, dukeImage)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package exceptions;
22

33
public class IllegalPositionException extends Exception {
4-
public IllegalPositionException(String cause) { super(cause); }
4+
public IllegalPositionException(String cause) {
5+
super(cause);
6+
}
57
}

src/main/java/model/DeadLineTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public String getTaskType() {
6060
*/
6161
@Override
6262
public ArrayList<String> getDetails() {
63-
assert description != null: "task description not assigned";
64-
assert description.length() > 0: "task description is empty";
63+
assert description != null : "task description not assigned";
64+
assert description.length() > 0 : "task description is empty";
6565

6666
return new ArrayList<String>(Arrays.asList(
6767
this.description,
@@ -70,7 +70,7 @@ public ArrayList<String> getDetails() {
7070

7171
@Override
7272
public boolean isOnDate(LocalDate targetDate) {
73-
assert by != null: "the value of 'by' not assigned";
73+
assert by != null : "the value of 'by' not assigned";
7474
return by.toLocalDate().equals(targetDate);
7575
}
7676

@@ -80,7 +80,7 @@ public boolean isOnDate(LocalDate targetDate) {
8080
*/
8181
@Override
8282
public String toString() {
83-
assert by != null: "the value of 'by' not assigned";
83+
assert by != null : "the value of 'by' not assigned";
8484
return "[" + TASK_TYPE_CHA + "]" + super.toString() + " (by: " + by.format(DATE_TIME_FORMAT) + ")";
8585
}
8686
}

src/main/java/model/EventTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public EventTask(String description, LocalDateTime at, boolean isDone) throws No
5050
*/
5151
@Override
5252
public ArrayList<String> getDetails() {
53-
assert description != null: "task description not assigned";
54-
assert description.length() > 0: "task description is empty";
53+
assert description != null : "task description not assigned";
54+
assert description.length() > 0 : "task description is empty";
5555

5656
return new ArrayList<String>(Arrays.asList(
5757
this.description,
@@ -70,7 +70,7 @@ public String getTaskType() {
7070

7171
@Override
7272
public boolean isOnDate(LocalDate targetDate) {
73-
assert at != null: "the value of 'at' not assigned";
73+
assert at != null : "the value of 'at' not assigned";
7474
return at.toLocalDate().equals(targetDate);
7575
}
7676

@@ -80,7 +80,7 @@ public boolean isOnDate(LocalDate targetDate) {
8080
*/
8181
@Override
8282
public String toString() {
83-
assert at != null: "the value of 'at' not assigned";
83+
assert at != null : "the value of 'at' not assigned";
8484
return "[" + TASK_TYPE_CHA + "]" + super.toString() + " (at: " + at.format(DATE_TIME_FORMAT) + ")";
8585
}
8686
}

src/main/java/model/Task.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ public void setDescription(String description) throws NoDescriptionException {
7777
this.description = description;
7878
}
7979

80+
/**
81+
* Checks whether the description of a task contains the inputted keyword.
82+
* @param keyWord user input keyword.
83+
* @return true if the description contains the keyword, false otherwise.
84+
*/
8085
public boolean hasKeyWord(String keyWord) {
81-
assert description != null: "description not assigned";
82-
assert description.length() > 0: "task description is empty";
86+
assert description != null : "description not assigned";
87+
assert description.length() > 0 : "task description is empty";
8388
return description.toLowerCase().contains(keyWord.toLowerCase());
8489
}
8590

@@ -103,8 +108,8 @@ private String getStatusIcon() {
103108
* @return description of the task.
104109
*/
105110
public String getDescription() {
106-
assert description != null: "description not assigned";
107-
assert description.length() > 0: "task description is empty";
111+
assert description != null : "description not assigned";
112+
assert description.length() > 0 : "task description is empty";
108113
return this.description;
109114
}
110115

@@ -113,8 +118,8 @@ public String getDescription() {
113118
* @return an arraylist including the description.
114119
*/
115120
public ArrayList<String> getDetails() {
116-
assert description != null: "description not assigned";
117-
assert description.length() > 0: "task description is empty";
121+
assert description != null : "description not assigned";
122+
assert description.length() > 0 : "task description is empty";
118123
return new ArrayList<String>(Collections.singletonList(this.description));
119124
}
120125

@@ -138,8 +143,8 @@ public void markAsDone() {
138143
* @return String.
139144
*/
140145
public String toString() {
141-
assert description != null: "description not assigned";
142-
assert description.length() > 0: "task description is empty";
146+
assert description != null : "description not assigned";
147+
assert description.length() > 0 : "task description is empty";
143148
return "[" + this.getStatusIcon() + "]" + " " + this.getDescription();
144149
}
145150
}

src/main/java/model/TaskList.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String add(Task task) {
5555

5656
String addTaskEndStr = addTaskEnd.insert(13, this.internalList.size()).toString();
5757

58-
assert this.internalList.size() > 0: "task not added";
58+
assert this.internalList.size() > 0 : "task not added";
5959
return ECHO_ADD_TASK
6060
+ task.toString()
6161
+ "\n"
@@ -68,7 +68,7 @@ public String add(Task task) {
6868
* @return response of the remove action.
6969
*/
7070
public String remove(int position) throws IllegalPositionException {
71-
assert this.internalList.size() > 0: "task list is empty, cannot delete";
71+
assert this.internalList.size() > 0 : "task list is empty, cannot delete";
7272

7373

7474
if (position < 0 || position >= internalList.size()) {
@@ -93,7 +93,7 @@ public String remove(int position) throws IllegalPositionException {
9393
* @return response of the mark action.
9494
*/
9595
public String markTaskAsDone(int position) throws IllegalPositionException {
96-
assert this.internalList.size() > 0: "task list is empty, cannot mark";
96+
assert this.internalList.size() > 0 : "task list is empty, cannot mark";
9797

9898
if (position < 0 || position >= internalList.size()) {
9999
throw new IllegalPositionException("Oops!!! The input position "
@@ -108,13 +108,18 @@ public String markTaskAsDone(int position) throws IllegalPositionException {
108108
+ "\n";
109109
}
110110

111+
/**
112+
* Filters tasks by checking whether the description contains a specific keyword.
113+
* @param keyWord user input keyword.
114+
* @return string representations of matched tasks.
115+
*/
111116
public String findByKeyWord(String keyWord) {
112117
StringBuilder matchedTasks = new StringBuilder();
113118
matchedTasks.append(ECHO_FIND_TASK);
114119

115120
for (int i = 0; i < this.internalList.size(); i++) {
116121
if (this.internalList.get(i) == null) {
117-
assert false: "element in arraylist is null";
122+
assert false : "element in arraylist is null";
118123
continue;
119124
}
120125
Task currentTask = this.internalList.get(i);
@@ -129,6 +134,11 @@ public String findByKeyWord(String keyWord) {
129134
return matchedTasks.toString();
130135
}
131136

137+
/**
138+
* Filters tasks by date. Ignore todo tasks.
139+
* @param targetDate user input date.
140+
* @return string representation of matches tasks.
141+
*/
132142
public String findTasksOnDate(LocalDate targetDate) {
133143
StringBuilder tasksOnDate = new StringBuilder();
134144
tasksOnDate.append(ECHO_VIEW_SCHEDULE);
@@ -138,7 +148,7 @@ public String findTasksOnDate(LocalDate targetDate) {
138148

139149
for (int i = 0; i < this.internalList.size(); i++) {
140150
if (this.internalList.get(i) == null) {
141-
assert false: "element in arraylist is null";
151+
assert false : "element in arraylist is null";
142152
continue;
143153
}
144154
Task currentTask = this.internalList.get(i);
@@ -161,6 +171,10 @@ public int size() {
161171
return internalList.size();
162172
}
163173

174+
public Task getTask(int index) {
175+
return internalList.get(index);
176+
}
177+
164178
/**
165179
* Converts the task list to a string by looping through the tasks and concatenate
166180
* all the string representation of tasks.
@@ -170,7 +184,7 @@ public String toString() {
170184
StringBuilder listOverView = new StringBuilder(ECHO_VIEW_TASK_LIST);
171185
for (int i = 0; i < this.internalList.size(); i++) {
172186
if (this.internalList.get(i) == null) {
173-
assert false: "element in arraylist is null";
187+
assert false : "element in arraylist is null";
174188
continue;
175189
}
176190
listOverView.append(Integer.toString(i + 1));

src/main/java/parser/Command.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public int findIndex(Pattern pattern, String input) {
5454
matcher.find();
5555

5656
String index = matcher.group(POSITION_TARGET_INDEX);
57-
assert index != null: "cannot find index";
57+
assert index != null : "cannot find index";
5858
return Integer.parseInt(index) - DIFFERENCE_IN_START_INDEX;
5959
}
6060

@@ -69,7 +69,7 @@ public String findDescription(Pattern pattern, String input) {
6969
matcher.find();
7070

7171
String description = matcher.group(POSITION_DESCRIPTION);
72-
assert description != null: "cannot find index";
72+
assert description != null : "cannot find index";
7373
return description.trim();
7474
}
7575

@@ -86,16 +86,24 @@ public LocalDateTime findDateTime(Pattern pattern, String input) throws IllegalD
8686
String dateString = matcher.group(POSITION_DATE);
8787
String timeString = matcher.group(POSITION_TIME);
8888

89-
assert dateString != null: "cannot find date string";
89+
assert dateString != null : "cannot find date string";
9090
return parseDateTime(dateString, timeString);
9191
}
9292

93+
/**
94+
* Finds the date string from the user input by regex.
95+
* Converts the date string to LocalDate object.
96+
* @param pattern Regex used to parse user input.
97+
* @param input user input.
98+
* @return parse LocalDate object.
99+
* @throws IllegalDateTimeFormatException if the date string is in invalid format.
100+
*/
93101
public LocalDate findDate(Pattern pattern, String input) throws IllegalDateTimeFormatException {
94102
Matcher matcher = pattern.matcher(input);
95103
matcher.find();
96104
String dateString = matcher.group(POSITION_VIEW_SCHEDULE_DATE);
97105

98-
assert dateString != null: "cannot find date string";
106+
assert dateString != null : "cannot find date string";
99107
return parseDate(dateString);
100108
}
101109

@@ -110,7 +118,7 @@ public String findKeyword(Pattern pattern, String input) {
110118
matcher.find();
111119

112120
String keyWord = matcher.group(POSITION_KEYWORD);
113-
assert keyWord != null: "cannot find keyword";
121+
assert keyWord != null : "cannot find keyword";
114122
return matcher.group(POSITION_KEYWORD);
115123
}
116124

0 commit comments

Comments
 (0)