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

@ -2,7 +2,7 @@ package commandSystem;
public interface Elevator { public interface Elevator {
public void sendFloorReachedNotification(); public void sendFloorReachedNotification();
public int getCurrentFloor(); public int getCurrentFloor();
public Direction getCurrentDirection(); public Direction getCurrentDirection();

View File

@ -4,60 +4,60 @@ import Requests.CallFromElevatorRequest;
import Requests.CallFromFloorRequest; import Requests.CallFromFloorRequest;
public class Test { public class Test {
private static boolean running = false;
private static EventQueue queue;
private static TestElevator elevator = new TestElevator();
public static void iter() { private static boolean running = false;
int nextDestination = queue.getNextInstruction(); private static EventQueue queue;
//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) { private static TestElevator elevator = new TestElevator();
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(); public static void iter() {
iter(); int nextDestination = queue.getNextInstruction();
iter(); //System.out.println("next dest = " + nextDestination);
iter(); if (!running) {
iter(); if (nextDestination > 0) { // return -1 if no next destination
iter(); running = true;
iter(); elevator.direction = elevator.currentFloor < nextDestination ? Direction.UP : Direction.DOWN;
iter(); }
iter(); } else {
iter(); if (elevator.currentFloor == nextDestination) {
iter(); queue.removeInstruction(elevator.currentFloor, elevator.direction);
iter(); 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();
}
}

View File

@ -4,13 +4,13 @@ public class TestElevator implements Elevator{
public int currentFloor; public int currentFloor;
public Direction direction; public Direction direction;
public TestElevator() { public TestElevator() {
this.direction = Direction.UP; this.direction = Direction.UP;
this.currentFloor = 0; this.currentFloor = 0;
} }
@Override @Override
public void sendFloorReachedNotification() { public void sendFloorReachedNotification() {
// TODO Auto-generated method stub // TODO Auto-generated method stub