models
Class FloorButtonsInElevator

java.lang.Object
  extended by models.FloorButtonsInElevator
All Implemented Interfaces:
HasInvariant

public class FloorButtonsInElevator
extends java.lang.Object
implements HasInvariant

Tested by JUnit_FloorButtonsInElevator and Validation_FloorButtonsInElevator
For managing the state of the floor requests inside the elevator (see ElevatorSpecification)

Version:
1
Author:
J Paul Gibson

Constructor Summary
FloorButtonsInElevator(int numberOfFloors)
          Initialises all floor requests (inside the elevator) to be false
 
Method Summary
 void cancelFloorRequestInElevator(int floor)
          Tested by JUnit_FloorButtonsInElevator.test_presses_cancels() Update the state when a request for the specified floor has been served
 boolean floorPressedInElevator(int floor)
          Tested by JUnit_FloorButtonsInElevator.test_presses_cancels()
 boolean invariant()
          The following safety conditions are required: number of floors must be at least 2 the number of floor buttons is the same as the number of floors Tested by JUnit_FloorButtonsInElevator.test_invariant()
 boolean noMoreRequestsAbove(int floor)
          Tested by JUnit_FloorButtonsInElevator.test_noMoreRequestsAbove()
 boolean noMoreRequestsBelow(int floor)
          Tested by JUnit_FloorButtonsInElevator.test_noMoreRequestsBelow()
 void pressFloorInElevator(int floor)
          Tested by JUnit_FloorButtonsInElevator.test_presses_cancels() Update the state when a request is made for the specified floor (inside the elevator)
 java.lang.String toString()
          Tested by JUnit_FloorButtonsInElevator.test_toString()
Lists the floors that have been requested inside the elevator
Typical output is of the form:
Requested Floors Inside Elevator: 2 4 7 In this example, the floors requested (2,4 and 7) are listed in order and separated by single spaces
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FloorButtonsInElevator

public FloorButtonsInElevator(int numberOfFloors)
                       throws java.lang.IllegalArgumentException
Initialises all floor requests (inside the elevator) to be false

Parameters:
numberOfFloors - is the number of floors in the lift system
Throws:
java.lang.IllegalArgumentException - if the number of floors is <=1
InvariantBroken - if not initialised in a safe state
Method Detail

cancelFloorRequestInElevator

public void cancelFloorRequestInElevator(int floor)
                                  throws java.lang.IllegalArgumentException
Tested by JUnit_FloorButtonsInElevator.test_presses_cancels() Update the state when a request for the specified floor has been served

Parameters:
floor -
Throws:
java.lang.IllegalArgumentException - if the number of floors specified is not in range

floorPressedInElevator

public boolean floorPressedInElevator(int floor)
                               throws java.lang.IllegalArgumentException
Tested by JUnit_FloorButtonsInElevator.test_presses_cancels()

Parameters:
floor -
Returns:
Whether there is currently a request to go to the specified floor (inside the elevator)
Throws:
java.lang.IllegalArgumentException - if the number of floors specified is not in range

invariant

public boolean invariant()
The following safety conditions are required: Tested by JUnit_FloorButtonsInElevator.test_invariant()

Specified by:
invariant in interface HasInvariant
Returns:
true if all these safety conditions are met, and false otherwise.

noMoreRequestsAbove

public boolean noMoreRequestsAbove(int floor)
                            throws java.lang.IllegalArgumentException
Tested by JUnit_FloorButtonsInElevator.test_noMoreRequestsAbove()

Parameters:
floor -
Returns:
whether there is a request for a floor (inside the elevator) above the specified floor
Throws:
java.lang.IllegalArgumentException - if the number of floors specified is not in range

noMoreRequestsBelow

public boolean noMoreRequestsBelow(int floor)
                            throws java.lang.IllegalArgumentException
Tested by JUnit_FloorButtonsInElevator.test_noMoreRequestsBelow()

Parameters:
floor -
Returns:
whether there is a request for a floor (inside the elevator) above the specified floor
Throws:
java.lang.IllegalArgumentException - if the number of floors specified is not in range

pressFloorInElevator

public void pressFloorInElevator(int floor)
                          throws java.lang.IllegalArgumentException
Tested by JUnit_FloorButtonsInElevator.test_presses_cancels() Update the state when a request is made for the specified floor (inside the elevator)

Parameters:
floor -
Throws:
java.lang.IllegalArgumentException - if the number of floors specified is not in range

toString

public java.lang.String toString()
Tested by JUnit_FloorButtonsInElevator.test_toString()
Lists the floors that have been requested inside the elevator
Typical output is of the form:
 Requested Floors Inside Elevator: 2 4 7
 
In this example, the floors requested (2,4 and 7) are listed in order and separated by single spaces

Overrides:
toString in class java.lang.Object