org.jwalk.test
Class ReservableBook

java.lang.Object
  extended by org.jwalk.test.LibraryBook
      extended by org.jwalk.test.ReservableBook

public class ReservableBook
extends LibraryBook

A more sophisticated ReservableBook also supports reservations and cancellations. One reservation at a time is allowed. The object introduces orthogonal Default and Reserved states; these combine with the inherited states of LibraryBook to produce four distinct states: Default, OnLoan, Reserved and Reserved&OnLoan.

Version:
1.0
Author:
Anthony Simons

Constructor Summary
ReservableBook()
          Constructs a ReservableBook in its default state.
 
Method Summary
 void cancel()
          Cancels an existing reservation.
 java.lang.String getRequester()
          Returns the name of the current requester, or null.
 boolean isReserved()
          Reports if this ReservableBook has been reserved.
 void issue(java.lang.String person)
          Issues this ReservableBook to the named person, if allowed.
 void reserve(java.lang.String person)
          Reserves this ReservableBook for the named person.
 
Methods inherited from class org.jwalk.test.LibraryBook
discharge, getBorrower, isOnLoan
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReservableBook

public ReservableBook()
Constructs a ReservableBook in its default state.

Method Detail

issue

public void issue(java.lang.String person)
           throws java.lang.Exception
Issues this ReservableBook to the named person, if allowed. The rules for issuing are more complex. Not only must the book not already be on loan; but if it has been previously reserved, it may only be issued to the requester who reserved it.

Overrides:
issue in class LibraryBook
Throws:
java.lang.Exception

reserve

public void reserve(java.lang.String person)
             throws java.lang.Exception
Reserves this ReservableBook for the named person. Only one reservation at a time is allowed.

Throws:
java.lang.Exception

cancel

public void cancel()
Cancels an existing reservation. Has no effect if this ReservableBook has not been reserved (a null operation).


getRequester

public java.lang.String getRequester()
Returns the name of the current requester, or null.


isReserved

public boolean isReserved()
Reports if this ReservableBook has been reserved.