Browse Source

删除 'java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java'

main
Songrui 3 weeks ago
parent
commit
dc00b21643
  1. 58
      java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java

58
java-cli/src/main/java/com/example/datacollect/controller/CrawlerController.java

@ -1,58 +0,0 @@
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<String, Command> commands = new HashMap<>();
private final ConsoleView view;
private final List<Article> articles;
private final List<String> commandHistory;
public CrawlerController(ConsoleView view, List<Article> articles) {
this.view = view;
this.articles = articles;
this.commandHistory = new ArrayList<>();
register(new HelpCommand(view));
register(new ListCommand(view));
CrawlCommand crawlCommand = new CrawlCommand(view);
register(crawlCommand);
commands.put("c", crawlCommand);
register(new ExitCommand(view));
register(new HistoryCommand(view, commandHistory));
}
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;
}
commandHistory.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);
}
}
Loading…
Cancel
Save