From 4572d05fe70517c09bf5fe2c5084c8b55f9ffa98 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 09:47:43 +0800 Subject: [PATCH 1/8] Create abstract class storage --- src/seedu/addressbook/storage/Storage.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/seedu/addressbook/storage/Storage.java diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java new file mode 100644 index 000000000..a23e4a1b5 --- /dev/null +++ b/src/seedu/addressbook/storage/Storage.java @@ -0,0 +1,5 @@ +package seedu.addressbook.storage; + +public abstract class Storage { + +} From 1a09752aba7c11548219b0f510dc6893316a346a Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 09:56:56 +0800 Subject: [PATCH 2/8] Add StorageFile to extend Storage --- src/seedu/addressbook/storage/StorageFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 693097a86..5a3ab661c 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -15,7 +15,7 @@ /** * Represents the file used to store address book data. */ -public class StorageFile { +public class StorageFile extends Storage { /** Default file path used if the user doesn't provide the file name. */ public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt"; From 00149b617f2ab081d39d9980e4b523ed05a7ae37 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 10:03:59 +0800 Subject: [PATCH 3/8] Add abstract methods --- src/seedu/addressbook/logic/Logic.java | 3 ++- src/seedu/addressbook/storage/Storage.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 17afd61a0..30d86334c 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -5,6 +5,7 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.data.person.ReadOnlyPerson; import seedu.addressbook.parser.Parser; +import seedu.addressbook.storage.Storage; import seedu.addressbook.storage.StorageFile; import java.util.Collections; @@ -17,7 +18,7 @@ public class Logic { - private StorageFile storage; + private Storage storage; private AddressBook addressBook; /** The list of person shown to the user most recently. */ diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java index a23e4a1b5..b0b9fa3ef 100644 --- a/src/seedu/addressbook/storage/Storage.java +++ b/src/seedu/addressbook/storage/Storage.java @@ -1,5 +1,10 @@ package seedu.addressbook.storage; -public abstract class Storage { +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.storage.StorageFile.StorageOperationException; +public abstract class Storage { + public abstract AddressBook load() throws StorageOperationException; + public abstract void save(AddressBook addressBook) throws StorageOperationException; + public abstract String getPath(); } From 1efd0d2cba91f0586177aa2b0d248465272d0839 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 10:32:48 +0800 Subject: [PATCH 4/8] Replace StorageFile with Storage in Logic.java --- src/seedu/addressbook/logic/Logic.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 30d86334c..400869c82 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -29,12 +29,12 @@ public Logic() throws Exception{ setAddressBook(storage.load()); } - Logic(StorageFile storageFile, AddressBook addressBook){ - setStorage(storageFile); + Logic(Storage storage, AddressBook addressBook){ + setStorage(storage); setAddressBook(addressBook); } - void setStorage(StorageFile storage){ + void setStorage(Storage storage){ this.storage = storage; } @@ -43,14 +43,14 @@ void setAddressBook(AddressBook addressBook){ } /** - * Creates the StorageFile object based on the user specified path (if any) or the default storage path. + * Creates the Storage object based on the user specified path (if any) or the default storage path. * @throws StorageFile.InvalidStorageFilePathException if the target file path is incorrect. */ - private StorageFile initializeStorage() throws StorageFile.InvalidStorageFilePathException { + private Storage initializeStorage() throws StorageFile.InvalidStorageFilePathException { return new StorageFile(); } - public String getStorageFilePath() { + public String getStoragePath() { return storage.getPath(); } From d92b826f79cc5593068ee3d79f5b24946166cd59 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 10:43:00 +0800 Subject: [PATCH 5/8] Add header comment to Storage.java --- src/seedu/addressbook/storage/Storage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java index b0b9fa3ef..a5c706eec 100644 --- a/src/seedu/addressbook/storage/Storage.java +++ b/src/seedu/addressbook/storage/Storage.java @@ -3,6 +3,9 @@ import seedu.addressbook.data.AddressBook; import seedu.addressbook.storage.StorageFile.StorageOperationException; +/** + * Represents the file used to store address book data. + */ public abstract class Storage { public abstract AddressBook load() throws StorageOperationException; public abstract void save(AddressBook addressBook) throws StorageOperationException; From 98749de1b344397457cab37f06724163effb5d41 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 10:43:17 +0800 Subject: [PATCH 6/8] Modify Gui method call --- src/seedu/addressbook/ui/Gui.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seedu/addressbook/ui/Gui.java b/src/seedu/addressbook/ui/Gui.java index ed21989a4..396120b8f 100644 --- a/src/seedu/addressbook/ui/Gui.java +++ b/src/seedu/addressbook/ui/Gui.java @@ -31,7 +31,7 @@ public Gui(Logic logic, String version) { public void start(Stage stage, Stoppable mainApp) throws IOException { mainWindow = createMainWindow(stage, mainApp); - mainWindow.displayWelcomeMessage(version, logic.getStorageFilePath()); + mainWindow.displayWelcomeMessage(version, logic.getStoragePath()); } private MainWindow createMainWindow(Stage stage, Stoppable mainApp) throws IOException{ From 033f0c99b51a3806197ecd71a0ed14edc7790f36 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 11:11:33 +0800 Subject: [PATCH 7/8] Create StorageStub --- .../addressbook/storage/StorageStub.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/seedu/addressbook/storage/StorageStub.java diff --git a/src/seedu/addressbook/storage/StorageStub.java b/src/seedu/addressbook/storage/StorageStub.java new file mode 100644 index 000000000..ce942532b --- /dev/null +++ b/src/seedu/addressbook/storage/StorageStub.java @@ -0,0 +1,29 @@ +package seedu.addressbook.storage; + +import seedu.addressbook.data.AddressBook; +import seedu.addressbook.storage.StorageFile.StorageOperationException; + +public class StorageStub extends Storage { + + private String path; + + public StorageStub(String path) { + this.path = path; + } + + @Override + public void save(AddressBook addressBook) throws StorageOperationException { + return; + } + + @Override + public AddressBook load() throws StorageOperationException { + return null; + } + + @Override + public String getPath() { + return path; + } + +} From 64c222a356c3a0730ffa70647a3ce445eb716176 Mon Sep 17 00:00:00 2001 From: Chengcheng Li Date: Sun, 5 Mar 2017 11:14:21 +0800 Subject: [PATCH 8/8] modify LogicTest to Use StorageStub --- src/seedu/addressbook/logic/Logic.java | 2 +- test/java/seedu/addressbook/logic/LogicTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 400869c82..abe862458 100644 --- a/src/seedu/addressbook/logic/Logic.java +++ b/src/seedu/addressbook/logic/Logic.java @@ -47,7 +47,7 @@ void setAddressBook(AddressBook addressBook){ * @throws StorageFile.InvalidStorageFilePathException if the target file path is incorrect. */ private Storage initializeStorage() throws StorageFile.InvalidStorageFilePathException { - return new StorageFile(); + return new StorageFile();//I'm not sure how to get rid of this coupling } public String getStoragePath() { diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 7efa921ca..9127251f3 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -12,7 +12,7 @@ import seedu.addressbook.data.person.*; import seedu.addressbook.data.tag.Tag; import seedu.addressbook.data.tag.UniqueTagList; -import seedu.addressbook.storage.StorageFile; +import seedu.addressbook.storage.StorageStub; import java.util.*; @@ -28,13 +28,13 @@ public class LogicTest { @Rule public TemporaryFolder saveFolder = new TemporaryFolder(); - private StorageFile saveFile; + private StorageStub saveFile; private AddressBook addressBook; private Logic logic; @Before public void setup() throws Exception { - saveFile = new StorageFile(saveFolder.newFile("testSaveFile.txt").getPath()); + saveFile = new StorageStub(saveFolder.newFile("testSaveFile.txt").getPath()); addressBook = new AddressBook(); saveFile.save(addressBook); logic = new Logic(saveFile, addressBook);