public Book getBookFromCSV(String line) { Book b = new Book(); StringTokenizer st = new StringTokenizer(line, ";"); b.setTitle(st.nextToken()); b.setNbPage(Integer.parseInt(st.nextToken())); b.setPrice(Double.parseDouble(st.nextToken())); b.setId(Integer.parseInt(st.nextToken())); return b; }
@Override public List<Book> getByPrice(double price) throws IOException { // TODO Auto-generated method stub List<Book> bookList = new ArrayList<Book>(); for (Book b : getCache()) { if (b.getPrice() <= price) bookList.add(b); } return bookList; }
@Override public List<Book> getByTitle(String word) throws IOException { // TODO Auto-generated method stub List<Book> bookList = new ArrayList<Book>(); for (Book b : getCache()) { if (b.getTitle().matches("(?i).*" + word + ".*")) { // (?i) = CASE_INSENSITIVE bookList.add(b); } } return bookList; }
@Override public Book getById(int id) throws IOException { // TODO Auto-generated method stub Book bookFound = null; for (Book b : getCache()) { if (b.getId() == id) { bookFound = b; } } return bookFound; }