clean up some whitespace
This commit is contained in:
parent
26d9057e85
commit
afeb28bc1e
@ -2,7 +2,7 @@ package commandSystem;
|
||||
|
||||
public interface Elevator {
|
||||
|
||||
|
||||
|
||||
public void sendFloorReachedNotification();
|
||||
public int getCurrentFloor();
|
||||
public Direction getCurrentDirection();
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user