Skip to content

Commit

Permalink
Successfully revamped the Architecture.
Browse files Browse the repository at this point in the history
Todo:
 - Revamp Tests to match
 - Amend Checkstyle Violations
 - Move TaskList, Wallet, ReceiptTracker, etc classes to Storage instead of Ui
Signed-off-by: Mudaafi <[email protected]>
  • Loading branch information
Mudaafi committed Nov 5, 2019
1 parent 1ad8bdd commit 03b41c6
Show file tree
Hide file tree
Showing 49 changed files with 1,216 additions and 813 deletions.
1 change: 1 addition & 0 deletions savedTask.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO test ####false
19 changes: 11 additions & 8 deletions src/main/java/executor/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
package executor.command;

import executor.task.TaskList;
import storage.StorageManager;
import ui.Wallet;
import utils.InfoCapsule;

public abstract class Command {
protected Boolean exitRequest = false;
protected InfoCapsule infoCapsule;
protected String userInput = null;
protected CommandType commandType;
protected String description = "NO DESCRIPTION";

// Constructor
public Command() {
this.infoCapsule = new InfoCapsule();
infoCapsule.setCodeError();
infoCapsule.setOutputStr("Command was not executed.\n");
}

/**
* Returns True if the command requests for the Ui to exit.
*
* Returns an InfoCapsule that details the Execution Info/Status of this Command.
* @return Boolean
*/
public Boolean getExitRequest() {
return exitRequest;
public InfoCapsule getInfoCapsule() {
return this.infoCapsule;
}

/**
* Executes a particular Command.
* @param storageManager StorageManager Object that holds all the Models of Duke
*/
public abstract void execute(TaskList taskList);

public abstract void execute(Wallet wallet);
public abstract void execute(StorageManager storageManager);

public String getDescription() {
return this.description;
Expand Down
33 changes: 21 additions & 12 deletions src/main/java/executor/command/CommandAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import executor.task.TaskList;
import interpreter.Parser;
import storage.StorageManager;
import ui.Wallet;

public class CommandAdd extends Command {
Expand All @@ -13,28 +14,36 @@ public class CommandAdd extends Command {

/**
* Constructor for CommandListMonYear subCommand Class.
*
* @param userInput String is the user input from the CLI
*/
public CommandAdd(String userInput) {
super();
this.userInput = userInput;
this.description = "Adds two double values. Format: add <number> // <number>";
this.commandType = CommandType.ADD;
}



@Override
public void execute(TaskList taskList) {

}

@Override
public void execute(Wallet wallet) {
this.entryOne = Double.parseDouble(Parser.parseForPrimaryInput(this.commandType, userInput));
this.entryTwo = Double.parseDouble(Parser.parseForFlag("", userInput));
public void execute(StorageManager storageManager) {
String entryOneStr = Parser.parseForPrimaryInput(this.commandType, userInput);
if (entryOneStr.equals("")) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Missing Numerator. \n FORMAT: div <number> // <number>\n");
return;
}
String entryTwoStr = Parser.parseForFlag("", userInput);
if (entryTwoStr == null) {
this.entryTwo = 0.0;
} else {
this.entryTwo = Double.parseDouble(entryTwoStr);
}
double sum = entryOne + entryTwo;
System.out.println(sum);
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr(entryOneStr
+ " + "
+ entryTwoStr
+ sum
+ "\n");
}

}
28 changes: 15 additions & 13 deletions src/main/java/executor/command/CommandAddIncomeReceipt.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package executor.command;

import executor.task.TaskList;
import duke.exception.DukeException;
import storage.StorageManager;
import ui.IncomeReceipt;
import ui.Ui;
import ui.Wallet;

import java.time.LocalDate;
import java.util.ArrayList;

public class CommandAddIncomeReceipt extends CommandAddReceipt {

Expand All @@ -15,6 +11,7 @@ public class CommandAddIncomeReceipt extends CommandAddReceipt {
* @param userInput The user input from the CLI
*/
public CommandAddIncomeReceipt(String userInput) {
super();
this.commandType = CommandType.IN;
this.userInput = userInput;
this.cash = extractIncome(this.commandType, this.userInput);
Expand All @@ -25,13 +22,18 @@ public CommandAddIncomeReceipt(String userInput) {
}

@Override
public void execute(TaskList taskList) {
}

@Override
public void execute(Wallet wallet) {
public void execute(StorageManager storageManager) {
IncomeReceipt r = new IncomeReceipt(this.cash, this.date, this.tags);
wallet.addReceipt(r);
Ui.dukeSays("Added Receipt: $" + r.getCashGained().toString() + "with tags: " + r.getTags().toString());
try {
storageManager.addReceipt(r);
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr("Added Receipt: $"
+ r.getCashGained().toString()
+ "with tags: "
+ r.getTags().toString());
} catch (DukeException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.toString());
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/executor/command/CommandAddReceipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ArrayList<String> extractTags(String userInput) {
}
}

String removeDollarSign(String input) {
private String removeDollarSign(String input) {
return input.trim().replace("$", "");
}

Expand Down
29 changes: 16 additions & 13 deletions src/main/java/executor/command/CommandAddSpendingReceipt.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package executor.command;

import executor.task.TaskList;
import duke.exception.DukeException;
import storage.StorageManager;
import ui.Receipt;
import ui.Ui;
import ui.Wallet;

import java.time.LocalDate;
import java.util.ArrayList;

public class CommandAddSpendingReceipt extends CommandAddReceipt {

Expand All @@ -15,6 +11,7 @@ public class CommandAddSpendingReceipt extends CommandAddReceipt {
* @param userInput The user input from the CLI
*/
public CommandAddSpendingReceipt(String userInput) {
super();
this.commandType = CommandType.OUT;
this.userInput = userInput;
this.cash = extractIncome(this.commandType, this.userInput);
Expand All @@ -25,14 +22,20 @@ public CommandAddSpendingReceipt(String userInput) {
}

@Override
public void execute(TaskList taskList) {
}

@Override
public void execute(Wallet wallet) {
public void execute(StorageManager storageManager) {
Receipt r = new Receipt(this.cash, this.date, this.tags);
wallet.addReceipt(r);
Ui.dukeSays("Added Receipt: $" + r.getCashSpent().toString() + " " + "with tags: " + r.getTags().toString());
try {
storageManager.addReceipt(r);
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr("Added Receipt: $"
+ r.getCashSpent().toString()
+ " "
+ "with tags: "
+ r.getTags().toString());
} catch (DukeException e) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr(e.getMessage());
}
}

}
16 changes: 5 additions & 11 deletions src/main/java/executor/command/CommandBlank.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package executor.command;

import executor.task.TaskList;
import ui.Ui;
import ui.Wallet;
import storage.StorageManager;

public class CommandBlank extends Command {

// Constructor
/**
* Constructor for CommandBlank subCommand Class.
* @param userInput The user input from the CLI
*/
public CommandBlank(String userInput) {
super();
this.userInput = userInput;
this.description = "Prints a line separator";
this.commandType = CommandType.BLANK;
Expand All @@ -21,12 +19,8 @@ public CommandBlank(String userInput) {
* Executes a particular Command.
*/
@Override
public void execute(TaskList taskList) {
Ui.printSeparator();
}

@Override
public void execute(Wallet wallet) {

public void execute(StorageManager storageManager) {
this.infoCapsule.setCodeToast();
this.infoCapsule.setOutputStr("");
}
}
16 changes: 4 additions & 12 deletions src/main/java/executor/command/CommandBye.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
package executor.command;

import executor.task.TaskList;
import ui.Ui;
import ui.Wallet;
import storage.StorageManager;

public class CommandBye extends Command {

// Constructor
/**
* Constructor for CommandBye subCommand Class.
* @param userInput The user input from the CLI
*/
public CommandBye(String userInput) {
super();
this.userInput = userInput;
this.description = "Exits the program \n"
+ "FORMAT : bye";
this.commandType = CommandType.BYE;
}

@Override
public void execute(TaskList taskList) {
this.exitRequest = true;
Ui.dukeSays("Bye. Hope to see you again soon!");
}

@Override
public void execute(Wallet wallet) {

public void execute(StorageManager storageManager) {
this.infoCapsule.setCodeExit();
}
}
Loading

0 comments on commit 03b41c6

Please sign in to comment.