diff --git a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java index b6452cb..7d7b6d0 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/PublicBookManager.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.regex.*; @@ -13,13 +14,10 @@ @Repository public class PublicBookManager implements IBookListener{ - private final BookManager bookManager; - private final HashMap> publicBooks = new HashMap<>(); public PublicBookManager(BookManager bookManager) { - this.bookManager = bookManager; - this.bookManager.addListener(this); + bookManager.addListener(this); } public ArrayList getAllPublicBooks(){ @@ -43,7 +41,13 @@ return books; } + public ArrayList searchBooksByTitle(String title, int sortBy){ + if(sortBy == 0){ + ArrayList result = searchBooksByTitle(title); + result.sort(Comparator.comparing(Book::getTime).reversed()); + return result; + } return null; } @@ -60,17 +64,23 @@ } public ArrayList searchBooksByAccount(String accountId, int sortBy){ + if(sortBy == 0){ + ArrayList result = searchBooksByAccount(accountId); + result.sort(Comparator.comparing(Book::getTime).reversed()); + return result; + } return null; } public ArrayList searchBooksByTitleAndAccount(String title, String accountId){ ArrayList books = searchBooksByTitle(title); + ArrayList result = new ArrayList<>(); for(Book book : books){ if(book.getAccountId().equals(accountId)){ - books.add(book); + result.add(book); } } - return books; + return result; } @Override