Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Leave task type #91

Merged
merged 5 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/CustomExceptions/RoomShareException.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class RoomShareException extends Exception {
public static final String wrongTaskType_Text = "Only meeting or assignment tag are accepted";
public static final String emptyDescription_Text = "You haven't included the description of you task";
public static final String emptyDate_Text = "You haven't included the date of your task";
public static final String emptyUser_Text = "You haven't included the user of your task";
public static final String emptyTaskType_Text = "You haven't specified the type of your task: assignment or meeting";
public static final String writeError_Text = "Error in writing file, cancelling write process...";
public static final String wrongIndexFormat_Text = "The index you've enter is in the wrong format";
Expand All @@ -28,6 +29,10 @@ public class RoomShareException extends Exception {
public RoomShareException(ExceptionType type){
switch(type) {

case emptyUser:
message = emptyUser_Text;
break;

case emptyList:
message = emptyList_Text;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Enums/ExceptionType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Enums;

public enum ExceptionType {
wrongTimeFormat, wrongIndexFormat, writeError, timeClash, emptyList, wrongFormat, empty, outOfBounds, wrongPriority, test, subTask, wrongTaskType, emptyDescription, emptyDate, emptyTaskType, others
wrongTimeFormat, wrongIndexFormat, writeError, timeClash, emptyList, wrongFormat, emptyUser, outOfBounds, wrongPriority, test, subTask, wrongTaskType, emptyDescription, emptyDate, emptyTaskType, others
}
2 changes: 1 addition & 1 deletion src/main/java/Enums/SaveType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Enums;

public enum SaveType {
A, M, empty
A, L, empty
}
36 changes: 5 additions & 31 deletions src/main/java/Model_Classes/Leave.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Model_Classes;

import Enums.TimeUnit;
import java.util.Date;

/**
Expand All @@ -11,10 +10,6 @@
public class Leave extends Task {
private Date from;
private Date to;
private boolean isFixedDuration;
private int duration;
private TimeUnit timeUnit;
private boolean isShort;
private String user;


Expand All @@ -23,16 +18,6 @@ public Leave(String description, String user, Date from, Date to) {
this.user = user;
this.from = from;
this.to = to;
this.isShort = false;
}

public Leave(String description, String user, Date from, int duration, TimeUnit unit) {
super(description, from);
this.user = user;
this.from = from;
this.duration = duration;
this.timeUnit = unit;
this.isShort = true;
}

public Date checkStartDate() {
Expand All @@ -43,24 +28,13 @@ public Date checkEndDate() {
return this.to;
}

public boolean isShort() {
return isShort;
}

public String getDuration() {
return Integer.toString(duration);
}

public TimeUnit getTimeUnit() {
return timeUnit;
@Override
public String getUser() {
return this.user;
}

@Override
public String toString() {
if(isShort) {
return "[L]" + super.toString() + " " + user + " (from: " + from + " back in( " + duration + " " + timeUnit.toString() + ")";
} else {
return "[L]" + super.toString() + " " + user + " (from: " + from + " to: " + to + ")";
}
return "[L] " + super.getDescription() + " (" + user + ")" + " (From: " + from + " To: " + to + ")";
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/Model_Classes/ProgressBar.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Model_Classes;

public class ProgressBar {
private String[] bar = new String[20];
private String[] bar = new String[50];
private float total;
private float done;

Expand All @@ -19,18 +19,18 @@ public ProgressBar(float total, float done) {
* Displays the progress bar
*/
public void showBar() {
for (int i=0; i<20; i++) {
for (int i=0; i<50; i++) {
bar[i] = " ";
}
float percentage =0;
if(total >= 1) {
percentage = done / total;
for (int i = 0; i < (int)(percentage*20); i++) {
for (int i = 0; i < (int)(percentage*50); i++) {
bar[i] = "=";
}
}
System.out.print("[");
for(int i=0; i<20; i++) {
for(int i=0; i<50; i++) {
System.out.print(bar[i]);
}
System.out.print("]");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Model_Classes/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ public void snoozeHour(int amount){
public void snoozeMinute(int amount){
this.time.setMinutes(this.time.getMinutes() + amount);
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package Operations;
package Model_Classes;

import CustomExceptions.RoomShareException;
import Enums.Priority;
Expand Down
131 changes: 103 additions & 28 deletions src/main/java/Operations/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
for (String list : tempList) {
String[] temp = list.split("#", 0);

// Identify type of tassk
// Identify type of task
String scanType = temp[0].trim();
SaveType type;
try {
Expand All @@ -67,12 +67,30 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
String scanDescription = temp[3].trim();
String description = scanDescription;

String scanDate = temp[4].trim();
Date from = new Date();
Date to = new Date();
Date date = new Date();
try {
date = parser.formatDate(scanDate);
} catch (RoomShareException e) {
System.out.println("error in loading file: date format error");
if (temp[4].contains("-")) {
String[] dateArray = temp[4].trim().split("-");
String scanFromDate = dateArray[0].trim();
try {
from = parser.formatDate(scanFromDate);
} catch (RoomShareException e) {
System.out.println("error in loading file: date format error");
}
String scanToDate = dateArray[1].trim();
try {
to = parser.formatDate(scanToDate);
} catch (RoomShareException e) {
System.out.println("error in loading file: date format error");
}
} else {
String scanDate = temp[4].trim();
try {
date = parser.formatDate(scanDate);
} catch (RoomShareException e) {
System.out.println("error in loading file: date format error");
}
}

String scanRecurrence = temp[5].trim();
Expand Down Expand Up @@ -103,6 +121,13 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
assignment.setDone(done);
if (!scanSubTask.equals("")) assignment.setSubTasks(scanSubTask);
taskArrayList.add(assignment);
} else if (type.equals(SaveType.L)) {
//Leave type
Leave leave = new Leave(description, user, from, to);
leave.setPriority(priority);
leave.setRecurrenceSchedule(recurrence);
leave.setDone(done);
taskArrayList.add(leave);
} else {
//Meeting type
if (isFixedDuration) {
Expand Down Expand Up @@ -151,41 +176,54 @@ public void writeFile(ArrayList<Task> list, String fileName) throws RoomShareExc
String recurrence = s.getRecurrenceSchedule().toString();
String user = s.getUser();
if (s instanceof Assignment) {
out = type + "#" +
isDone + "#" +
priority + "#" +
description + "#" +
date + "#" +
recurrence + "#" +
user + "#" +
"N" + "#" +
"0" + "#" +
"unDefined" + "#";
// Saves sub-tasks
if( !(((Assignment) s).getSubTasks() == null ) ) {
ArrayList<String> subTasks = ((Assignment) s).getSubTasks();
for( String subTask : subTasks ) {
out += subTask + ",";
}
out = type + "#" +
isDone + "#" +
priority + "#" +
description + "#" +
date + "#" +
recurrence + "#" +
user + "#" +
"N" + "#" +
"0" + "#" +
"unDefined" + "#";
// Saves sub-tasks
if (!(((Assignment) s).getSubTasks() == null)) {
ArrayList<String> subTasks = ((Assignment) s).getSubTasks();
for (String subTask : subTasks) {
out += subTask + ",";
}
out += "#";
} else if (s instanceof Meeting){
}
out += "#";
} else if (s instanceof Leave) {
String leaveDate = convertForStorageLeave(s);
out = type + "#" +
isDone + "#" +
priority + "#" +
description + "#" +
leaveDate + "#" +
recurrence + "#" +
user + "#" +
"N" + "#" +
"0" + "#" +
"unDefined" + "#"
+ "#";
} else if (s instanceof Meeting) {
if (((Meeting) s).isFixedDuration()) {
String duration = ((Meeting) s).getDuration();
String unit = ((Meeting) s).getTimeUnit().toString();
out = type + "#" +
out = type + "#" +
isDone + "#" +
priority + "#" +
description + "#" +
date + "#" +
recurrence + "#" +
user+ "#" +
user + "#" +
"F" + "#" +
duration + "#" +
unit + "#"
+ "#";
} else {
out = type + "#" +
out = type + "#" +
isDone + "#" +
priority + "#" +
description + "#" +
Expand All @@ -198,7 +236,7 @@ public void writeFile(ArrayList<Task> list, String fileName) throws RoomShareExc
+ "#";
}
}
writer.write(out );
writer.write(out);
writer.newLine();
}
writer.close();
Expand All @@ -212,6 +250,7 @@ public void writeFile(ArrayList<Task> list, String fileName) throws RoomShareExc
* will format the time information for deadline and event tasks
* Additional formatting will be done for recurring tasks to include recurrence schedule
* returns a string with all the relevant information.
*
* @param task task object to be converted
* @return time A String containing all the relevant information
* @throws RoomShareException If there is any error in parsing the Date information.
Expand All @@ -234,4 +273,40 @@ String convertForStorage(Task task) throws RoomShareException {
}
}

private String convertForStorageLeave(Task task) throws RoomShareException {
try {
String time = "";
String[] prelimSplit = task.toString().split("\\(");
String[] tempString = prelimSplit[2].split("\\s+");
//from year
String fromYear = tempString[6].trim();
//to year
String toYear = tempString[13].trim().substring(0, tempString[13].length() -1);
//from month
Date fromMonth = new SimpleDateFormat("MMM").parse(tempString[2]);
DateFormat dateFormatFromMonth = new SimpleDateFormat("MM");
String fromMth = dateFormatFromMonth.format(fromMonth);
//to month
Date toMonth = new SimpleDateFormat("MMM").parse(tempString[9]);
DateFormat dateFormatToMonth = new SimpleDateFormat("MM");
String toMth = dateFormatToMonth.format(fromMonth);
//from time
String[] fromTimeArray = tempString[4].split(":", 3);
//to time
String[] toTimeArray = tempString[11].split(":", 3);
//from day
String fromDay = tempString[3];
//to day
String toDay = tempString[10];

time = fromDay + "/" + fromMth + "/" + fromYear + " " + fromTimeArray[0] + ":" + fromTimeArray[1] + "-" +
toDay + "/" + toMth + "/" + toYear + " " + toTimeArray[0] + ":" + toTimeArray[1];
return time;
} catch (ParseException e) {
throw new RoomShareException(ExceptionType.wrongFormat);
}
}

}


Loading