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