@Override public Book getBookByID(String bookId) throws BookNotFoundException { Map<String, Book> books = module.getBooks(); Book result = books.get(bookId); if (result == null) { throw new BookNotFoundException(module.getID(), bookId); } return result; }
@Override public List<Book> getBooks() { Map<String, Book> books = module.getBooks(); ArrayList<Book> result = new ArrayList<Book>(books.size()); for (String bookID : books.keySet()) { result.add(books.get(bookID)); } return result; }
@Override public List<String> getChapterNumbers(String bookId) throws BookNotFoundException { ArrayList<String> result = new ArrayList<String>(); Book book = getBookByID(bookId); for (int i = 0; i < book.getChapterQty(); i++) { result.add("" + (i + (module.isChapterZero() ? 0 : 1))); } return result; }
@Override public Book getPrevBook(String bookId) throws BookNotFoundException { Book result = getBookByID(bookId); if (result == null) { throw new BookNotFoundException(module.getID(), bookId); } List<Book> books = getBooks(); int pos = books.indexOf(result); if (pos > 0) { return books.get(--pos); } return null; }