Class BookDatabase

java.lang.Object
edu.pdx.cs410J.di.JaxbDatabase
edu.pdx.cs410J.di.BookDatabase
All Implemented Interfaces:
BookInventory

public class BookDatabase extends JaxbDatabase implements BookInventory
An implementation of BookInventory that stores a database of books in a flat file
  • Constructor Details

    • BookDatabase

      @Inject public BookDatabase(@DataDirectory File directory) throws jakarta.xml.bind.JAXBException, IOException
      Creates a new database of books stored in a file named "books.xml"
      Parameters:
      directory - The directory in which the data file will reside
      Throws:
      IOException - If the data file cannot be created
      jakarta.xml.bind.JAXBException - If we cannot create the XML context
    • BookDatabase

      BookDatabase(File directory, String fileName) throws IOException, jakarta.xml.bind.JAXBException
      Creates a new database of books. This method is package-protected for testing purposes.
      Parameters:
      directory - The directory in which the data file will reside
      fileName - The name of the file to store the book inventory
      Throws:
      IOException - If the data file cannot be created
      jakarta.xml.bind.JAXBException - If we cannot create the XML context
  • Method Details

    • remove

      public void remove(Book book)
      Description copied from interface: BookInventory
      Removes a book from the inventory
      Specified by:
      remove in interface BookInventory
      Parameters:
      book - The book to remove
    • add

      public void add(Book... books)
      Description copied from interface: BookInventory
      Adds some books to the inventory
      Specified by:
      add in interface BookInventory
      Parameters:
      books - A bunch of bookx
    • getCopies

      public int getCopies(Book book)
      Description copied from interface: BookInventory
      Returns the number of copies of the given book in the inventory
      Specified by:
      getCopies in interface BookInventory
      Parameters:
      book - The book of interest
      Returns:
      the number of copies of book
    • getBooks

      public Set<Book> getBooks()
      Description copied from interface: BookInventory
      Returns all of the books in this inventory
      Specified by:
      getBooks in interface BookInventory
      Returns:
      all of the books in this inventory