From 3dddcec002dbc3818bccacf994f34127b41220f3 Mon Sep 17 00:00:00 2001 From: zhangsiyuan <3837703520@qq.com> Date: Thu, 7 May 2026 17:37:42 +0800 Subject: [PATCH] =?UTF-8?q?w10-=E5=BC=A0=E6=80=9D=E6=B8=8A-202401070104?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w10/ArticleRepository.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 w10/ArticleRepository.java diff --git a/w10/ArticleRepository.java b/w10/ArticleRepository.java new file mode 100644 index 0000000..dcde405 --- /dev/null +++ b/w10/ArticleRepository.java @@ -0,0 +1,38 @@ +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 List
getAll() { + return Collections.unmodifiableList(articles); + } + + public int size() { + return articles.size(); + } + + public void addAll(List
articleList) { + if (articleList == null) { + throw new IllegalArgumentException("Article list cannot be null"); + } + for (Article article : articleList) { + add(article); + } + } + + public void clear() { + articles.clear(); + } +}