From afeb28bc1ec9ccaf3bf1ac904d44cc107726aec1 Mon Sep 17 00:00:00 2001 From: cyril-colin Date: Mon, 14 Oct 2019 08:46:59 +0200 Subject: [PATCH] clean up some whitespace --- src/commandSystem/Elevator.java | 2 +- src/commandSystem/Test.java | 108 ++++++++++++++-------------- src/commandSystem/TestElevator.java | 6 +- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/commandSystem/Elevator.java b/src/commandSystem/Elevator.java index d97e8d3..63969f5 100644 --- a/src/commandSystem/Elevator.java +++ b/src/commandSystem/Elevator.java @@ -2,7 +2,7 @@ package commandSystem; public interface Elevator { - + public void sendFloorReachedNotification(); public int getCurrentFloor(); public Direction getCurrentDirection(); diff --git a/src/commandSystem/Test.java b/src/commandSystem/Test.java index 78d8f91..52d0d1b 100644 --- a/src/commandSystem/Test.java +++ b/src/commandSystem/Test.java @@ -4,60 +4,60 @@ import Requests.CallFromElevatorRequest; import Requests.CallFromFloorRequest; public class Test { - - private static boolean running = false; - private static EventQueue queue; - - private static TestElevator elevator = new TestElevator(); - public static void iter() { - int nextDestination = queue.getNextInstruction(); - //System.out.println("next dest = " + nextDestination); - if (!running) { - if (nextDestination > 0) { // return -1 if no next destination - running = true; - elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; - } - } else { - if (elevator.currentFloor == nextDestination) { - queue.removeInstruction(elevator.currentFloor, elevator.direction); - running = false; - } else { - elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; - elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1; - } - } - System.out.println("elevator floor " + elevator.currentFloor + " direction " + - (elevator.direction == Direction.UP? "up" : "down") + " running: " + running); - } + private static boolean running = false; + private static EventQueue queue; - public static void main(String[] args) { - queue = new EventQueue(elevator); - iter(); - iter(); - queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN)); - iter(); - System.out.println("someone calls from floor 2 to go down"); - iter(); - queue.computeRequest(new CallFromFloorRequest(1, Direction.UP)); - System.out.println("someone calls from floor 1 to go up"); - iter(); - - queue.computeRequest(new CallFromElevatorRequest(5)); - System.out.println("the guy who entered calls for floor 5"); + private static TestElevator elevator = new TestElevator(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - iter(); - - } -} \ No newline at end of file + public static void iter() { + int nextDestination = queue.getNextInstruction(); + //System.out.println("next dest = " + nextDestination); + if (!running) { + if (nextDestination > 0) { // return -1 if no next destination + running = true; + elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; + } + } else { + if (elevator.currentFloor == nextDestination) { + queue.removeInstruction(elevator.currentFloor, elevator.direction); + running = false; + } else { + elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN; + elevator.currentFloor += elevator.direction == Direction.UP ? 1 : -1; + } + } + System.out.println("elevator floor " + elevator.currentFloor + " direction " + + (elevator.direction == Direction.UP? "up" : "down") + " running: " + running); + } + + public static void main(String[] args) { + queue = new EventQueue(elevator); + iter(); + iter(); + queue.computeRequest(new CallFromFloorRequest(2, Direction.DOWN)); + iter(); + System.out.println("someone calls from floor 2 to go down"); + iter(); + queue.computeRequest(new CallFromFloorRequest(1, Direction.UP)); + System.out.println("someone calls from floor 1 to go up"); + iter(); + + queue.computeRequest(new CallFromElevatorRequest(5)); + System.out.println("the guy who entered calls for floor 5"); + + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + iter(); + + } +} diff --git a/src/commandSystem/TestElevator.java b/src/commandSystem/TestElevator.java index eab7e26..2b5052d 100644 --- a/src/commandSystem/TestElevator.java +++ b/src/commandSystem/TestElevator.java @@ -4,13 +4,13 @@ public class TestElevator implements Elevator{ public int currentFloor; public Direction direction; - + public TestElevator() { this.direction = Direction.UP; this.currentFloor = 0; } - - + + @Override public void sendFloorReachedNotification() { // TODO Auto-generated method stub