Skip to content

Commit

Permalink
Style changes for checkstyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParasK26 committed Oct 31, 2018
1 parent f73e5ce commit bfabdc4
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.saleshistory.ReadOnlySalesHistory;
import seedu.address.model.saleshistory.SalesHistory;

/**
* Indicates a change in the {@link SalesHistory}
*/
public class SalesHistoryChangedEvent extends BaseEvent {

public final ReadOnlySalesHistory data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public LoginCommand(Username username, Password password) {
this.username = username;
this.password = password;
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(username);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,15 @@ private void reloadAddressBook(Username username) {
}

/**
* Updates the sales history and its storage path using the {@code username} provided.
* @param username
* Reloads the sales history
*/
private void reloadSalesHistory(Username username) {
private void reloadSalesHistory() {
Optional<ReadOnlySalesHistory> salesHistoryOptional;
ReadOnlySalesHistory newSalesHistory;

try {
salesHistoryOptional = storage.readSalesHistory();
if(!salesHistoryOptional.isPresent()) {
if (!salesHistoryOptional.isPresent()) {
logger.info("Data file not found. Will be starting with an empty SalesHistory");
}
newSalesHistory = salesHistoryOptional.orElseGet(SampleDataUtil::getSampleSalesHistory);
Expand Down Expand Up @@ -272,8 +271,9 @@ public synchronized void addUser(User person) throws DuplicateUserException {
public boolean checkAuthentication(Username username, Password password) throws AuthenticatedException {
boolean result = versionedUserDatabase.checkAuthentication(username, password);
if (hasLoggedIn() && result) {
storage.update(versionedUserDatabase.getUser(username));
reloadAddressBook(username);
reloadSalesHistory(username);
reloadSalesHistory();
reloadDistributorBook(username);
}
return result;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/model/ProductDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javafx.collections.ObservableList;

import seedu.address.model.product.Product;
import seedu.address.model.product.UniquePersonList;
import seedu.address.model.saleshistory.SalesHistory;
import seedu.address.model.timeidentifiedclass.TimeIdentifiedClass;
import seedu.address.model.timeidentifiedclass.exceptions.InvalidTimeFormatException;

/**
* Wraps all data at the address-book level
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UserPrefs {
private Path addressBookFilePath = Paths.get("data" , "addressbook.xml");
private Path distributorBookFilePath = Paths.get("data", "distributorbook.xml");
private Path usersFilePath = Paths.get("data", "users.xml");
private Path salesHistoryFilePath = Paths.get("data","saleshistory.xml");
private Path salesHistoryFilePath = Paths.get("data", "saleshistory.xml");

public UserPrefs() {
setGuiSettings(750, 500, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/product/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Set<Tag> getTags() {
* This defines a weaker notion of equality between two persons.
*/
public boolean isSameProduct(Product otherProduct) {
if (otherProduct.getSerialNumber() == this.getSerialNumber() ) {
if (otherProduct.getSerialNumber() == this.getSerialNumber()) {
return true;
}

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/seedu/address/model/saleshistory/SalesHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.Set;
import java.util.TreeMap;


import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import seedu.address.model.timeidentifiedclass.Reminder;
import seedu.address.model.timeidentifiedclass.TimeIdentifiedClass;
import seedu.address.model.timeidentifiedclass.Transaction;
Expand Down Expand Up @@ -72,9 +72,13 @@ public SalesHistory(ReadOnlySalesHistory toBeCopied) {
copyReadOnlySalesHistory(toBeCopied);
}

/**
* Copies the {@code toBeCopied} to the {@code SalesHistory}
* @param toBeCopied
*/
private void copyReadOnlySalesHistory(ReadOnlySalesHistory toBeCopied) {
for (Transaction transaction : toBeCopied.getTransactionsAsObservableList()) {
// These exceptions should never be raised. Printing the stack trace will help debugging.
// These exceptions should never be thrown. Printing the stack trace will help debugging.
try {
addTransaction(transaction);
} catch (InvalidTimeFormatException e) {
Expand All @@ -84,7 +88,7 @@ private void copyReadOnlySalesHistory(ReadOnlySalesHistory toBeCopied) {
}
}
for (Reminder reminder : toBeCopied.getRemindersAsObservableList()) {
// These exceptions should never be raised. Printing the stack trace will help debugging.
// These exceptions should never be thrown. Printing the stack trace will help debugging.
try {
addReminder(reminder);
} catch (InvalidTimeFormatException e) {
Expand Down Expand Up @@ -186,6 +190,10 @@ public void removeReminder(String reminderTime) throws InvalidTimeFormatExceptio
reminderObservableList.remove(toRemove);
}

/**
* Resets the {@code SalesHistory} according to a {@code ReadOnlySalesHistory} object
* @param src
*/
public void resetData(ReadOnlySalesHistory src) {
transactionRecord.clear();
reminderRecord.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class SalesHistoryManager extends SalesHistory {
*/
public SalesHistoryManager(ReadOnlySalesHistory initialState) {
super(initialState);
if (getTransactionRecord().size() > 0) {
lastTransaction = getTransactionRecord().lastEntry().getValue();
}
}

/**
Expand Down Expand Up @@ -77,7 +74,7 @@ public String getDaysTransactionsAsString(String day) throws InvalidTimeFormatEx
}

public Transaction getLastTransaction() {
return lastTransaction;
return getTransactionRecord().lastEntry().getValue();
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
import seedu.address.model.saleshistory.ReadOnlySalesHistory;
import seedu.address.model.saleshistory.SalesHistory;
import seedu.address.model.tag.Tag;
import seedu.address.model.timeidentifiedclass.Transaction;
import seedu.address.model.timeidentifiedclass.exceptions.ClosedTransactionException;
import seedu.address.model.timeidentifiedclass.exceptions.DuplicateTransactionException;
import seedu.address.model.timeidentifiedclass.exceptions.InvalidTimeFormatException;

/**
* Contains utility methods for populating {@code ProductDatabase} with sample data.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@ public void saveSalesHistory(ReadOnlySalesHistory salesHistory) throws IOExcepti
salesHistoryStorage.saveSalesHistory(salesHistory, salesHistoryStorage.getSalesHistoryFilePath());
}

@Override
public void deleteSalesHistory() throws IOException {
salesHistoryStorage.deleteSalesHistory();
}

@Override
public void saveSalesHistory(ReadOnlySalesHistory salesHistory, Path filePath) throws IOException {
logger.fine("Attempting to write to data file: " + filePath);
salesHistoryStorage.saveSalesHistory(salesHistory, filePath);
}

@Override
public void deleteSalesHistory() throws IOException {
salesHistoryStorage.deleteSalesHistory();
}

@Override
@Subscribe
public void handleSalesHistoryChangedEvent(SalesHistoryChangedEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.commons.util.FileUtil;
import seedu.address.model.saleshistory.ReadOnlySalesHistory;
import seedu.address.model.saleshistory.SalesHistory;

/**
* A class to access and modify {@link SalesHistory} stored on the hard disk in xml form.
*/
public class XmlSalesHistoryStorage implements SalesHistoryStorage {
private static Logger logger = LogsCenter.getLogger(XmlSalesHistoryStorage.class);

Expand Down

0 comments on commit bfabdc4

Please sign in to comment.