-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLaneManager.java
63 lines (50 loc) · 1.53 KB
/
LaneManager.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
import java.util.HashSet;
import java.util.Iterator;
public class LaneManager {
private ControlDesk controlDesk;
/** The collection of Lanes */
private HashSet<Lane> lanes;
/** The number of lanes represented */
private int numLanes;
public LaneManager(ControlDesk controlDesk, int numLanes) {
this.controlDesk = controlDesk;
this.lanes = new HashSet<>(numLanes);
this.numLanes = numLanes;
for (int i = 0; i < numLanes; i++) {
lanes.add(new Lane());
}
}
/**
* Iterate through the available lanes and assign the paties in the wait queue if lanes are available.
*
*/
public void assignLane() {
Iterator<Lane> it = lanes.iterator();
while (it.hasNext() && controlDesk.getWaitQueue().hasMoreElements()) {
Lane curLane = it.next();
if (!curLane.isPartyAssigned()) {
System.out.println("ok... assigning this party");
curLane.assignParty(((Party) controlDesk.getWaitQueue().next()));
}
}
controlDesk.publish(new PartyQueueEvent(controlDesk.getPartyQueue()));
}
/**
* Accessor for the number of lanes represented by the ControlDesk
*
* @return an int containing the number of lanes represented
*
*/
public int getNumLanes() {
return numLanes;
}
/**
* Accessor method for lanes
*
* @return a HashSet of Lanes
*
*/
public HashSet<Lane> getLanes() {
return lanes;
}
}