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.

32 lines
890 B

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ArticleRepository {
private final List<Article2> articles = new ArrayList<>();
public void add(Article2 article) {
if (article == null) throw new IllegalArgumentException("文章不能为空");
articles.add(article);
}
public void addAll(List<Article2> newArticles) {
if (newArticles == null) throw new IllegalArgumentException("列表不能为空");
for (Article2 a : newArticles) {
if (a == null) throw new IllegalArgumentException("列表中不能有空对象");
articles.add(a);
}
}
public List<Article2> getAll() {
return Collections.unmodifiableList(articles);
}
public int size() {
return articles.size();
}
public void clear() {
articles.clear();
}
}