import java.util.LinkedList; public class Library { private LinkedList liste; // ‾‾‾‾‾‾ -> Medium für E eingesetzt (Generics) public Library() { liste = new LinkedList(); // leere Liste anlegen } public void add(Medium b) { if (!liste.contains(b)) // 1. Prüfe, ob enthalten liste.add(b); } public Medium get(long id) { //for (int i = 0; i < liste.size(); i++) { // Book b = liste.get(i); for (Medium b : liste) if (b.getIdNr() == id) return b; return null; } public boolean delete(Medium b) { return liste.remove(b); } public LinkedList getBooksWrittenBy(String author) { if (author == null) return new LinkedList(); LinkedList found = new LinkedList(); for (Medium m : liste) { if (m instanceof Book) { Book b = (Book) m; if (author.equals(b.getAutor())) found.add(b); } } return found; } }