nachos.machine
Interface RiderControls


public interface RiderControls

A set of controls that can be used by a rider controller. Each rider uses a distinct RiderControls object.


Method Summary
 boolean enterElevator(int elevator)
          Enter an elevator.
 boolean exitElevator(int floor)
          Exit the elevator.
 void finish()
          Call when the rider is finished.
 int getDirectionDisplay(int elevator)
          Return the indicated direction of the specified elevator, set by ElevatorControls.setDirectionDisplay().
 int getFloor()
          Return the current location of the rider.
 int[] getFloors()
          Return an array specifying the sequence of floors at which this rider has successfully exited an elevator.
 RiderEvent 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 pressDirectionButton(boolean up)
          Press a direction button.
 boolean pressDownButton()
          Press the down button.
 boolean pressFloorButton(int floor)
          Press a floor button.
 boolean pressUpButton()
          Press the up button.
 void setInterruptHandler(Runnable handler)
          Set the rider's 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 rider's interrupt handler. This handler will be called when the rider observes an event.

Parameters:
handler - the rider's interrupt handler.

getFloor

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

Returns:
the floor the rider is on.

getFloors

int[] getFloors()
Return an array specifying the sequence of floors at which this rider has successfully exited an elevator. This array naturally does not count the floor the rider started on, nor does it count floors where the rider is in the elevator and does not exit.

Returns:
an array specifying the floors this rider has visited.

getDirectionDisplay

int getDirectionDisplay(int elevator)
Return the indicated direction of the specified elevator, set by ElevatorControls.setDirectionDisplay().

Parameters:
elevator - the elevator to check the direction of.
Returns:
the displayed direction for the elevator.
See Also:
ElevatorControls.setDirectionDisplay(int, int)

pressDirectionButton

boolean pressDirectionButton(boolean up)
Press a direction button. If up is true, invoke pressUpButton(); otherwise, invoke pressDownButton().

Parameters:
up - true to press the up button, false to press the down button.
Returns:
the return value of pressUpButton() or of pressDownButton().

pressUpButton

boolean pressUpButton()
Press the up button. The rider must not be on the top floor and must not be inside an elevator. If an elevator is on the same floor as this rider, has the doors open, and says it is going up, does nothing and returns false.

Returns:
true if the button event was sent to the elevator controller.

pressDownButton

boolean pressDownButton()
Press the down button. The rider must not be on the bottom floor and must not be inside an elevator. If an elevator is on the same floor as as this rider, has the doors open, and says it is going down, does nothing and returns false.

Returns:
true if the button event was sent to the elevator controller.

enterElevator

boolean enterElevator(int elevator)
Enter an elevator. A rider cannot enter an elevator if its doors are not open at the same floor, or if the elevator is full. The rider must not already be in an elevator.

Parameters:
elevator - the elevator to enter.
Returns:
true if the rider successfully entered the elevator.

pressFloorButton

boolean pressFloorButton(int floor)
Press a floor button. The rider must be inside an elevator. If the elevator already has its doors open on floor, does nothing and returns false.

Parameters:
floor - the button to press.
Returns:
true if the button event was sent to the elevator controller.

exitElevator

boolean exitElevator(int floor)
Exit the elevator. A rider cannot exit the elevator if its doors are not open on the requested floor. The rider must already be in an elevator.

Parameters:
floor - the floor to exit on.
Returns:
true if the rider successfully got off the elevator.

finish

void finish()
Call when the rider is finished.


getNextEvent

RiderEvent getNextEvent()
Return the next event in the event queue. Note that there may be multiple events pending when a rider 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.