Appendix H Elevator Model (on (Web server hosting) CD) 1427 320

Appendix H Elevator Model (on CD) 1427 320 321 // get next DoorListener 322 while ( iterator.hasNext() ) { 323 324 // get next ElevatorMoveListener from Set 325 ElevatorMoveListener listener = 326 ( ElevatorMoveListener ) iterator.next(); 327 328 // send ElevatorMoveEvent to this listener 329 listener.elevatorDeparted( new ElevatorMoveEvent( 330 this, currentFloorLocation ) ); 331 332 } // end while loop 333 } // end method sendDepartureEvent 334 335 // request Elevator 336 public void requestElevator( Location location ) 337 { 338 // if Elevator is idle 339 if ( !isMoving() ) { 340 341 // if Elevator is on same Floor of request 342 if ( location == currentFloorLocation ) 343 344 // Elevator has already arrived; send arrival event 345 sendArrivalEvent( currentFloorLocation ); 346 347 // if Elevator is on opposite Floor of request 348 else { 349 350 if ( getDoor().isDoorOpen() ) 351 pauseThread( Door.AUTOMATIC_CLOSE_DELAY ); 352 setMoving( true ); // move to other Floor 353 } 354 } 355 else // if Elevator is moving 356 357 // if Elevator departed from same Floor as request 358 if ( location == currentFloorLocation ) 359 summoned = true; 360 36 // if Elevator is traveling to Floor of request, 36 // continue traveling 36 36 } // end method requestElevator 36 36 // invoked when bell has rung 36 public void bellRang( BellEvent bellEvent ) 36 { 36 // send event to bellListener 370 if ( bellListener != null ) 371 bellListener.bellRang( bellEvent ); Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 8 of 9).
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply