correction bugs instructionqueue
This commit is contained in:
parent
0541b38e50
commit
2ed258e60e
@ -20,7 +20,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
||||
downQueue = new ArrayList<Integer>();
|
||||
emergencyState = false;
|
||||
currentFloor = 0;
|
||||
currentDirection = Direction.NONE;
|
||||
currentDirection = Direction.UP;
|
||||
}
|
||||
|
||||
public void computeEvent(Event event) {
|
||||
@ -64,7 +64,7 @@ public class BasicInstructionQueue implements InstructionQueue {
|
||||
/*
|
||||
* If the requested floor is under the elevator, adds the instruction to the
|
||||
* downQueue then sorts it. if it's above, adds the instruction to the upQueue
|
||||
* then sorts it. If it's the same floor, doesn't do anything
|
||||
* then sorts it. If it's the same floor, doesn't do anything.
|
||||
*/
|
||||
case CALLFROMELEVATOR:
|
||||
if (event.getRequestedFloor() > currentFloor && !upQueue.contains(event.getRequestedFloor()))
|
||||
@ -110,6 +110,9 @@ public class BasicInstructionQueue implements InstructionQueue {
|
||||
*/
|
||||
public int getNextInstruction() {
|
||||
int nextFloor = -1;
|
||||
|
||||
//System.out.println("" + upQueue + downQueue);
|
||||
|
||||
switch (currentDirection) {
|
||||
// get the first element of upQueue that is ABOVE the elevator's current floor
|
||||
case UP:
|
||||
|
@ -9,19 +9,22 @@ public class Test {
|
||||
private static boolean running = false;
|
||||
private static InstructionQueue queue;
|
||||
|
||||
private static Direction currentDirection;
|
||||
private static int currentFloor;
|
||||
private static Direction currentDirection = Direction.UP;
|
||||
private static int currentFloor = 0;
|
||||
|
||||
public static void iter() {
|
||||
int nextDestination = queue.getNextInstruction();
|
||||
|
||||
if (!running) {
|
||||
// would be -1 if the queue doesn't have any next instruction
|
||||
|
||||
//System.out.println("next dest : " + nextDestination);
|
||||
if (nextDestination != -1) {
|
||||
running = true;
|
||||
currentDirection = currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
|
||||
}
|
||||
} else {
|
||||
//System.out.println("not running");
|
||||
// if we just reached a new floor
|
||||
if (currentFloor == nextDestination) {
|
||||
queue.computeEvent(new ReachedFloorEvent(currentFloor, currentDirection));
|
||||
@ -32,16 +35,14 @@ public class Test {
|
||||
}
|
||||
}
|
||||
System.out.println("elevator floor " + currentFloor + " direction " +
|
||||
(currentDirection == Direction.UP? "up" : "down") + " running: " + running);
|
||||
(currentDirection) + " running: " + running);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//TODO envoyer les notifs de changements d'étages
|
||||
queue = new BasicInstructionQueue();
|
||||
iter();
|
||||
iter();
|
||||
queue.computeEvent(new CallFromFloorEvent(2, Direction.DOWN));
|
||||
iter();
|
||||
System.out.println("someone calls from floor 2 to go down");
|
||||
iter();
|
||||
queue.computeEvent(new CallFromFloorEvent(1, Direction.UP));
|
||||
|
Reference in New Issue
Block a user