-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessGraphNode.java
More file actions
129 lines (103 loc) · 2.98 KB
/
Copy pathProcessGraphNode.java
File metadata and controls
129 lines (103 loc) · 2.98 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.io.File;
import java.util.ArrayList;
/**
* Programming Assignment 1
* Done by:
* Koh Kai Wei 1001471
* Chan Wei Ren 1001459
*
* CHANGES : Added a running boolean to tell us if the process is running.
* METHODS :
* isRunning - Returns a boolean representing if the node's command is running as a process
* setRunning - sets running to true or false.
*
**/
public class ProcessGraphNode {
//point to all the parents
private ArrayList<ProcessGraphNode> parents=new ArrayList<>();
//point to all the children
private ArrayList<ProcessGraphNode> children=new ArrayList<>();
//properties of ProcessGraphNode
private int nodeId;
private File inputFile;
private File outputFile;
private String command;
private boolean runnable;
private boolean executed;
private boolean running; // This field is to notify us if the node is running
public ProcessGraphNode(int nodeId ) {
this.nodeId = nodeId;
this.runnable=false;
this.running=false;
this.executed=false;
}
public void setRunning(boolean running) {
this.running = running;
}
public void setRunnable() {
this.runnable = true;
}
public void setNotRunnable() {this.runnable = false;}
public void setExecuted() {
this.executed = true;
}
public boolean isRunning() {
return running;
}
public boolean isRunnable() {
return runnable;
}
public boolean isExecuted() {
return executed;
}
public void addChild(ProcessGraphNode child){
if (!children.contains(child)){
children.add(child);
}
}
public void addParent(ProcessGraphNode parent){
if (!parents.contains(parent)){
parents.add(parent);
}
}
public void setInputFile(File inputFile) {
this.inputFile = inputFile;
}
public void setCommand(String command) {
this.command = command;
}
public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
public File getInputFile() {
return inputFile;
}
public File getOutputFile() {
return outputFile;
}
public String getCommand() {
return command;
}
public ArrayList<ProcessGraphNode> getParents() {
return parents;
}
public ArrayList<ProcessGraphNode> getChildren() {
return children;
}
public int getNodeId() {
return nodeId;
}
public synchronized boolean allParentsExecuted(){
boolean ans=true;
for (ProcessGraphNode child : this.getChildren()) {
if (child.isExecuted()) {
return false;
}
}
for (ProcessGraphNode parent:this.getParents()) {
if (!parent.isExecuted())
ans=false;
}
return ans;
}
}