The inventory interface is BookInventory
. Package declaration, imports, and Javadocs have been removed for clarity:
public interface BookInventory { enum SearchCriteria { ISBN_LIKE, TITLE_LIKE, AUTHOR_LIKE, GROUP_LIKE, GRADE_GT, GRADE_LT } Set<String> getCategories(); MutableBook createBook(String isbn) throws BookAlreadyExistsException;; MutableBook loadBookForEdit(String isbn) throws BookNotFoundException; String storeBook(MutableBook book) throws InvalidBookException; Book loadBook(String isbn) throws BookNotFoundException; void removeBook(String isbn) throws BookNotFoundException; Set<String> searchBooks( Map<SearchCriteria, String> criteria); }
The method getCategories
gives back the list of book categories.
The method createBook
is the factory method. It is used to create a new book for a given ISBN and throws a BookAlreadyExistsException
if a book with that ISBN is already inventoried. The loadBookForEdit
method will retrieve a book that's already created or throw a BookNotFoundException
if the book is not in the inventory.
Both of these methods will return a MutableBook
as the intention is to edit the book and then store it using the storeBook
method.
The storeBook
method saves changes made to a book. It will check that the book has all mandatory attributes set and throw an InvalidBookException
if it's not the case. It returns the ISBN of the book that was stored.
The loadBook
method loads an existing book, given its ISBN reference. It returns a read-only Book
or throws a BookNotFoundException
if no book was previously stored with this particular ISBN reference.
The removeBook
method removes a book from the inventory, based on its ISBN reference, or throws a BookNotFoundException
, if no book was previously stored with this ISBN reference.
The exceptions are straightforward and are not listed here.
The searchBooks
method finds the books in the bookshelf that match a given set of criteria. It returns the set of ISBNs for the books that match the search criteria. They are as follows:
ISBN_LIKE
to filter on ISBN. For example, "123-%" and "%987", would include books with ISBN starting with "123-" and ending with "987" respectivelyTITLE_LIKE
to filter on titleAUTHOR_LIKE
to filter on authorCATEGORY_LIKE
to filter on book categoryRATING_GT
to include books with a rating greater than that of a given valueRATING_LT
to include books with a rating lesser than that of a given valueFor example, if we want to search for all books from "John Doe", which we assigned a grade higher than 5, we would call:
Map<SearchCriteria, String> criteria = new HashMap<SearchCriteria, String>(); crits.put(SearchCriteria.AUTHOR_LIKE, "John Doe"); crits.put(SearchCriteria.GRADE_GT, "5"); Set<String> results = impl.searchBooks(crits);
3.145.35.194