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][W10-B4]Goh Yue Quan #432

Closed
wants to merge 4 commits into from
Closed
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
14 changes: 8 additions & 6 deletions src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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 seedu.addressbook.storage.Storage.InvalidStoragePathException;

import java.util.Collections;
import java.util.List;
Expand All @@ -17,7 +19,7 @@
public class Logic {


private StorageFile storage;
private Storage storage;
private AddressBook addressBook;

/** The list of person shown to the user most recently. */
Expand All @@ -28,12 +30,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;
}

Expand All @@ -45,11 +47,11 @@ void setAddressBook(AddressBook addressBook){
* Creates the StorageFile 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 InvalidStoragePathException {
return new StorageFile();
Copy link

Choose a reason for hiding this comment

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

👍 Good attempt at 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

}

public String getStorageFilePath() {
public String getStoragePath() {
return storage.getPath();
}

Expand Down
33 changes: 33 additions & 0 deletions src/seedu/addressbook/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.addressbook.storage;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.exception.IllegalValueException;

public abstract class Storage {

/**
* 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);
}
}
Copy link

Choose a reason for hiding this comment

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

👍


/**
* 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);
}
}

public abstract void save(AddressBook addressBook) throws StorageOperationException;
Copy link

Choose a reason for hiding this comment

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

👍


public abstract AddressBook load() throws StorageOperationException;

public abstract String getPath();

}
27 changes: 4 additions & 23 deletions 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 All @@ -24,40 +24,21 @@ public class StorageFile {
* More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
*/

/**
* Signals that the given file path does not fulfill the storage filepath constraints.
*/
public static class InvalidStorageFilePathException extends IllegalValueException {
public InvalidStorageFilePathException(String message) {
super(message);
}
}

/**
* 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);
}
}

private final JAXBContext jaxbContext;

public final Path path;

/**
* @throws InvalidStorageFilePathException if the default path is invalid
*/
public StorageFile() throws InvalidStorageFilePathException {
public StorageFile() throws InvalidStoragePathException {
this(DEFAULT_STORAGE_FILEPATH);
}

/**
* @throws InvalidStorageFilePathException if the given file path is invalid
*/
public StorageFile(String filePath) throws InvalidStorageFilePathException {
public StorageFile(String filePath) throws InvalidStoragePathException {
try {
jaxbContext = JAXBContext.newInstance(AdaptedAddressBook.class);
} catch (JAXBException jaxbe) {
Expand All @@ -66,7 +47,7 @@ public StorageFile(String filePath) throws InvalidStorageFilePathException {

path = Paths.get(filePath);
if (!isValidPath(path)) {
throw new InvalidStorageFilePathException("Storage file should end with '.txt'");
throw new InvalidStoragePathException("Storage file should end with '.txt'");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/ui/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}

.text-area {
-fx-background-color: black;
-fx-control-inner-background: black;
-fx-background-color: #8B4513;
-fx-control-inner-background: #8B4513;
-fx-font-family: "Segoe UI Semibold";
-fx-font-size: 10pt;
-fx-padding: 5 5 5 5;
Expand Down
Binary file added src/seedu/addressbook/ui/newBackground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.storage.StorageFile;

import java.util.*;

Expand All @@ -28,16 +27,16 @@ public class LogicTest {
@Rule
public TemporaryFolder saveFolder = new TemporaryFolder();

private StorageFile saveFile;
private StorageStub storageStub;
private AddressBook addressBook;
private Logic logic;

@Before
public void setup() throws Exception {
saveFile = new StorageFile(saveFolder.newFile("testSaveFile.txt").getPath());
storageStub = new StorageStub();
addressBook = new AddressBook();
saveFile.save(addressBook);
logic = new Logic(saveFile, addressBook);
storageStub.save(addressBook);
logic = new Logic(storageStub, addressBook);
}

@Test
Expand Down Expand Up @@ -90,7 +89,7 @@ private void assertCommandBehavior(String inputCommand,
//Confirm the state of data is as expected
assertEquals(expectedAddressBook, addressBook);
assertEquals(lastShownList, logic.getLastShownList());
assertEquals(addressBook, saveFile.load());
assertEquals(null, storageStub.load());
Copy link

@hwkchia hwkchia Mar 7, 2017

Choose a reason for hiding this comment

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

👍 You are the only one to have identified this. You can simply just remove the line 😄

}


Expand Down
24 changes: 24 additions & 0 deletions test/java/seedu/addressbook/logic/StorageStub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.addressbook.logic;

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

public class StorageStub extends Storage {

@Override
public AddressBook load() throws StorageOperationException {
return null;
}

@Override
public String getPath() {
return null;
}

@Override
public void save(AddressBook addressBook) throws StorageOperationException {

}

}
Copy link

Choose a reason for hiding this comment

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

👍 Very nice. Minimalist and in the correct directory. ⭐️

2 changes: 1 addition & 1 deletion test/java/seedu/addressbook/storage/StorageFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import seedu.addressbook.data.person.Phone;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.storage.StorageFile.StorageOperationException;
import seedu.addressbook.storage.Storage.StorageOperationException;
import static seedu.addressbook.util.TestUtil.assertTextFilesEqual;

public class StorageFileTest {
Expand Down