Java Reference
In-Depth Information
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Class representing a collection of {@link Book} objects. The {@code Book}
* objects are stored in a user-defined order, which defaults to insertion
* order. A given {@code Book} can also be specified by the user as
* <i>featured</i>, optionally with a <i>featured message</i>.
*/
public class Library {
private final List<Book> books = new ArrayList<>();
private final Map<Book, String> featuredBooks = new HashMap<>();
/**
* Adds a book to the end of the topics list.
*
* @param book The topic to add; may not be {@code null}.
*/
public void addBook(Book book) {
Objects.requireNonNull(book, "book to add");
this.books.add(book);
}
/**
* Adds a book to the end of the topics list, and adds it as a featured book
* with the given message.
*
* @param book The topic to add; may not be {@code null}.
* @param message The featured message, which may be {@code null}.
*/
public void addFeaturedBook(Book book, String message) {
this.addBook(book);
this.featuredBooks.put(book, message);
}
/**
* Provides direct access to the listing of books. Modifying the returned|
* collection will modify the topics in the library.
*
* @return The topics in this library; never {@code null}.
*/
public List<Book> getBooks() {
return this.books;
}
/**
* Provides direct access to the listing of featured books. Modifying the
* returned map will modify the featured books and their messages.
*
Search WWH ::




Custom Search