Exemplo n.º 1
0
 public List<Book> booksForTitlePrefix(String prefix) {
   final LinkedList<Book> filtered = new LinkedList<Book>();
   for (Book b : books()) {
     if (prefix.equals(TitleUtil.firstTitleLetter(b))) {
       filtered.add(b);
     }
   }
   return filtered;
 }
Exemplo n.º 2
0
 public List<String> titlesForTitlePrefix(String prefix, int limit) {
   if (limit <= 0) {
     return Collections.emptyList();
   }
   final ArrayList<String> titles = new ArrayList<String>(limit);
   synchronized (myBooksByFile) {
     for (Book b : myBooksByFile.values()) {
       if (prefix.equals(TitleUtil.firstTitleLetter(b))) {
         titles.add(b.getTitle());
         if (--limit == 0) {
           break;
         }
       }
     }
   }
   return titles;
 }