package com.example.datacollect.repository; import com.example.datacollect.model.Article; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArticleRepository { private final List
articles = new ArrayList<>(); public void add(Article article) { if (article == null) { throw new IllegalArgumentException("Article cannot be null"); } articles.add(article); } public void addAll(List
articleList) { if (articleList == null) { throw new IllegalArgumentException("列表不能为 null"); } for (Article article : articleList) { add(article); // 复用上面的 add,自动防 null } } public List
getAll() { return Collections.unmodifiableList(articles); } public int size() { return articles.size(); } public void clear() { articles.clear(); } }