Skip to content

Commit 61da633

Browse files
authored
Merge pull request nus-cs2103-AY2021S2#66 from geraldfan/refactor-geraldfan-addressbook
Refactor AddressBook to TaskTracker
2 parents ca4a7d7 + 7432ef0 commit 61da633

49 files changed

Lines changed: 560 additions & 512 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/DeveloperGuide.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The `UI` component,
8080
**API** :
8181
[`Logic.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/logic/Logic.java)
8282

83-
1. `Logic` uses the `AddressBookParser` class to parse the user command.
83+
1. `Logic` uses the `TaskTrackerParser` class to parse the user command.
8484
1. This results in a `Command` object which is executed by the `LogicManager`.
8585
1. The command execution can affect the `Model` (e.g. adding a person).
8686
1. The result of the command execution is encapsulated as a `CommandResult` object which is passed back to the `Ui`.
@@ -107,7 +107,7 @@ The `Model`,
107107
* does not depend on any of the other three components.
108108

109109

110-
<div markdown="span" class="alert alert-info">:information_source: **Note:** An alternative (arguably, a more OOP) model is given below. It has a `Tag` list in the `AddressBook`, which `Person` references. This allows `AddressBook` to only require one `Tag` object per unique `Tag`, instead of each `Person` needing their own `Tag` object.<br>
110+
<div markdown="span" class="alert alert-info">:information_source: **Note:** An alternative (arguably, a more OOP) model is given below. It has a `Tag` list in the `TaskTracker`, which `Person` references. This allows `TaskTracker` to only require one `Tag` object per unique `Tag`, instead of each `Person` needing their own `Tag` object.<br>
111111
![BetterModelClassDiagram](images/BetterModelClassDiagram.png)
112112

113113
</div>
@@ -137,37 +137,37 @@ This section describes some noteworthy details on how certain features are imple
137137

138138
#### Proposed Implementation
139139

140-
The proposed undo/redo mechanism is facilitated by `VersionedAddressBook`. It extends `AddressBook` with an undo/redo history, stored internally as an `addressBookStateList` and `currentStatePointer`. Additionally, it implements the following operations:
140+
The proposed undo/redo mechanism is facilitated by `VersionedTaskTracker`. It extends `TaskTracker` with an undo/redo history, stored internally as an `taskTrackerStateList` and `currentStatePointer`. Additionally, it implements the following operations:
141141

142-
* `VersionedAddressBook#commit()` — Saves the current address book state in its history.
143-
* `VersionedAddressBook#undo()` — Restores the previous address book state from its history.
144-
* `VersionedAddressBook#redo()` — Restores a previously undone address book state from its history.
142+
* `VersionedTaskTracker#commit()` — Saves the current address book state in its history.
143+
* `VersionedTaskTracker#undo()` — Restores the previous address book state from its history.
144+
* `VersionedTaskTracker#redo()` — Restores a previously undone address book state from its history.
145145

146-
These operations are exposed in the `Model` interface as `Model#commitAddressBook()`, `Model#undoAddressBook()` and `Model#redoAddressBook()` respectively.
146+
These operations are exposed in the `Model` interface as `Model#commitTaskTracker()`, `Model#undoTaskTracker()` and `Model#redoTaskTracker()` respectively.
147147

148148
Given below is an example usage scenario and how the undo/redo mechanism behaves at each step.
149149

150-
Step 1. The user launches the application for the first time. The `VersionedAddressBook` will be initialized with the initial address book state, and the `currentStatePointer` pointing to that single address book state.
150+
Step 1. The user launches the application for the first time. The `VersionedTaskTracker` will be initialized with the initial address book state, and the `currentStatePointer` pointing to that single address book state.
151151

152152
![UndoRedoState0](images/UndoRedoState0.png)
153153

154-
Step 2. The user executes `delete 5` command to delete the 5th person in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.
154+
Step 2. The user executes `delete 5` command to delete the 5th person in the address book. The `delete` command calls `Model#commitTaskTracker()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `taskTrackerStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.
155155

156156
![UndoRedoState1](images/UndoRedoState1.png)
157157

158-
Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.
158+
Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitTaskTracker()`, causing another modified address book state to be saved into the `taskTrackerStateList`.
159159

160160
![UndoRedoState2](images/UndoRedoState2.png)
161161

162-
<div markdown="span" class="alert alert-info">:information_source: **Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the address book state will not be saved into the `addressBookStateList`.
162+
<div markdown="span" class="alert alert-info">:information_source: **Note:** If a command fails its execution, it will not call `Model#commitTaskTracker()`, so the address book state will not be saved into the `taskTrackerStateList`.
163163

164164
</div>
165165

166-
Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.
166+
Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoTaskTracker()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.
167167

168168
![UndoRedoState3](images/UndoRedoState3.png)
169169

170-
<div markdown="span" class="alert alert-info">:information_source: **Note:** If the `currentStatePointer` is at index 0, pointing to the initial AddressBook state, then there are no previous AddressBook states to restore. The `undo` command uses `Model#canUndoAddressBook()` to check if this is the case. If so, it will return an error to the user rather
170+
<div markdown="span" class="alert alert-info">:information_source: **Note:** If the `currentStatePointer` is at index 0, pointing to the initial TaskTracker state, then there are no previous TaskTracker states to restore. The `undo` command uses `Model#canUndoTaskTracker()` to check if this is the case. If so, it will return an error to the user rather
171171
than attempting to perform the undo.
172172

173173
</div>
@@ -180,17 +180,17 @@ The following sequence diagram shows how the undo operation works:
180180

181181
</div>
182182

183-
The `redo` command does the opposite — it calls `Model#redoAddressBook()`, which shifts the `currentStatePointer` once to the right, pointing to the previously undone state, and restores the address book to that state.
183+
The `redo` command does the opposite — it calls `Model#redoTaskTracker()`, which shifts the `currentStatePointer` once to the right, pointing to the previously undone state, and restores the address book to that state.
184184

185-
<div markdown="span" class="alert alert-info">:information_source: **Note:** If the `currentStatePointer` is at index `addressBookStateList.size() - 1`, pointing to the latest address book state, then there are no undone AddressBook states to restore. The `redo` command uses `Model#canRedoAddressBook()` to check if this is the case. If so, it will return an error to the user rather than attempting to perform the redo.
185+
<div markdown="span" class="alert alert-info">:information_source: **Note:** If the `currentStatePointer` is at index `taskTrackerStateList.size() - 1`, pointing to the latest address book state, then there are no undone TaskTracker states to restore. The `redo` command uses `Model#canRedoTaskTracker()` to check if this is the case. If so, it will return an error to the user rather than attempting to perform the redo.
186186

187187
</div>
188188

189-
Step 5. The user then decides to execute the command `list`. Commands that do not modify the address book, such as `list`, will usually not call `Model#commitAddressBook()`, `Model#undoAddressBook()` or `Model#redoAddressBook()`. Thus, the `addressBookStateList` remains unchanged.
189+
Step 5. The user then decides to execute the command `list`. Commands that do not modify the address book, such as `list`, will usually not call `Model#commitTaskTracker()`, `Model#undoTaskTracker()` or `Model#redoTaskTracker()`. Thus, the `taskTrackerStateList` remains unchanged.
190190

191191
![UndoRedoState4](images/UndoRedoState4.png)
192192

193-
Step 6. The user executes `clear`, which calls `Model#commitAddressBook()`. Since the `currentStatePointer` is not pointing at the end of the `addressBookStateList`, all address book states after the `currentStatePointer` will be purged. Reason: It no longer makes sense to redo the `add n/David …​` command. This is the behavior that most modern desktop applications follow.
193+
Step 6. The user executes `clear`, which calls `Model#commitTaskTracker()`. Since the `currentStatePointer` is not pointing at the end of the `taskTrackerStateList`, all address book states after the `currentStatePointer` will be purged. Reason: It no longer makes sense to redo the `add n/David …​` command. This is the behavior that most modern desktop applications follow.
194194

195195
![UndoRedoState5](images/UndoRedoState5.png)
196196

@@ -274,16 +274,16 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
274274

275275
### Use cases
276276

277-
(For all use cases below, the **System** is the `AddressBook` and the **Actor** is the `user`, unless specified otherwise)
277+
(For all use cases below, the **System** is the `TaskTracker` and the **Actor** is the `user`, unless specified otherwise)
278278

279279
**Use case: Delete a deadline**
280280

281281
**MSS**
282282

283283
1. User requests to list deadlines
284-
2. AddressBook shows a list of deadlines
284+
2. TaskTracker shows a list of deadlines
285285
3. User requests to delete a specific deadline in the list
286-
4. AddressBook deletes the deadline
286+
4. TaskTracker deletes the deadline
287287

288288
Use case ends.
289289

@@ -295,16 +295,16 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
295295

296296
* 3a. The given index is invalid.
297297

298-
* 3a1. AddressBook shows an error message.
298+
* 3a1. TaskTracker shows an error message.
299299

300300
Use case resumes at step 2.
301301

302302
**Use case: Edit a deadline**
303303

304304
1. User requests to list deadlines
305-
2. AddressBook shows a list of deadlines
305+
2. TaskTracker shows a list of deadlines
306306
3. User requests to edit a specific deadline in the list
307-
4. AddressBook updates the specific deadline in the list
307+
4. TaskTracker updates the specific deadline in the list
308308

309309
Use case ends.
310310

@@ -314,55 +314,55 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
314314

315315
Use case ends.
316316
* 3a. The given index is invalid
317-
* 3a1. AddressBook shows an error message.
317+
* 3a1. TaskTracker shows an error message.
318318

319319
Use case resumes at step 2.
320320
* 3b. Optional fields are not provided
321-
* 3b1. AddressBook shows an error message
321+
* 3b1. TaskTracker shows an error message
322322

323323
Use case resumes at step 2.
324324

325325
**Use case: Setting a priority tag**
326326

327327
1. User requests to list deadlines
328-
2. AddressBook shows a list of deadlines**
328+
2. TaskTracker shows a list of deadlines**
329329
3. User requests to set a priority tag on a specific deadline in the list
330-
4. AddressBook sets a priority tag to the specific deadline in the list
330+
4. TaskTracker sets a priority tag to the specific deadline in the list
331331

332332
**Extensions**
333333

334334
* 2a. The list is empty.
335335

336336
Use case ends.
337337
* 3a. The given index is invalid
338-
* 3a1. AddressBook shows an error message
338+
* 3a1. TaskTracker shows an error message
339339

340340
Use case resumes at step 2
341341
* 3b. The given priority tag is invalid
342-
* 3b1. AddressBook shows an error message
342+
* 3b1. TaskTracker shows an error message
343343

344344
Use case resumes at step 2
345345

346346
**Use case: Adding notes to a deadline**
347347

348348
1. User requests to list deadlines
349-
2. AddressBook shows a list of deadlines**
349+
2. TaskTracker shows a list of deadlines**
350350
3. User requests to add a note to a specific deadline in the list
351-
4. AddressBook adds a note to the specific deadline in the list
351+
4. TaskTracker adds a note to the specific deadline in the list
352352

353353
**Extensions**
354354

355355
* 2a. The list is empty.
356356

357357
Use case ends
358358
* 3a. The given index is invalids
359-
* 3a1. AddressBook shows an error message
359+
* 3a1. TaskTracker shows an error message
360360

361361
Use case resumes at step 2
362362
* 3b. The deadline has existing notes
363-
* 3b1. AddressBook requests for confirmation to overwrite previous notes
363+
* 3b1. TaskTracker requests for confirmation to overwrite previous notes
364364
* 3b2. User confirms the request to overwrite previous notes
365-
* 3b3. AddressBook overwrites the previous notes with a new note
365+
* 3b3. TaskTracker overwrites the previous notes with a new note
366366

367367
Use case ends
368368

src/main/java/seedu/address/MainApp.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
import seedu.address.commons.util.StringUtil;
1616
import seedu.address.logic.Logic;
1717
import seedu.address.logic.LogicManager;
18-
import seedu.address.model.AddressBook;
1918
import seedu.address.model.Model;
2019
import seedu.address.model.ModelManager;
2120
import seedu.address.model.ReadOnlyTaskTracker;
2221
import seedu.address.model.ReadOnlyUserPrefs;
22+
import seedu.address.model.TaskTracker;
2323
import seedu.address.model.UserPrefs;
2424
import seedu.address.model.util.SampleDataUtil;
25-
import seedu.address.storage.AddressBookStorage;
26-
import seedu.address.storage.JsonAddressBookStorage;
25+
import seedu.address.storage.JsonTaskTrackerStorage;
2726
import seedu.address.storage.JsonUserPrefsStorage;
2827
import seedu.address.storage.Storage;
2928
import seedu.address.storage.StorageManager;
29+
import seedu.address.storage.TaskTrackerStorage;
3030
import seedu.address.storage.UserPrefsStorage;
3131
import seedu.address.ui.Ui;
3232
import seedu.address.ui.UiManager;
@@ -48,16 +48,16 @@ public class MainApp extends Application {
4848

4949
@Override
5050
public void init() throws Exception {
51-
logger.info("=============================[ Initializing AddressBook ]===========================");
51+
logger.info("=============================[ Initializing TaskTracker ]===========================");
5252
super.init();
5353

5454
AppParameters appParameters = AppParameters.parse(getParameters());
5555
config = initConfig(appParameters.getConfigPath());
5656

5757
UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
5858
UserPrefs userPrefs = initPrefs(userPrefsStorage);
59-
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath());
60-
storage = new StorageManager(addressBookStorage, userPrefsStorage);
59+
TaskTrackerStorage taskTrackerStorage = new JsonTaskTrackerStorage(userPrefs.getTaskTrackerFilePath());
60+
storage = new StorageManager(taskTrackerStorage, userPrefsStorage);
6161

6262
initLogging(config);
6363

@@ -74,20 +74,22 @@ public void init() throws Exception {
7474
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
7575
*/
7676
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
77-
Optional<ReadOnlyTaskTracker> addressBookOptional;
77+
78+
Optional<ReadOnlyTaskTracker> taskTrackerOptional;
79+
7880
ReadOnlyTaskTracker initialData;
7981
try {
80-
addressBookOptional = storage.readAddressBook();
81-
if (!addressBookOptional.isPresent()) {
82-
logger.info("Data file not found. Will be starting with a sample AddressBook");
82+
taskTrackerOptional = storage.readTaskTracker();
83+
if (!taskTrackerOptional.isPresent()) {
84+
logger.info("Data file not found. Will be starting with a sample TaskTracker");
8385
}
84-
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
86+
initialData = taskTrackerOptional.orElseGet(SampleDataUtil::getSampleTaskTracker);
8587
} catch (DataConversionException e) {
86-
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
87-
initialData = new AddressBook();
88+
logger.warning("Data file not in the correct format. Will be starting with an empty TaskTracker");
89+
initialData = new TaskTracker();
8890
} catch (IOException e) {
89-
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
90-
initialData = new AddressBook();
91+
logger.warning("Problem while reading from the file. Will be starting with an empty TaskTracker");
92+
initialData = new TaskTracker();
9193
}
9294

9395
return new ModelManager(initialData, userPrefs);
@@ -151,7 +153,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
151153
+ "Using default user prefs");
152154
initializedPrefs = new UserPrefs();
153155
} catch (IOException e) {
154-
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
156+
logger.warning("Problem while reading from the file. Will be starting with an empty TaskTracker");
155157
initializedPrefs = new UserPrefs();
156158
}
157159

@@ -167,13 +169,13 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
167169

168170
@Override
169171
public void start(Stage primaryStage) {
170-
logger.info("Starting AddressBook " + MainApp.VERSION);
172+
logger.info("Starting TaskTracker " + MainApp.VERSION);
171173
ui.start(primaryStage);
172174
}
173175

174176
@Override
175177
public void stop() {
176-
logger.info("============================ [ Stopping Address Book ] =============================");
178+
logger.info("============================ [ Stopping Task Tracker ] =============================");
177179
try {
178180
storage.saveUserPrefs(model.getUserPrefs());
179181
} catch (IOException e) {

src/main/java/seedu/address/logic/Logic.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@
1616
public interface Logic {
1717
/**
1818
* Executes the command and returns the result.
19+
*
1920
* @param commandText The command as entered by the user.
2021
* @return the result of the command execution.
2122
* @throws CommandException If an error occurs during command execution.
22-
* @throws ParseException If an error occurs during parsing.
23+
* @throws ParseException If an error occurs during parsing.
2324
*/
2425
CommandResult execute(String commandText) throws CommandException, ParseException;
2526

2627
/**
27-
* Returns the AddressBook.
28+
* Returns the TaskTracker.
2829
*
29-
* @see seedu.address.model.Model#getAddressBook()
30+
* @see seedu.address.model.Model#getTaskTracker()
3031
*/
31-
ReadOnlyTaskTracker getAddressBook();
3232

33-
/** Returns an unmodifiable view of the filtered list of persons */
33+
ReadOnlyTaskTracker getTaskTracker();
34+
35+
36+
/**
37+
* Returns an unmodifiable view of the filtered list of persons
38+
*/
3439
ObservableList<Person> getFilteredPersonList();
3540

3641
/**
3742
* Returns the user prefs' address book file path.
3843
*/
39-
Path getAddressBookFilePath();
44+
Path getTaskTrackerFilePath();
4045

4146
/**
4247
* Returns the user prefs' GUI settings.

0 commit comments

Comments
 (0)