diff --git a/src/commandSystem/BasicInstructionQueue.java b/src/commandSystem/BasicInstructionQueue.java index a8f76a7..7e54d7f 100644 --- a/src/commandSystem/BasicInstructionQueue.java +++ b/src/commandSystem/BasicInstructionQueue.java @@ -20,7 +20,7 @@ public class BasicInstructionQueue implements InstructionQueue { downQueue = new ArrayList(); 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: diff --git a/src/commandSystem/Test.java b/src/commandSystem/Test.java index df36959..7d260af 100644 --- a/src/commandSystem/Test.java +++ b/src/commandSystem/Test.java @@ -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));