clean up some whitespace
This commit is contained in:
parent
26d9057e85
commit
afeb28bc1e
@ -5,59 +5,59 @@ import Requests.CallFromFloorRequest;
|
||||
|
||||
public class Test {
|
||||
|
||||
private static boolean running = false;
|
||||
private static EventQueue queue;
|
||||
private static boolean running = false;
|
||||
private static EventQueue queue;
|
||||
|
||||
private static TestElevator elevator = new TestElevator();
|
||||
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);
|
||||
}
|
||||
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();
|
||||
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");
|
||||
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();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
iter();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user