public class BookFactory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
bookFilename |
private java.util.List<Book> |
books |
private int |
id |
Constructor and Description |
---|
BookFactory()
Create a new empty BookFactory
|
BookFactory(java.lang.String bookFilename)
Create a new BookFactory and fill it with information from a JSON file
|
Modifier and Type | Method and Description |
---|---|
Book |
getBook(int index)
Looks for a Book with the given id
|
Book |
getBook(java.lang.String title)
Linear search through the array list for Book with the given Title
|
(package private) Book |
newBook(java.lang.String title,
java.lang.String status)
Adds a new Book into this class
|
private Book |
search(int index,
int start,
int end)
Recursive binary search through the array list for the Book with the given id
|
(package private) void |
setBookFileName(java.lang.String bookFilename)
Update the output filename for the object
|
(package private) void |
toJsonFile()
Output the data into a JSON file replacing the input file (or if filename not given, "books.json")
|
void |
update(Book oldBook,
Book newBook)
Replacing a Book in the array list with a new Book
|
private java.lang.String bookFilename
private java.util.List<Book> books
private int id
public BookFactory()
public BookFactory(java.lang.String bookFilename)
bookFilename
- Name of the input JSON filepublic Book getBook(int index)
index
- id of the Book to be foundpublic Book getBook(java.lang.String title)
title
- Title of the Book to be foundBook newBook(java.lang.String title, java.lang.String status)
title
- Title of the Bookstatus
- Status of the Bookprivate Book search(int index, int start, int end)
index
- id of the Book to be foundstart
- Starting point to searchend
- Ending point to searchvoid setBookFileName(java.lang.String bookFilename)
bookFilename
- The new filenamevoid toJsonFile()