You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
992 B

package command;
import controller.CrawlerController;
import java.util.List;
import model.Article;
public class ListCommand implements Command {
private CrawlerController controller;
public ListCommand(CrawlerController controller) {
this.controller = controller;
}
@Override
public void execute() {
List<Article> articles = controller.getArticles();
if (articles.isEmpty()) {
controller.getView().showMessage("暂无数据");
return;
}
controller.getView().showMessage("\n已爬取的数据列表:");
for (int i = 0; i < articles.size(); i++) {
Article article = articles.get(i);
controller.getView().showMessage(
String.format("[%d] %s - %s", i + 1, article.getSource(), article.getTitle())
);
}
}
@Override
public String getDescription() {
return "显示已爬取的数据列表";
}
}