9 |
9 |
10 object Document_Status { |
10 object Document_Status { |
11 /* command status */ |
11 /* command status */ |
12 |
12 |
13 object Command_Status { |
13 object Command_Status { |
|
14 object Theory_Status extends Enumeration { |
|
15 val NONE, INITIALIZED, CONSOLIDATING, CONSOLIDATED = Value |
|
16 |
|
17 def initialized(t: Value): Boolean = t >= INITIALIZED |
|
18 def consolidating(t: Value): Boolean = t >= CONSOLIDATING |
|
19 def consolidated(t: Value): Boolean = t >= CONSOLIDATED |
|
20 |
|
21 def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2 |
|
22 } |
|
23 |
14 val proper_elements: Markup.Elements = |
24 val proper_elements: Markup.Elements = |
15 Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING, |
25 Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING, |
16 Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
26 Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
17 |
27 |
18 val liberal_elements: Markup.Elements = |
28 val liberal_elements: Markup.Elements = |
21 def make( |
31 def make( |
22 markups: Iterable[Markup], |
32 markups: Iterable[Markup], |
23 warned: Boolean = false, |
33 warned: Boolean = false, |
24 failed: Boolean = false |
34 failed: Boolean = false |
25 ): Command_Status = { |
35 ): Command_Status = { |
|
36 var theory_status = Theory_Status.NONE |
26 var touched = false |
37 var touched = false |
27 var accepted = false |
38 var accepted = false |
28 var warned1 = warned |
39 var warned1 = warned |
29 var failed1 = failed |
40 var failed1 = failed |
30 var canceled = false |
41 var canceled = false |
31 var finalized = false |
42 var finalized = false |
32 var forks = 0 |
43 var forks = 0 |
33 var runs = 0 |
44 var runs = 0 |
34 for (markup <- markups) { |
45 for (markup <- markups) { |
35 markup.name match { |
46 markup.name match { |
|
47 case Markup.INITIALIZED => |
|
48 theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED) |
|
49 case Markup.CONSOLIDATING => |
|
50 theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING) |
|
51 case Markup.CONSOLIDATED => |
|
52 theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED) |
36 case Markup.ACCEPTED => accepted = true |
53 case Markup.ACCEPTED => accepted = true |
37 case Markup.FORKED => touched = true; forks += 1 |
54 case Markup.FORKED => touched = true; forks += 1 |
38 case Markup.JOINED => forks -= 1 |
55 case Markup.JOINED => forks -= 1 |
39 case Markup.RUNNING => touched = true; runs += 1 |
56 case Markup.RUNNING => touched = true; runs += 1 |
40 case Markup.FINISHED => runs -= 1 |
57 case Markup.FINISHED => runs -= 1 |
61 def merge(args: IterableOnce[Command_Status]): Command_Status = |
79 def merge(args: IterableOnce[Command_Status]): Command_Status = |
62 args.iterator.foldLeft(empty)(_ + _) |
80 args.iterator.foldLeft(empty)(_ + _) |
63 } |
81 } |
64 |
82 |
65 final class Command_Status private( |
83 final class Command_Status private( |
|
84 private val theory_status: Command_Status.Theory_Status.Value, |
66 private val touched: Boolean, |
85 private val touched: Boolean, |
67 private val accepted: Boolean, |
86 private val accepted: Boolean, |
68 private val warned: Boolean, |
87 private val warned: Boolean, |
69 private val failed: Boolean, |
88 private val failed: Boolean, |
70 private val canceled: Boolean, |
89 private val canceled: Boolean, |
77 else if (failed) "Command_Status(failed)" |
96 else if (failed) "Command_Status(failed)" |
78 else if (warned) "Command_Status(warned)" |
97 else if (warned) "Command_Status(warned)" |
79 else "Command_Status(...)" |
98 else "Command_Status(...)" |
80 |
99 |
81 def is_empty: Boolean = |
100 def is_empty: Boolean = |
|
101 !Command_Status.Theory_Status.initialized(theory_status) && |
82 !touched && !accepted && !warned && !failed && !canceled && !finalized && |
102 !touched && !accepted && !warned && !failed && !canceled && !finalized && |
83 forks == 0 && runs == 0 |
103 forks == 0 && runs == 0 |
84 |
104 |
85 def + (that: Command_Status): Command_Status = |
105 def + (that: Command_Status): Command_Status = |
86 if (is_empty) that |
106 if (is_empty) that |
87 else if (that.is_empty) this |
107 else if (that.is_empty) this |
88 else { |
108 else { |
89 new Command_Status( |
109 new Command_Status( |
|
110 theory_status = Command_Status.Theory_Status.merge(theory_status, that.theory_status), |
90 touched = touched || that.touched, |
111 touched = touched || that.touched, |
91 accepted = accepted || that.accepted, |
112 accepted = accepted || that.accepted, |
92 warned = warned || that.warned, |
113 warned = warned || that.warned, |
93 failed = failed || that.failed, |
114 failed = failed || that.failed, |
94 canceled = canceled || that.canceled, |
115 canceled = canceled || that.canceled, |
95 finalized = finalized || that.finalized, |
116 finalized = finalized || that.finalized, |
96 forks = forks + that.forks, |
117 forks = forks + that.forks, |
97 runs = runs + that.runs) |
118 runs = runs + that.runs) |
98 } |
119 } |
|
120 |
|
121 def initialized: Boolean = Command_Status.Theory_Status.initialized(theory_status) |
|
122 def consolidating: Boolean = Command_Status.Theory_Status.consolidating(theory_status) |
|
123 def consolidated: Boolean = Command_Status.Theory_Status.consolidated(theory_status) |
|
124 def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0 |
99 |
125 |
100 def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
126 def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
101 def is_running: Boolean = runs != 0 |
127 def is_running: Boolean = runs != 0 |
102 def is_warned: Boolean = warned |
128 def is_warned: Boolean = warned |
103 def is_failed: Boolean = failed |
129 def is_failed: Boolean = failed |