Skip to content

Commit

Permalink
Merge pull request #18 from AY1920S1-CS2113T-F10-3/master
Browse files Browse the repository at this point in the history
update 24/oct
  • Loading branch information
lijiayu980606 authored Oct 24, 2019
2 parents 7014443 + f7f67bc commit f1aacd4
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 233 deletions.
Binary file modified data/duke.txt
Binary file not shown.
7 changes: 3 additions & 4 deletions src/main/java/AlphaNUS.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AlphaNUS(String filepath) {
tasklist = new TaskList();
fund = new Fund(); //TODO the fund need to be stored in the text file.
managermap = new HashMap<String, Payee>();
commandList = new ArrayList<String>();
ArrayList<String> commandList = storage.load();
projectmap = new HashMap<String, Project>();//To replace managermap in main class
run();
}
Expand All @@ -50,7 +50,7 @@ public void run() {
boolean isExit = false;
while (!isExit) {
String input = ui.readInput();
isExit = Parser.parse(input, tasklist, ui, fund, storage, managermap, commandList, projectmap);
isExit = Parser.parse(input, tasklist, ui, fund, storage, commandList, managermap, projectmap);
}
}

Expand All @@ -59,7 +59,6 @@ public void run() {
* @param args Unused.
*/
public static void main(String[] args) {
new AlphaNUS("..data/AlphaNUS.txt").run();
new AlphaNUS("data/duke.txt").run();
}

}
10 changes: 0 additions & 10 deletions src/main/java/Launcher.java

This file was deleted.

130 changes: 0 additions & 130 deletions src/main/java/Main.java

This file was deleted.

