You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
package com.rental.crawler.repository;
|
|
|
|
import com.rental.crawler.model.Book;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class ArticleRepository {
|
|
private List<Book> articles;
|
|
|
|
public ArticleRepository() {
|
|
this.articles = new ArrayList<>();
|
|
}
|
|
|
|
public ArticleRepository(List<Book> articles) {
|
|
this.articles = articles != null ? new ArrayList<>(articles) : new ArrayList<>();
|
|
}
|
|
|
|
public void add(Book article) {
|
|
if (article != null) {
|
|
this.articles.add(article);
|
|
}
|
|
}
|
|
|
|
public void addAll(List<Book> newArticles) {
|
|
if (newArticles == null) {
|
|
return;
|
|
}
|
|
for (Book article : newArticles) {
|
|
if (article != null) {
|
|
this.articles.add(article);
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<Book> findAll() {
|
|
return new ArrayList<>(this.articles);
|
|
}
|
|
|
|
public Book findByIndex(int index) {
|
|
if (index >= 0 && index < this.articles.size()) {
|
|
return this.articles.get(index);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int size() {
|
|
return this.articles.size();
|
|
}
|
|
|
|
public void clear() {
|
|
this.articles.clear();
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return this.articles.isEmpty();
|
|
}
|
|
}
|