12
12
* Represents the schedule state at a particular step
13
13
*/
14
14
public class StepState implements Serializable {
15
- /**
16
- * Mapping from machine type to list of machine instances
17
- */
18
- private Map <Class <? extends PMachine >, List <PMachine >> machineListByType = new HashMap <>();
19
-
20
15
/**
21
16
* Set of machines
22
17
*/
@@ -31,7 +26,6 @@ public class StepState implements Serializable {
31
26
public StepState copyState () {
32
27
StepState stepState = new StepState ();
33
28
34
- stepState .machineListByType = new HashMap <>(this .machineListByType );
35
29
stepState .machineSet = new TreeSet <>(this .machineSet );
36
30
37
31
stepState .machineLocalStates = new HashMap <>();
@@ -44,7 +38,6 @@ public StepState copyState() {
44
38
}
45
39
46
40
public void clear () {
47
- machineListByType .clear ();
48
41
machineSet .clear ();
49
42
machineLocalStates .clear ();
50
43
}
@@ -54,12 +47,10 @@ public void resetToZero() {
54
47
for (PMachine machine : PExplicitGlobal .getMachineSet ()) {
55
48
machine .reset ();
56
49
}
57
- machineListByType .clear ();
58
50
machineSet .clear ();
59
51
}
60
52
61
53
public void setTo (StepState input ) {
62
- machineListByType = new HashMap <>(input .machineListByType );
63
54
machineSet = new TreeSet <>(input .machineSet );
64
55
machineLocalStates = new HashMap <>(input .machineLocalStates );
65
56
assert (machineSet .size () == machineLocalStates .size ());
@@ -80,10 +71,6 @@ public void setTo(StepState input) {
80
71
* @param machine Machine to add
81
72
*/
82
73
public void makeMachine (PMachine machine ) {
83
- if (!machineListByType .containsKey (machine .getClass ())) {
84
- machineListByType .put (machine .getClass (), new ArrayList <>());
85
- }
86
- machineListByType .get (machine .getClass ()).add (machine );
87
74
machineSet .add (machine );
88
75
}
89
76
@@ -94,7 +81,13 @@ public void makeMachine(PMachine machine) {
94
81
* @return Number of machine of a given type
95
82
*/
96
83
public int getMachineCount (Class <? extends PMachine > type ) {
97
- return machineListByType .getOrDefault (type , new ArrayList <>()).size ();
84
+ int result = 0 ;
85
+ for (PMachine m : machineSet ) {
86
+ if (type .isInstance (m )) {
87
+ result ++;
88
+ }
89
+ }
90
+ return result ;
98
91
}
99
92
100
93
@ Override
0 commit comments