コード例 #1
0
  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;
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
 @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;
 }
コード例 #4
0
  @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;
  }