diff --git a/src/seedu/addressbook/logic/Logic.java b/src/seedu/addressbook/logic/Logic.java index 17afd61a0..abe862458 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. */ @@ -28,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; } @@ -42,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 { - return new StorageFile(); + private Storage initializeStorage() throws StorageFile.InvalidStorageFilePathException { + return new StorageFile();//I'm not sure how to get rid of this coupling } - public String getStorageFilePath() { + public String getStoragePath() { return storage.getPath(); } diff --git a/src/seedu/addressbook/storage/Storage.java b/src/seedu/addressbook/storage/Storage.java new file mode 100644 index 000000000..a5c706eec --- /dev/null +++ b/src/seedu/addressbook/storage/Storage.java @@ -0,0 +1,13 @@ +package seedu.addressbook.storage; + +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; + public abstract String getPath(); +} 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"; 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; + } + +} 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{ 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);