-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseFile.java
More file actions
79 lines (65 loc) · 2.79 KB
/
Copy pathParseFile.java
File metadata and controls
79 lines (65 loc) · 2.79 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
79
/**
* Created by jit_biswas on 2/1/2018.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
public class ParseFile {
//this method generates a ProcessGraph and store in ProcessGraph Class
public static void generateGraph(File inputFile) {
try{
Scanner fileIn=new Scanner(inputFile);
int index=0;
ArrayList<Integer> edgeParents = new ArrayList<Integer>();
ArrayList<Integer> edgeChildren = new ArrayList<Integer>();
while(fileIn.hasNext()){
String line=fileIn.nextLine();
String[] quatiles= line.split(":");
if (quatiles.length!=4) {
System.out.println("Wrong input format!");
throw new Exception();
}
//add this node
ProcessGraph.addNode(index);
//handle Children
if (!quatiles[1].equals("none")){
String[] childrenStringArray=quatiles[1].split(" ");
int[] childrenId=new int[childrenStringArray.length];
for (int i = 0; i < childrenId.length; i++) {
childrenId[i]= Integer.parseInt(childrenStringArray[i]);
edgeParents.add(index);
edgeChildren.add(childrenId[i]);
}
}
//setup command
ProcessGraph.nodes.get(index).setCommand(quatiles[0]);
//setup input
ProcessGraph.nodes.get(index).setInputFile(new File(quatiles[2]));
//setup output
ProcessGraph.nodes.get(index).setOutputFile(new File(quatiles[3]));
//mark initial runnable
for (ProcessGraphNode node:ProcessGraph.nodes) {
if (node.getParents().isEmpty()){
node.setRunnable();
}
}
index++;
}
for (int i = 0; i < edgeParents.size(); i++) {
int p = edgeParents.get(i);
int c = edgeChildren.get(i);
ProcessGraph.nodes.get(p).addChild(ProcessGraph.nodes.get(c));
}
//setup parent
for (ProcessGraphNode node : ProcessGraph.nodes) {
for (ProcessGraphNode childNode : node.getChildren()) {
ProcessGraph.nodes.get(childNode.getNodeId()).addParent(ProcessGraph.nodes.get(node.getNodeId()));
}
}
} catch (Exception e){
// System.out.println("File not found!");
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}