Skip to content

Commit

Permalink
Merge pull request #78 from benitokun123/master
Browse files Browse the repository at this point in the history
Clean up TaskCreator.java for compatibility and readability
  • Loading branch information
benitokun123 authored Oct 20, 2019
2 parents 60e692d + c83e42c commit 8312555
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 106 deletions.
6 changes: 3 additions & 3 deletions src/main/java/Model_Classes/Meeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public Meeting(String description, Date at) {
this.isFixedDuration = false;
}

public Meeting (String description, int duration, TimeUnit unit) {
super(description, null);
public Meeting (String description, Date date, int duration, TimeUnit unit) {
super(description, date);
this.duration = duration;
this.timeUnit = unit;
this.isFixedDuration = true;
Expand All @@ -36,7 +36,7 @@ public Meeting (String description, int duration, TimeUnit unit) {
@Override
public String toString() {
if (isFixedDuration){
return "[M]" + super.toString() + " (in: " + duration + " " + timeUnit.toString() + ")";
return "[M]" + super.toString() + " (on: " + super.getDate() + ") (duration: " + duration + " " + timeUnit.toString() + ")";
} else {
return "[M]" + super.toString() + " (on: " + super.getDate() + ")";
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Model_Classes/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getUser() {
* @return time the task was created
*/

public void setUser(String user) {
public void setAssignee(String user) {
this.user = user;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Operations/RecurHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public boolean checkRecurrence() {
Assignment recurringAssignment= new Assignment(description, getNewDate(check));
recurringAssignment.setRecurrenceSchedule(type);
recurringAssignment.setPriority(check.getPriority());
recurringAssignment.setUser(check.getUser());
recurringAssignment.setAssignee(check.getUser());
taskList.replace(index, recurringAssignment);
isEdited = true;
} else {
Meeting recurringMeeting= new Meeting(description, getNewDate(check));
recurringMeeting.setRecurrenceSchedule(type);
recurringMeeting.setPriority(check.getPriority());
recurringMeeting.setUser(check.getUser());
recurringMeeting.setAssignee(check.getUser());
taskList.replace(index, recurringMeeting);
isEdited = true;
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/Operations/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
// Assignment type
Assignment assignment = new Assignment(description, date);
assignment.setPriority(priority);
assignment.setUser(user);
assignment.setAssignee(user);
assignment.setRecurrenceSchedule(recurrence);
assignment.setDone(done);
if (scanSubTask.length() != 0) assignment.setSubTasks(scanSubTask);
taskArrayList.add(assignment);
} else {
//Meeting type
if (isFixedDuration) {
Meeting meeting = new Meeting(description, duration, unit);
Meeting meeting = new Meeting(description, date, duration, unit);
meeting.setPriority(priority);
meeting.setUser(user);
meeting.setAssignee(user);
meeting.setRecurrenceSchedule(recurrence);
meeting.setDone(done);
taskArrayList.add(meeting);
} else {
Meeting meeting = new Meeting(description, date);
meeting.setRecurrenceSchedule(recurrence);
meeting.setPriority(priority);
meeting.setUser(user);
meeting.setAssignee(user);
meeting.setDone(done);
taskArrayList.add(meeting);
}
Expand Down Expand Up @@ -224,8 +224,7 @@ String convertForStorage(Task task) throws RoomShareException {
String month = dateFormat.format(date);
String[] timeArray = tempString[4].split(":", 3);
String day = tempString[3];
String recurrence = task.getRecurrenceSchedule().toString();
time = day + "/" + month + "/" + year + " " + timeArray[0] + ":" + timeArray[1] + '#' + recurrence +"#";
time = day + "/" + month + "/" + year + " " + timeArray[0] + ":" + timeArray[1];
// if (task instanceof FixedDuration) {
// String[] durationArray = prelimSplit[3].split(":");
// String temp = durationArray[1].trim();
Expand Down
163 changes: 69 additions & 94 deletions src/main/java/Operations/TaskCreator.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package Operations;

import CustomExceptions.RoomShareException;
import Enums.ExceptionType;
import Enums.Priority;
import Enums.RecurrenceScheduleType;
import Enums.TimeUnit;
import Model_Classes.Assignment;
import Model_Classes.Meeting;
import Model_Classes.Task;
import java.util.Timer;
import java.util.TimerTask;

import java.util.Date;

Expand All @@ -21,30 +19,45 @@ public TaskCreator() {
}

public Task create(String input) throws RoomShareException {
Priority priorityType;
RecurrenceScheduleType recurrenceScheduleType;
String assignee;

// extract the description
String[] descriptionArray = input.split("\\(");
String[] descriptionArray2 = descriptionArray[1].trim().split("\\)");
String description = descriptionArray2[0].trim();
// extract the Task Type
String[] typeArray = input.split("#");
String type = typeArray[1];

// extract the priority
String[] priorityArray = input.split("\\*");
Priority priority;
if (priorityArray.length != 1) {
String priority = priorityArray[1].trim();
String inputPriority = priorityArray[1].trim();
try {
priorityType = Priority.valueOf(priority);
priority = Priority.valueOf(inputPriority);
} catch (IllegalArgumentException e) {
System.out.println("There seems to some mistake in your priority entry, will be setting priority as low");
priorityType = Priority.low;
priority = Priority.low;
}
} else {
priorityType = Priority.low;
priority = Priority.low;
}

// extract the description
String[] descriptionArray = input.split("\\(");
String[] descriptionArray2 = descriptionArray[1].trim().split("\\)");
String description = descriptionArray2[0].trim();

// extract date
String dateArray[] = input.split("&");
String dateInput = dateArray[1].trim();
Date date;
try {
date = new Parser().formatDate(dateInput);
} catch (RoomShareException e) {
System.out.println("Wrong date format");
date = new Date();
}

// extract the assignee
String[] assigneeArray = input.split("@");
String assignee;
if (assigneeArray.length != 1) {
assignee = assigneeArray[1].trim();
} else {
Expand All @@ -53,97 +66,59 @@ public Task create(String input) throws RoomShareException {

// extract recurrence schedule
String[] recurrenceArray = input.split("%");
RecurrenceScheduleType recurrence;
if (recurrenceArray.length != 1) {
String recurrence = recurrenceArray[1].trim();
String inputRecurrence = recurrenceArray[1].trim();
try {
recurrenceScheduleType = RecurrenceScheduleType.valueOf(recurrence);
recurrence = RecurrenceScheduleType.valueOf(inputRecurrence);
} catch (IllegalArgumentException e) {
System.out.println("There seems to some mistake in your recurrence entry, will be setting recurrence as none");
recurrenceScheduleType = RecurrenceScheduleType.none;
recurrence = RecurrenceScheduleType.none;
}
} else {
recurrenceScheduleType = RecurrenceScheduleType.none;
recurrence = RecurrenceScheduleType.none;
}
// extract the Task Type
String[] type = input.split("#");
// extract the time
String[] timeArray = input.split("&");
String[] durationArray = timeArray[1].split(" ");
String[] durationLength = durationArray[1].split("-");
TimeUnit unit = TimeUnit.minutes;
int duration =0;
if (timeArray.length != 1 && durationLength.length < 1) {
// not a fixed duration task
String time = timeArray[1].trim();
// create the time
Date by;
try {
by = parser.formatDate(time);
} catch (RoomShareException e) {
by = new Date();
}
if (type[1].contains("assignment")) {
Assignment createdTask = new Assignment(description, by);
createdTask.setPriority(priorityType);
createdTask.setUser(assignee);
createdTask.setRecurrenceSchedule(recurrenceScheduleType);
return createdTask;
} else {
//checks for time clashes before creating Meeting
if( !CheckAnomaly.checkTime(by) ) {
Meeting createdTask = new Meeting(description, by);
createdTask.setPriority(priorityType);
createdTask.setUser(assignee);
createdTask.setRecurrenceSchedule(recurrenceScheduleType);
return createdTask;
} else {
throw new RoomShareException(ExceptionType.timeClash);
}
}
} else if (durationLength.length > 1){
duration = Integer.parseInt(durationLength[1]) - Integer.parseInt(durationLength[0]);
//need to change this section
if(durationArray[1].contains("r")) {
TaskReminder taskReminder = new TaskReminder(description, duration);
taskReminder.start();
}
if((duration % 100) == 0) {
duration = duration % 9;
unit = TimeUnit.valueOf("hours");
Meeting meeting = new Meeting(description, duration, unit);
meeting.setPriority(priorityType);
meeting.setUser(assignee);
meeting.setRecurrenceSchedule(recurrenceScheduleType);

//extract duration
String[] durationArray = input.split("\\^");
String[] inputDuration = durationArray[1].split(" ");
int duration;
TimeUnit unit;
try {
duration = Integer.parseInt(inputDuration[0].trim());
unit = TimeUnit.valueOf(inputDuration[1].trim());
}
catch (IllegalArgumentException e) {
duration = 0;
unit = TimeUnit.unDefined;
}

if (type.contains("assignment")) {
Assignment assignment = new Assignment(description,date);
assignment.setPriority(priority);
assignment.setAssignee(assignee);
assignment.setRecurrenceSchedule(recurrence);
return assignment;
}

if (type.contains("meeting")) {
if (unit.equals(TimeUnit.unDefined)) {
// duration was not specified or not correctly input
Meeting meeting = new Meeting(description,date);
meeting.setPriority(priority);
meeting.setAssignee(assignee);
meeting.setRecurrenceSchedule(recurrence);
return meeting;
} else {
if( !CheckAnomaly.checkTime(duration, unit) ) {
Meeting meeting = new Meeting(description, duration, unit);
meeting.setPriority(priorityType);
meeting.setUser(assignee);
meeting.setRecurrenceSchedule(recurrenceScheduleType);
return meeting;
} else {
throw new RoomShareException(ExceptionType.timeClash);
}
}
} else {
// fixed duration task
// extract the fixed duration timing
String[] fixedDurationArray = input.split("\\^");
String[] tempArray = fixedDurationArray[1].split("\\s+");
duration = Integer.parseInt(tempArray[0].trim());
unit = TimeUnit.valueOf(tempArray[1].toLowerCase().trim());

//reminder function
if(durationArray[1].contains("r")) {
TaskReminder taskReminder = new TaskReminder(description, duration);
taskReminder.start();
else {
Meeting meeting = new Meeting(description, date, duration, unit);
meeting.setPriority(priority);
meeting.setAssignee(assignee);
meeting.setRecurrenceSchedule(recurrence);
return meeting;
}
Meeting meeting = new Meeting(description, duration, unit);
meeting.setPriority(priorityType);
meeting.setUser(assignee);
meeting.setRecurrenceSchedule(recurrenceScheduleType);
return meeting;
}

return null;
}
}

0 comments on commit 8312555

Please sign in to comment.