-
Notifications
You must be signed in to change notification settings - Fork 163
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][W10-B3] Chen Penghao #358
base: master
Are you sure you want to change the base?
Changes from all commits
01e9339
d02def6
160f35d
fd73a2c
ccddf0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package seedu.addressbook.storage; | ||
|
||
import java.nio.file.Path; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.storage.Storage.StorageOperationException; | ||
|
||
public abstract class Storage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header comment? |
||
|
||
/** | ||
* Signals that the given file path does not fulfill the storage filepath constraints. | ||
*/ | ||
public static class InvalidStoragePathException extends IllegalValueException { | ||
public InvalidStoragePathException(String message) { | ||
super(message); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/** | ||
* Signals that some error has occured while trying to convert and read/write data between the application | ||
* and the storage file. | ||
*/ | ||
public static class StorageOperationException extends Exception { | ||
public StorageOperationException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
public abstract AddressBook load() throws StorageOperationException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
public abstract void save(AddressBook addressBook) throws StorageOperationException; | ||
|
||
public abstract String getPath(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package seedu.addressbook.storage; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.storage.Storage.InvalidStoragePathException; | ||
import seedu.addressbook.storage.jaxb.AdaptedAddressBook; | ||
|
||
public class StorageStub extends Storage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You should also place |
||
|
||
/** Default file path used if the user doesn't provide the file name. */ | ||
public final static String DEFAULT_STORAGE_FILEPATH = "addressbook.txt"; | ||
|
||
/* Note: Note the use of nested classes below. | ||
* More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html | ||
*/ | ||
private final JAXBContext jaxbContext; | ||
|
||
|
||
public final Path path; | ||
public StorageStub() throws InvalidStoragePathException { | ||
this(DEFAULT_STORAGE_FILEPATH); | ||
} | ||
|
||
/** | ||
* @throws InvalidStorageFilePathException if the given file path is invalid | ||
*/ | ||
public StorageStub(String filePath) throws InvalidStoragePathException { | ||
try { | ||
jaxbContext = JAXBContext.newInstance(AdaptedAddressBook.class); | ||
} catch (JAXBException jaxbe) { | ||
throw new RuntimeException("jaxb initialisation error"); | ||
} | ||
|
||
path = Paths.get(filePath); | ||
if (!isValidPath(path)) { | ||
throw new InvalidStoragePathException("Storage file should end with '.txt'"); | ||
} | ||
} | ||
|
||
private boolean isValidPath(Path filePath) { | ||
return filePath.toString().endsWith(".txt"); | ||
} | ||
|
||
@Override | ||
public AddressBook load() throws StorageOperationException { | ||
// TODO Auto-generated method stub | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
@Override | ||
public void save(AddressBook addressBook) throws StorageOperationException { | ||
return; | ||
|
||
} | ||
|
||
@Override | ||
public String getPath() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 applying DIP.
The creating of
StorageFile
is a little unfortunate, but nonetheless has to be done. The original design already violates OCP. Fyi, an issue has been raised regarding this se-edu/addressbook-level3#75