nachos.machine
Interface ElevatorControls


public interface ElevatorControls

A set of controls that can be used by an elevator controller.


Method Summary
 void closeDoors(int elevator)
          Close an elevator's doors.
 void finish()
          Call when the elevator controller is finished.
 int getFloor(int elevator)
          Return the current location of the elevator.
 ElevatorEvent getNextEvent()
          Return the next event in the event queue.
 int getNumElevators()
          Return the number of elevators in the elevator bank.
 int getNumFloors()
          Return the number of floors in the elevator bank.
 boolean moveTo(int floor, int elevator)
          Move an elevator to another floor.
 void openDoors(int elevator)
          Open an elevator's doors.
 void setDirectionDisplay(int elevator, int direction)
          Set which direction the elevator bank will show for this elevator's display.
 void setInterruptHandler(Runnable handler)
          Set the elevator interrupt handler.
 

Method Detail

getNumFloors

int getNumFloors()
Return the number of floors in the elevator bank. If n is the number of floors in the bank, then the floors are numbered 0 (the ground floor) through n - 1 (the top floor).

Returns:
the number of floors in the bank.

getNumElevators

int getNumElevators()
Return the number of elevators in the elevator bank. If n is the number of elevators in the bank, then the elevators are numbered 0 through n - 1.

Returns:
the numbe rof elevators in the bank.

setInterruptHandler

void setInterruptHandler(Runnable handler)
Set the elevator interrupt handler. This handler will be called when an elevator event occurs, and when all the riders have reaced their destinations.

Parameters:
handler - the elevator interrupt handler.

openDoors

void openDoors(int elevator)
Open an elevator's doors.

Parameters:
elevator - which elevator's doors to open.

closeDoors

void closeDoors(int elevator)
Close an elevator's doors.

Parameters:
elevator - which elevator's doors to close.

moveTo

boolean moveTo(int floor,
               int elevator)
Move an elevator to another floor. The elevator's doors must be closed. If the elevator is already moving and cannot safely stop at the specified floor because it has already passed or is about to pass the floor, fails and returns false. If the elevator is already stopped at the specified floor, returns false.

Parameters:
floor - the floor to move to.
elevator - the elevator to move.
Returns:
true if the elevator's destination was changed.

getFloor

int getFloor(int elevator)
Return the current location of the elevator. If the elevator is in motion, the returned value will be within one of the exact location.

Parameters:
elevator - the elevator to locate.
Returns:
the floor the elevator is on.

setDirectionDisplay

void setDirectionDisplay(int elevator,
                         int direction)
Set which direction the elevator bank will show for this elevator's display. The direction argument should be one of the dir* constants in the ElevatorBank class.

Parameters:
elevator - the elevator whose direction display to set.
direction - the direction to show (up, down, or neither).

finish

void finish()
Call when the elevator controller is finished.


getNextEvent

ElevatorEvent getNextEvent()
Return the next event in the event queue. Note that there may be multiple events pending when an elevator interrupt occurs, so this method should be called repeatedly until it returns null.

Returns:
the next event, or null if no further events are currently pending.