Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T6A1][F12-B1]Wang Si Qi #493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. */
Expand Down
18 changes: 18 additions & 0 deletions src/seedu/addressbook/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.addressbook.storage;

import java.nio.file.Path;

import javax.xml.bind.JAXBContext;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.storage.StorageFile.StorageOperationException;

public abstract class Storage {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do remember to include header comments.
Refer to the coding standard provided in the handbook.



public abstract void save(AddressBook addressBook) throws StorageOperationException;

public abstract AddressBook load() throws StorageOperationException;

public abstract String getPath();
}
5 changes: 4 additions & 1 deletion src/seedu/addressbook/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -83,6 +83,7 @@ private static boolean isValidPath(Path filePath) {
*
* @throws StorageOperationException if there were errors converting and/or storing data to file.
*/
@Override
public void save(AddressBook addressBook) throws StorageOperationException {

/* Note: Note the 'try with resource' statement below.
Expand All @@ -108,6 +109,7 @@ public void save(AddressBook addressBook) throws StorageOperationException {
*
* @throws StorageOperationException if there were errors reading and/or converting data from file.
*/
@Override
public AddressBook load() throws StorageOperationException {
try (final Reader fileReader =
new BufferedReader(new FileReader(path.toFile()))) {
Expand Down Expand Up @@ -141,6 +143,7 @@ public AddressBook load() throws StorageOperationException {
}
}

@Override
public String getPath() {
return path.toString();
}
Expand Down