-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelControl.java
132 lines (112 loc) · 2.65 KB
/
ModelControl.java
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
130
131
132
/**
*
*/
package simulator;
/**
* A message passing object for tracking progress in long running tasks and
* instructing them to cancel if required.
*
* City University BSc Computing with Artificial Intelligence Project title:
* Building a TD Simulator for Real-Time Classical Conditioning
*
* @supervisor Dr. Eduardo Alonso
* @author Jonathan Gray
**/
public class ModelControl {
/** Task progress. **/
private volatile double progress;
public int getTotalProgress() {
return totalProgress;
}
public void setTotalProgress(int totalProgress) {
this.totalProgress = totalProgress;
}
private volatile int totalProgress;
/** Cancelled switch. **/
private volatile boolean isCancelled;
/** Estimated time taken for one run of the basic section of the task. **/
private long estimatedCycleTime = 0;
/** Number of times the cycletime has been updated. **/
private int modCount;
private volatile boolean isComplete;
private boolean madeExport;
public ModelControl() {
progress = 0;
isCancelled = false;
modCount = 1;
isComplete = false;
estimatedCycleTime = 0;
madeExport = false;
totalProgress = 0;
}
public void madeExport(boolean made) {
madeExport = made;
}
public boolean madeExport() {
return madeExport;
}
/**
*
* @return the estimated time for a single section of the underlying task.
*/
public long getEstimatedCycleTime() {
return estimatedCycleTime / modCount;
}
/**
* @return the progress
*/
public double getProgress() {
return progress;
}
/**
*
* @param increment
* to apply to progress.
*/
public void incrementProgress(double increment) {
progress += increment;
}
/**
* @return true if the associated task has been cancelled.
*/
public boolean isCancelled() {
return isCancelled;
}
/**
* @return the isComplete
*/
public boolean isComplete() {
return isComplete;
}
/**
* @param isCancelled
* true to cancel the task this passes messages for.
*/
public void setCancelled(boolean isCancelled) {
this.isCancelled = isCancelled;
}
/**
* @param isComplete
* the isComplete to set
*/
public void setComplete(boolean isComplete) {
this.isComplete = isComplete;
}
/**
*
* @param time
* recorded run time for a subsection of the main task.
*/
public void setEstimatedCycleTime(long time) {
time = Math.max(1, time);
modCount++;
estimatedCycleTime += time;// = Math.max(estimatedCycleTime,time);
}
/**
* @param progress
* the progress to set
*/
public void setProgress(double progress) {
this.progress = progress;
}
}