clean up some whitespace

This commit is contained in:
cyril-colin 2019-10-14 08:46:59 +02:00
parent 26d9057e85
commit afeb28bc1e
3 changed files with 58 additions and 58 deletions

View File

@ -5,59 +5,59 @@ import Requests.CallFromFloorRequest;
public class Test { public class Test {
private static boolean running = false; private static boolean running = false;
private static EventQueue queue; private static EventQueue queue;
private static TestElevator elevator = new TestElevator(); private static TestElevator elevator = new TestElevator();
public static void iter() { public static void iter() {
int nextDestination = queue.getNextInstruction(); int nextDestination = queue.getNextInstruction();
//System.out.println("next dest = " + nextDestination); //System.out.println("next dest = " + nextDestination);
if (!running) { if (!running) {
if (nextDestination > 0) { // return -1 if no next destination if (nextDestination > 0) { // return -1 if no next destination
running = true; running = true;
elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
} }
} else { } else {
if (elevator.currentFloor == nextDestination) { if (elevator.currentFloor == nextDestination) {
queue.removeInstruction(elevator.currentFloor, elevator.direction); queue.removeInstruction(elevator.currentFloor, elevator.direction);
running = false; running = false;
} else { } else {
elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1; elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1;
} }
} }
System.out.println("elevator floor " + elevator.currentFloor + " direction " + System.out.println("elevator floor " + elevator.currentFloor + " direction " +
(elevator.direction == Direction.UP? "up" : "down") + " running: " + running); (elevator.direction == Direction.UP? "up" : "down") + " running: " + running);
} }
public static void main(String[] args) { public static void main(String[] args) {
queue = new EventQueue(elevator); queue = new EventQueue(elevator);
iter(); iter();
iter(); iter();
queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN)); queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN));
iter(); iter();
System.out.println("someone calls from floor 2 to go down"); System.out.println("someone calls from floor 2 to go down");
iter(); iter();
queue.computeRequest(new CallFromFloorRequest(1, Direction.UP)); queue.computeRequest(new CallFromFloorRequest(1, Direction.UP));
System.out.println("someone calls from floor 1 to go up"); System.out.println("someone calls from floor 1 to go up");
iter(); iter();
queue.computeRequest(new CallFromElevatorRequest(5)); queue.computeRequest(new CallFromElevatorRequest(5));
System.out.println("the guy who entered calls for floor 5"); System.out.println("the guy who entered calls for floor 5");
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
iter(); iter();
} }
} }