diff --git a/w8/AI架构审计.png b/w8/AI架构审计.png new file mode 100644 index 0000000..78377d6 Binary files /dev/null and b/w8/AI架构审计.png differ diff --git a/w8/Article.java b/w8/Article.java new file mode 100644 index 0000000..b79d3b5 --- /dev/null +++ b/w8/Article.java @@ -0,0 +1,45 @@ +package com.example.datacollect.model; + +public class Article { + private String title; + private String url; + private String content; + private String author; // 新增 + private String publishDate; // 新增 + + // 更新构造器,加入新字段 + public Article(String title, String url, String content, String author, String publishDate) { + this.title = title; + this.url = url; + this.content = content; + this.author = author; + this.publishDate = publishDate; + } + + // 原有的 getter/setter 保持不变 + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + + public String getUrl() { return url; } + public void setUrl(String url) { this.url = url; } + + public String getContent() { return content; } + public void setContent(String content) { this.content = content; } + + // 新增 getter/setter + public String getAuthor() { return author; } + public void setAuthor(String author) { this.author = author; } + + public String getPublishDate() { return publishDate; } + public void setPublishDate(String publishDate) { this.publishDate = publishDate; } + + @Override + public String toString() { + return "Article{" + + "title='" + title + '\'' + + ", url='" + url + '\'' + + ", author='" + author + '\'' + + ", publishDate='" + publishDate + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/w8/CrawlerController.java b/w8/CrawlerController.java new file mode 100644 index 0000000..34e196b --- /dev/null +++ b/w8/CrawlerController.java @@ -0,0 +1,54 @@ +package com.example.datacollect.controller; + +import com.example.datacollect.command.Command; +import com.example.datacollect.command.CrawlCommand; +import com.example.datacollect.command.ExitCommand; +import com.example.datacollect.command.HelpCommand; +import com.example.datacollect.command.HistoryCommand; +import com.example.datacollect.command.ListCommand; +import com.example.datacollect.model.Article; +import com.example.datacollect.view.ConsoleView; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CrawlerController { + private final Map commands = new HashMap<>(); + private final ConsoleView view; + private final List
articles; + private final List history = new ArrayList<>(); // 新增 + + public CrawlerController(ConsoleView view, List
articles) { + this.view = view; + this.articles = articles; + register(new HelpCommand(view)); + register(new ListCommand(view)); + register(new CrawlCommand(view)); + register(new ExitCommand(view)); + register(new HistoryCommand(history)); // 新增 + } + + private void register(Command command) { + commands.put(command.getName(), command); + } + + public void handle(String input) { + String text = input == null ? "" : input.trim(); + if (text.isEmpty()) { + return; + } + + history.add(text); // 新增:每次输入都记录 + + String[] args = text.split("\\s+"); + String cmdName = args[0].toLowerCase(); + Command command = commands.get(cmdName); + if (command == null) { + view.printError("Unknown command: " + cmdName); + return; + } + command.execute(args, articles); + } +} \ No newline at end of file diff --git a/w8/HistoryCommand.java b/w8/HistoryCommand.java new file mode 100644 index 0000000..282edca --- /dev/null +++ b/w8/HistoryCommand.java @@ -0,0 +1,30 @@ +package com.example.datacollect.command; + +import com.example.datacollect.model.Article; +import java.util.List; + +public class HistoryCommand implements Command { + + private List history; // 存储所有历史命令 + + public HistoryCommand(List history) { + this.history = history; + } + + @Override + public String getName() { + return "history"; + } + + @Override + public void execute(String[] args, List
articles) { + if (history.isEmpty()) { + System.out.println("No command history yet."); + } else { + System.out.println("Command History:"); + for (int i = 0; i < history.size(); i++) { + System.out.println(" " + (i + 1) + ". " + history.get(i)); + } + } + } +}