46 changes: 33 additions & 13 deletions src/main/java/command/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,83 +34,103 @@ public class Parser {
* @param tasklist Tasklist of the user.
* @param ui Ui that interacts with the user.
* @param storage Storage for the Tasklist.
* @param commandList
* @param commandList List of input commands.
* @return Returns boolean variable to indicate when to stop parsing for input.
* @throws AlphaNUSException if input is not valid.
*/
public static boolean parse(String input, TaskList tasklist, Ui ui, Fund fund, Storage storage, HashMap<String, Payee> managermap, ArrayList<String> commandList, HashMap<String, Project> projectmap) {

public static boolean parse(String input, TaskList tasklist, Ui ui, Fund fund, Storage storage, ArrayList<String> commandList,
HashMap<String, Payee> managermap, HashMap<String, Project> projectmap) {
try {
if (instr.isBye(input)) {
//print bye message
ui.byeMessage();
ui.getIn().close();
return true;
} else if (instr.isHistory(input)) {
process.history(ui,commandList, storage);
} else if (instr.isAddProject(input)) {
process.commandHistory(input, ui, storage);
if (currentProject == null) {
currentProject = process.addProject(input, ui, projectmap);
} else {
process.addProject(input, ui, projectmap);
}
} else if (instr.isDeleteProject(input)) {
Project deletedProject = process.deleteProject(input, ui, projectmap);
process.commandHistory(input, ui, storage);
if (currentProject == deletedProject) {
currentProject = null;
}
} else if (instr.isGoToProject(input)) {
if (currentProject == null) {
process.noProject(ui);
}
currentProject = process.goToProject(input, ui, projectmap);
} else if (currentProject == null) {
process.noProject(ui);
process.commandHistory(input, ui, storage);
} else if (instr.isList(input)) {
//print out current list
process.commandHistory(input, ui, commandList,storage);
ui.printList(tasklist, "list");
process.commandHistory(input, ui, storage);
} else if (instr.isDone(input)) {
process.done(input, tasklist, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isDeadline(input)) {
process.deadline(input, tasklist, ui);
storage.save(tasklist.returnArrayList());
process.commandHistory(input, ui, storage);
//storage.save(tasklist.returnArrayList());

} else if (instr.isDoAfter(input)) {
process.doAfter(input, tasklist, ui);
Storage.save(tasklist.returnArrayList());
//Storage.save(tasklist.returnArrayList());
} else if (instr.isDeletePayment(input)) {
process.deletePayment(input, managermap, ui);
process.commandHistory(input, ui, storage);
//storage.save(tasklist.returnArrayList());

} else if (instr.isFind(input)) {
// process.find(input, tasklist, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isWithinPeriodTask(input)) {
process.within(input, tasklist, ui);
storage.save(tasklist.returnArrayList());
process.commandHistory(input, ui, storage);
//storage.save(tasklist.returnArrayList());
} else if (instr.isSnooze(input)) {
process.snooze(input, tasklist, ui);
storage.save(tasklist.returnArrayList());
process.commandHistory(input, ui, storage);
//storage.save(tasklist.returnArrayList());
/*
`} else if (instr.isPostpone(input)) {
process.postpone(input, tasklist, ui);
storage.save(tasklist.returnArrayList());`
*/
} else if (instr.isReschedule(input)) {
// process.reschedule(input, tasklist, ui);
storage.save(tasklist.returnArrayList());
//storage.save(tasklist.returnArrayList());
} else if (instr.isViewSchedule(input)) {
process.viewSchedule(input, tasklist, ui);
process.commandHistory(input, ui, storage);
//storage.save(tasklist.returnArrayList());
} else if (instr.isReminder(input)) {
//process.reminder(input, tasklist, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isEdit(input)) {
// process.edit(input,tasklist,ui);
process.commandHistory(input, ui, storage);
} else if (instr.isAddPayment(input)) {
process.addPayment(input, managermap, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isgetpayee(input)) {
process.findPayee(input, ui, managermap);
process.commandHistory(input, ui, storage);
} else if (instr.isAddPayee(input)) {
process.addPayee(input, managermap, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isDeletePayee(input)) {
process.deletePayee(input, managermap, ui);
process.commandHistory(input, ui, commandList, storage);
process.commandHistory(input, ui, storage);
} else if (instr.isInvoice(input)) {
process.inVoice(input, tasklist, ui);
process.commandHistory(input, ui, storage);
} else if (instr.isHistory(input)) {
process.commandHistory(input, ui,commandList, storage);
} else if (instr.isSetFund(input)) {
Expand All @@ -120,7 +140,7 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Fund fund, S
} else {
throw new AlphaNUSException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
} catch (AlphaNUSException | IOException e) {
} catch (AlphaNUSException e) {
process.homePageMessage(currentProject.projectname, projectmap.size(), ui);
} catch (NullPointerException e) {
process.homePageMessage(null, projectmap.size(), ui);
Expand Down
39 changes: 19 additions & 20 deletions src/main/java/command/Process.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import task.WithinPeriodTask;
import ui.Ui;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -510,22 +507,24 @@ public void inVoice(String input, TaskList tasklist, Ui ui) {
ui.exceptionMessage(" ☹ OOPS!!! Please input the correct command format (refer to user guide)");
}
}
/**
* processes the input command and stores it in a text file.
* @param input Input from the user.
* @param ui Ui that interacts with the user.
* @param storage Storage that stores the input commands entered by the user.
*/

public void commandHistory(String input, Ui ui, ArrayList<String> commandList, Storage storage) throws IOException {
if (!input.equals("history")) {
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
String formattedDate = dateFormat.format(date);
String command_time = input + " at " + formattedDate;
//commandList.add(command_time);
FileWriter fw = new FileWriter(String.valueOf(storage));
BufferedWriter bw = new BufferedWriter(fw);
bw.write(command_time);
}
else{
//ui.printArrayList(commandList);
ui.printTxtfile(String.valueOf(storage));
}
}
public void commandHistory(String input, Ui ui, Storage storage) {
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String formattedDate = dateFormat.format(date);
String commandTime = input + " | " + formattedDate;
storage.save(commandTime);
}

public void history(Ui ui, ArrayList<String> commandList, Storage storage) {
commandList = storage.load();
ui.printArrayList(commandList);
}
}
Loading

0 comments on commit f1aacd4

Please sign in to comment.