forked from nus-cs2103-AY2122S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
873 additions
and
181 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Duke; | ||
public enum Action { | ||
LIST, | ||
DONE, | ||
TODO, | ||
DEADLINE, | ||
EVENT, | ||
DELETE, | ||
BYE, | ||
FIND, | ||
UNKNOWN | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package Duke; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* <pre> | ||
* Child class Deadline from Task Class | ||
* </pre> | ||
*/ | ||
public class Deadline extends Task{ | ||
|
||
|
||
/** | ||
* Defult constructor, | ||
*/ | ||
public Deadline(String actionName, boolean compleated, String date, String type) { | ||
super(actionName, compleated, type, date); | ||
} | ||
|
||
/** | ||
* Defult to String. | ||
* @return String representation of task | ||
*/ | ||
@Override | ||
public String toString(){ | ||
|
||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy HH:mm"); | ||
|
||
String check = "[ ]"; | ||
if (this.compleated){ | ||
check = "[X]"; | ||
} | ||
return "[D] " + check + " " + this.actionName + "(by: " + dateFormat.format(date) + ")"; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package Duke; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* <pre> | ||
* Child class Event from Task Class | ||
* </pre> | ||
*/ | ||
public class Event extends Task{ | ||
|
||
/** | ||
* Defult constructor, | ||
*/ | ||
public Event(String actionName, boolean compleated, String date, String type){ | ||
super(actionName, compleated, type, date); | ||
} | ||
|
||
/** | ||
* Defult to String. | ||
* @return String representation of task | ||
*/ | ||
@Override | ||
public String toString(){ | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy HH:mm"); | ||
|
||
String check = "[ ]"; | ||
if (this.compleated){ | ||
check = "[X]"; | ||
} | ||
return "[E] " + check + " " + this.actionName + "(at: " + dateFormat.format(date) + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package Duke; | ||
|
||
/** | ||
* <pre> | ||
* InputNotValidError class | ||
* </pre> | ||
*/ | ||
public class InputNotValidError extends Exception { | ||
public InputNotValidError(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package Duke; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Parser { | ||
String command; | ||
Action action; | ||
|
||
public Parser(String command){ | ||
this.command = command; | ||
this.action = action(command); | ||
} | ||
|
||
public Action action(String command){ | ||
String[] splited = command.split(" ", 2); | ||
|
||
String action1 = splited[0]; | ||
if (action1.equals("list")){ | ||
return Action.LIST; | ||
}else if (action1.equals("done")){ | ||
return Action.DONE; | ||
}else if(action1.equals("todo")){ | ||
return Action.TODO; | ||
}else if(action1.equals("deadline")){ | ||
return Action.DEADLINE; | ||
}else if(action1.equals("event")){ | ||
return Action.EVENT; | ||
}else if(action1.equals("delete")){ | ||
return Action.DELETE; | ||
}else if(action1.equals("bye")){ | ||
return Action.BYE; | ||
}else if(action1.equals("find")){ | ||
return Action.FIND; | ||
} | ||
else{ | ||
return Action.UNKNOWN; | ||
} | ||
} | ||
|
||
public Action getAction(){ | ||
return this.action; | ||
} | ||
|
||
public int getCommandSize(){ | ||
String[] splited = this.command.split(" ", 2); | ||
return splited.length; | ||
} | ||
|
||
public String getActionList(){ | ||
String[] splited = this.command.split(" ", 2); | ||
return splited[1]; | ||
} | ||
|
||
public boolean isValid() throws InputNotValidError{ | ||
Set<Action> infoReqired = new HashSet<>(Arrays.asList( | ||
Action.TODO, Action.DONE,Action.DONE,Action.DEADLINE,Action.EVENT)); | ||
if (this.action == Action.UNKNOWN){ | ||
throw new InputNotValidError("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
}else{ | ||
if(infoReqired.contains(this.action) && this.getCommandSize() <= 1){ | ||
throw new InputNotValidError("☹ OOPS!!! The description of a " + this.getActionList() + " cannot be empty."); | ||
}else{ | ||
return true; | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package Duke; | ||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
|
||
|
||
|
||
/** | ||
* <pre> | ||
* Stroage class, | ||
* this class is to deal with | ||
* loading tasks from the file and saving tasks in the file. | ||
* </pre> | ||
* @param <String> Filepath path to the data txt file | ||
*/ | ||
public class Storage { | ||
|
||
String filepath; | ||
|
||
/** | ||
* Defult constructor | ||
* @param filepath filepath to the data txt file | ||
*/ | ||
public Storage (String filepath){ | ||
this.filepath = filepath; | ||
} | ||
|
||
/** | ||
* Method to load data from txt file, | ||
* returns the arraylist of tring array representation of tasks. | ||
* @return String array representation of tasks | ||
*/ | ||
public ArrayList<String[]> loadData() throws FileNotFoundException{ | ||
ArrayList<String[]> res = new ArrayList<>(); | ||
try (BufferedReader br = new BufferedReader(new FileReader(this.filepath))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
String[] splited = line.split("\\|"); | ||
res.add(splited); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return res; | ||
} | ||
|
||
/** | ||
* Method to save data to txt file, | ||
* @param tasks String array representation of tasks | ||
*/ | ||
public void saveData(ArrayList<Task> tasks) throws IOException{ | ||
File fout = new File(this.filepath); | ||
FileOutputStream fos = new FileOutputStream(fout); | ||
|
||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); | ||
|
||
for(Task eachtask : tasks){ | ||
String actionname = eachtask.getActionName(); | ||
boolean compleated = eachtask.getCompleted(); | ||
String type = eachtask.getType(); | ||
String done = "0"; | ||
String output; | ||
|
||
if (compleated){ | ||
done = "1"; | ||
} | ||
|
||
if(type.equals("T")){ | ||
output = type + " | " + done + " | " + actionname; | ||
}else{ | ||
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HHmm"); | ||
Date date = eachtask.getDate(); | ||
output = type + " | " + done + " | " + actionname + " | " + dateFormat.format(date) ; | ||
} | ||
bw.write(output); | ||
bw.newLine(); | ||
} | ||
bw.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package Duke; | ||
import java.util.Date; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
|
||
/** | ||
* <pre> | ||
* Task object to hold the task, | ||
* this is to create each tasks framework. | ||
* </pre> | ||
* @param <String> actionName name of the action | ||
* @param <boolean> compleated weather the task if completed | ||
* @param <String> type action type | ||
* @param <Date> date Date object of the task | ||
*/ | ||
public class Task{ | ||
String actionName; | ||
boolean compleated; | ||
String type; | ||
Date date; | ||
|
||
/** | ||
* Defult constructor, | ||
* prase the date into spedific format. | ||
* @param actionName name of the action | ||
* @param compleated weather the task if completed | ||
* @param type action type | ||
* @param date Date object of the task | ||
*/ | ||
public Task(String actionName, boolean compleated, String type, String date){ | ||
this.actionName = actionName; | ||
this.compleated = compleated; | ||
this.type = type; | ||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HHmm"); | ||
try { | ||
this.date = format.parse(date); | ||
} catch (ParseException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* To mark the task as | ||
* as compleated. | ||
*/ | ||
public void doneTask(){ | ||
this.compleated = true; | ||
} | ||
|
||
/** | ||
* To return the name of the action. | ||
* @return action name | ||
*/ | ||
public String getActionName(){ | ||
return this.actionName; | ||
} | ||
|
||
/** | ||
* To return the boolean of compleateness. | ||
* @return compleated boolean | ||
*/ | ||
public boolean getCompleted(){ | ||
return this.compleated; | ||
} | ||
|
||
/** | ||
* To return the type of the action. | ||
* @return action type name | ||
*/ | ||
public String getType(){ | ||
return this.type; | ||
} | ||
|
||
/** | ||
* To return the date of the task. | ||
* @return date of task | ||
*/ | ||
public Date getDate(){ | ||
return this.date; | ||
} | ||
|
||
/** | ||
* Defult to String. | ||
* @return String representation of task | ||
*/ | ||
public String toString(){ | ||
String check = "[ ]"; | ||
if (this.compleated){ | ||
check = "[X]"; | ||
} | ||
return check + " " + this.actionName; | ||
} | ||
} |
Oops, something went wrong.