package class1_3_Interfaces;// Dr. Yoder. MSOE. 02 December 2016 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * This class represents a home (paper hardcopy) library collection */ public class Library { private List books = new ArrayList<>(); /** * Pull the book off of the shelf by the specific author. * @param author the full name of the person who wrote the book. * @return the requested book (or null if not found! * ... wish there was a better way to handle this....) */ public Book findByAuthor(String author) { int i = 0; Book found; while(i < books.size() && books.get(i).getAuthor().equals(author)) { i++; } if(i == books.size()) { found = null; } else { found = books.get(i); } return found; } /** * Add a set of books to the library. * Null references are skipped and not added to the library. * (Is there a better way to handle this?) * @param books the books to be added */ public void addBooks(List books) { if(books != null) { for (Book book : books) { if (book != null) { this.books.add(book); } } } } @Override public String toString() { String s = "Library:\n"; for(Book book: books) { s +=" " + book + "\n"; } return s; } // public void addBooks(LinkedList books) { // if(books != null) { // for (Book book : books) { // if (book != null) { // this.books.add(book); // } // } // } // } }