➊
if (booksByFilter.contains("publisher")) {
for (int j = 0; j < filter.get("publisher").size(); j++) {
String publisherName = filter.get("publisher").get(j);
for (int i = 0; i < listOfBooks.size(); i++) {
Book book = listOfBooks.get(i);
if (publisherName.equalsIgnoreCase(book.getPublisher()))
booksByPublisher.add(book);
}
}
}
➋
if (booksByFilter.contains("category")) {
for (int i = 0; i < filter.get("category").size(); i++) {
String category = filter.get("category").get(i);
List<Book> list = getBookListByCategory(category);
booksByCategory.addAll(list);
}
}
booksByCategory.retainAll(booksByPublisher); ➌
return booksByCategory;
}
}