-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookMapperBackend.java
72 lines (56 loc) · 1.82 KB
/
BookMapperBackend.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.ArrayList;
import java.util.List;
/**
* This class helps you edit and get the books in the HastableMap of books
*/
public class BookMapperBackend extends IterableHashtableMap<String,IBook> implements IBookMapperBackend {
//creating a HashTable of Books with unique title, author and isbn
public IterableHashtableMap<String, IBook> bookList = new IterableHashtableMap<>();
public String authorFilter;
@Override
public void addBook(IBook book) {
bookList.put(book.getISBN13(), book);
}
@Override
public int getNumberOfBooks() {
return bookList.size();
}
@Override
public void setAuthorFilter(String filterBy) {
this.authorFilter = filterBy;
}
@Override
public String getAuthorFilter() {
if (authorFilter.isEmpty()) {
return null;
}
return authorFilter;
}
@Override
public void resetAuthorFilter() {
setAuthorFilter(null);
}
@Override
public List<IBook> searchByTitleWord(String word) {
List<IBook> titleList = new ArrayList<>();
while (bookList.iterator().hasNext()) {
IBook book = (IBook) bookList.iterator();
String title = book.getTitle();
if (title.toLowerCase().contains(word.toLowerCase())
&& book.getAuthors() == null) {
titleList.add((IBook)(bookList).iterator());
} else if (title.toLowerCase().contains(word.toLowerCase())
&& book.getAuthors() != null) {
titleList.add((IBook) (bookList).iterator());
}
}
return titleList;
}
@Override
public IBook getByISBN(String ISBN) {
if (!bookList.containsKey(ISBN)) {
return null;
}
return bookList.get(ISBN);
}
}