Skip to content

Commit

Permalink
Refactor address book to loan book (#115)
Browse files Browse the repository at this point in the history
* Update README, including changing the app's name and its introduction

* Add LoanRate class

* Correct the checkstyle error

* Correct checkstyle errors in LoanRateTest

* Add a new line in LoanRateTest

* Add a new line in LoanRate class

* Update LoanRate class

* Change the regex of rate and add some test cases

* Change the type of rate from String to double

* Correct checkstyle errors

* Update LoanRate class

* Correct checkstyle error

* Correct checkstyle errors

* Add config.json

* . (#2)

* Refactor LoanTime to extend DataField class (#73)

* Add Irham's picture

* Change title to Loanbook App

* Refactor LoanTime to extend DataField class

* Edit documentation of LoanTime methods

* Remove unnecessary import statement from LoanTimeTest

* Fix style check violations in LoanTime and LoanTimeTest

* Fix test in LoanTimeTest

* Modify loanTimeDifferenceMinutes method in LoanTime to use static method

* Add LoanRate class (#29)

* Update README, including changing the app's name and its introduction

* Add LoanRate class

* Correct the checkstyle error

* Correct checkstyle errors in LoanRateTest

* Add a new line in LoanRateTest

* Add a new line in LoanRate class

* Update LoanRate class

* Change the regex of rate and add some test cases

* Change the type of rate from String to double

* Correct checkstyle errors

* Update LoanRate class

* Correct checkstyle error

* Correct checkstyle errors

* Add a new line at EOF

* Replace "address" by "loan" that won't affect other parts of the project in logic

* Replace "address" by "loan" that won't affect other parts of the project in common

* Replace "address" by "loan" that won't affect other parts of the project in model

* Replace "address" by "loan" that won't affect other parts of the project in storage

* Replace "address" by "loan" that won't affect other parts of the project in MainApp

* Refactor AddressBook class to LoanBook

* Refactor VersionedAddressBook class to VersionedLoanBook

* Refactor ReadOnlyAddressBook class to ReadOnlyLoanBook

* Refactor "address" to "loan" in model folder and model test

* Replace all "address" to "loan" in logic folder and logic tests

* Replace "address" by "loan" in common and ui, but some parts involving storage are left

* Refactor all the files and tests about Storage

* Refactor "address" to "loan"

* Fix CheckStyle Errors

* Fix CheckStyle Error

* Fix a missing change
  • Loading branch information
Kelly9373 committed Oct 20, 2018
1 parent b25262e commit 75e70af
Show file tree
Hide file tree
Showing 91 changed files with 1,234 additions and 1,233 deletions.
46 changes: 23 additions & 23 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.LoanBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyLoanBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.LoanBookStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.storage.XmlAddressBookStorage;
import seedu.address.storage.XmlLoanBookStorage;
import seedu.address.ui.Ui;
import seedu.address.ui.UiManager;

Expand All @@ -54,16 +54,16 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing LoanBook ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
userPrefs = initPrefs(userPrefsStorage);
AddressBookStorage addressBookStorage = new XmlAddressBookStorage(userPrefs.getAddressBookFilePath());
storage = new StorageManager(addressBookStorage, userPrefsStorage);
LoanBookStorage loanBookStorage = new XmlLoanBookStorage(userPrefs.getLoanBookFilePath());
storage = new StorageManager(loanBookStorage, userPrefsStorage);

initLogging(config);

Expand All @@ -77,25 +77,25 @@ public void init() throws Exception {
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
* Returns a {@code ModelManager} with the data from {@code storage}'s loan book and {@code userPrefs}. <br>
* The data from the sample loan book will be used instead if {@code storage}'s loan book is not found,
* or an empty loan book will be used instead if errors occur when reading {@code storage}'s loan book.
*/
private Model initModelManager(Storage storage, UserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyLoanBook> loanBookOptional;
ReadOnlyLoanBook initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
loanBookOptional = storage.readLoanBook();
if (!loanBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample LoanBook");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialData = loanBookOptional.orElseGet(SampleDataUtil::getSampleLoanBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty LoanBook");
initialData = new LoanBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Problem while reading from the file. Will be starting with an empty LoanBook");
initialData = new LoanBook();
}

return new ModelManager(initialData, userPrefs);
Expand Down Expand Up @@ -159,7 +159,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from the file. Will be starting with an empty LoanBook");
initializedPrefs = new UserPrefs();
}

Expand All @@ -179,13 +179,13 @@ private void initEventsCenter() {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting LoanBook " + MainApp.VERSION);
ui.start(primaryStage);
}

@Override
public void stop() {
logger.info("============================ [ Stopping Address Book ] =============================");
logger.info("============================ [ Stopping Loan Book ] =============================");
ui.stop();
try {
storage.saveUserPrefs(userPrefs);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class LogsCenter {
private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
private static final String LOG_FILE = "loanbook.log";
private static Level currentLogLevel = Level.INFO;
private static final Logger logger = LogsCenter.getLogger(LogsCenter.class);
private static FileHandler fileHandler;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package seedu.address.commons.events.model;

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.ReadOnlyLoanBook;

/** Indicates the LoanBook in the model has changed*/
public class LoanBookChangedEvent extends BaseEvent {

public final ReadOnlyLoanBook data;

public LoanBookChangedEvent(ReadOnlyLoanBook data) {
this.data = data;
}

@Override
public String toString() {
return "number of loans " + data.getLoanList().size();
}
}
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.LoanBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.loan.Loan;
Expand All @@ -21,19 +21,19 @@ public class LogicManager extends ComponentManager implements Logic {

private final Model model;
private final CommandHistory history;
private final AddressBookParser addressBookParser;
private final LoanBookParser loanBookParser;

public LogicManager(Model model) {
this.model = model;
history = new CommandHistory();
addressBookParser = new AddressBookParser();
loanBookParser = new LoanBookParser();
}

@Override
public CommandResult execute(String commandText) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");
try {
Command command = addressBookParser.parseCommand(commandText);
Command command = loanBookParser.parseCommand(commandText);
return command.execute(model, history);
} finally {
history.add(commandText);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import seedu.address.model.loan.Loan;

/**
* Adds a loan to the address book.
* Adds a loan to the loan book.
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a loan to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a loan to the loan book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
Expand All @@ -35,7 +35,7 @@ public class AddCommand extends Command {
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "New loan added: %1$s";
public static final String MESSAGE_DUPLICATE_LOAN = "This loan already exists in the address book";
public static final String MESSAGE_DUPLICATE_LOAN = "This loan already exists in the loan book";

private final Loan toAdd;

Expand All @@ -56,7 +56,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

model.addLoan(toAdd);
model.commitAddressBook();
model.commitLoanBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import static java.util.Objects.requireNonNull;

import seedu.address.logic.CommandHistory;
import seedu.address.model.AddressBook;
import seedu.address.model.LoanBook;
import seedu.address.model.Model;

/**
* Clears the address book.
* Clears the loan book.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_SUCCESS = "Loan book has been cleared!";


@Override
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.resetData(new AddressBook());
model.commitAddressBook();
model.resetData(new LoanBook());
model.commitLoanBook();
return new CommandResult(MESSAGE_SUCCESS);
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import seedu.address.model.loan.Loan;

/**
* Deletes a loan identified using it's displayed index from the address book.
* Deletes a loan identified using it's displayed index from the loan book.
*/
public class DeleteCommand extends Command {

Expand Down Expand Up @@ -45,7 +45,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

Loan loanToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteLoan(loanToDelete);
model.commitAddressBook();
model.commitLoanBook();
return new CommandResult(String.format(MESSAGE_DELETE_LOAN_SUCCESS, loanToDelete));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing loan in the address book.
* Edits the details of an existing loan in the loan book.
*/
public class EditCommand extends Command {

Expand All @@ -49,7 +49,7 @@ public class EditCommand extends Command {

public static final String MESSAGE_EDIT_LOAN_SUCCESS = "Edited Loan: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_LOAN = "This loan already exists in the address book.";
public static final String MESSAGE_DUPLICATE_LOAN = "This loan already exists in the loan book.";

private final Index index;
private final EditLoanDescriptor editLoanDescriptor;
Expand Down Expand Up @@ -84,7 +84,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

model.updateLoan(loanToEdit, editedLoan);
model.updateFilteredLoanList(PREDICATE_SHOW_ALL_LOANS);
model.commitAddressBook();
model.commitLoanBook();
return new CommandResult(String.format(MESSAGE_EDIT_LOAN_SUCCESS, editedLoan));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";
public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Loan Book as requested ...";

@Override
public CommandResult execute(Model model, CommandHistory history) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.model.loan.NameContainsKeywordsPredicate;

/**
* Finds and lists all loans in address book whose name contains any of the argument keywords.
* Finds and lists all loans in loan book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class FindCommand extends Command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.model.Model;

/**
* Lists all loans in the address book to the user.
* Lists all loans in the loan book to the user.
*/
public class ListCommand extends Command {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.model.Model;

/**
* Reverts the {@code model}'s address book to its previously undone state.
* Reverts the {@code model}'s loan book to its previously undone state.
*/
public class RedoCommand extends Command {

Expand All @@ -20,11 +20,11 @@ public class RedoCommand extends Command {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

if (!model.canRedoAddressBook()) {
if (!model.canRedoLoanBook()) {
throw new CommandException(MESSAGE_FAILURE);
}

model.redoAddressBook();
model.redoLoanBook();
model.updateFilteredLoanList(PREDICATE_SHOW_ALL_LOANS);
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import seedu.address.model.loan.Loan;

/**
* Selects a loan identified using it's displayed index from the address book.
* Selects a loan identified using it's displayed index from the loan book.
*/
public class SelectCommand extends Command {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.model.Model;

/**
* Reverts the {@code model}'s address book to its previous state.
* Reverts the {@code model}'s loan book to its previous state.
*/
public class UndoCommand extends Command {

Expand All @@ -20,11 +20,11 @@ public class UndoCommand extends Command {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);

if (!model.canUndoAddressBook()) {
if (!model.canUndoLoanBook()) {
throw new CommandException(MESSAGE_FAILURE);
}

model.undoAddressBook();
model.undoLoanBook();
model.updateFilteredLoanList(PREDICATE_SHOW_ALL_LOANS);
return new CommandResult(MESSAGE_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Parses user input.
*/
public class AddressBookParser {
public class LoanBookParser {

/**
* Used for initial separation of command word and args.
Expand Down
Loading

0 comments on commit 75e70af

Please sign in to comment.