Code:
int rating = 0;
Map<IBook, Integer> books = new HashMap<IBook, Integer>();
/**
* Add a rated book to the shelf.
*
* @param book
* the book to add
* @param rating
* how much did you like this book?
* @throws NullPointerException
* if book is null
*/
@Override
public void addBook(IBook book, int rating) {
if (book.getYear() < 1900) {
throw new IllegalArgumentException("release date < 1900");
}
if (book.getTitle().isEmpty()) {
throw new IllegalArgumentException("kein Buchtitel gebeben");
}
if (book.getAuthors() == null || book.getAuthors().isEmpty()) {
throw new IllegalArgumentException("keine Authoren vorhanden");
}
if (books.containsKey(book)) {
throw new IllegalArgumentException(
"Das selbe Buch ist schon Vorhanden");
}
for (Map.Entry<IBook, Integer> e : books.entrySet()) {
if (book.getAuthors().equals(e.getKey().getAuthors())
&& book.getTitle().equals(e.getKey().getTitle())
&& book.getYear() == e.getKey().getYear()) {
throw new IllegalArgumentException();
}
}