Esempio n. 1
0
  public static List<Book> listBooksByTitleInfix(String titleInfix, int offset, int limit) {

    titleInfix = titleInfix.toLowerCase();

    int curOffset = 0;
    ArrayList<Book> result = new ArrayList<Book>(limit);

    for (int i = 0; i < STORE.size(); i++) {

      Book book = STORE.get(i);

      if (book.getTitle().toLowerCase().contains(titleInfix)) {
        if (curOffset >= offset) {
          result.add(book);
        }
        curOffset++;
      }

      if (result.size() == limit) {
        break;
      }
    }

    return result;
  }
Esempio n. 2
0
  public static Integer countBooksByTitleInfix(String infix) {

    int count = 0;
    infix = infix.toLowerCase();

    for (Book b : STORE) {
      if (b.getTitle().toLowerCase().contains(infix)) {
        count++;
      }
    }

    return count;
  }