-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileReader.java
More file actions
78 lines (75 loc) · 3.21 KB
/
FileReader.java
File metadata and controls
78 lines (75 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.io.*;
import java.util.*;
public class FileReader {
private Schedule schedule;
public FileReader(Schedule schedule){
this.schedule = schedule;
}
public void read(String filename) throws Exception{
Scanner in = new Scanner(new File(filename));
String next1 = "";
String next2 = "";
ArrayList<String> taskData = new ArrayList<String>();
ArrayList<Task> newTasks = new ArrayList<Task>();
String type = "";
try{
in.next();
while(in.hasNext()){
next1 = in.next();
taskData.add(next1.substring(1, next1.length()-2));
next1 = in.next();
if(next1.equals("{")){
while(!(next1.equals("},") || next1.equals("}"))){
next1 = in.next();
next1 = in.next();
if(next1.substring(next1.length()-1).equals(",")){
next1 = next1.substring(1, next1.length()-2);
}
else if(next1.substring(next1.length()-1).equals("\"")){
next1 = next1.substring(1, next1.length()-1);
}
taskData.add(next1);
// count++;
}
}
else{
throw new Exception("Invalid format");
}
if(taskData.get(1).equals("TRANSIENT")){
Runtime runtime = new Runtime();
runtime.startTime = Double.parseDouble(taskData.get(2));
runtime.duration = Double.parseDouble(taskData.get(3));
Task newTask = new TransientTask(taskData.get(0), Integer.parseInt(taskData.get(5)), runtime);
if(taskData.get(4).equals("True")){
newTask.setAntiTask(true);
}
else if(taskData.get(4).equals("False")){
newTask.setAntiTask(false);
}
else{
throw new Exception("Invalid format");
}
schedule.checkConflicts(newTask);
newTasks.add(newTask);
}
else if(taskData.get(1).equals("RECURRING")){
Runtime runtime = new Runtime();
runtime.startTime = Double.parseDouble(taskData.get(2));
runtime.duration = Double.parseDouble(taskData.get(3));
Task newTask = new RecurringTask(taskData.get(0), Integer.parseInt(taskData.get(5)), runtime, Integer.parseInt(taskData.get(7)), Integer.parseInt(taskData.get(8)));
schedule.checkConflicts(newTask);
newTasks.add(newTask);
}
else{
throw new Exception("Invalid format");
}
}
}
catch (Exception e){
throw new Exception("Invalid format");
}
for(Task task : newTasks){
schedule.addTask(task);
}
}
}