import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; public class HistoryCommand11 implements Command11 { private static final Logger logger = Logger.getLogger(HistoryCommand11.class.getName()); private final List commandHistory = new ArrayList<>(); @Override public String getName() { return "history"; } @Override public void execute(String[] args, List articles) { if (commandHistory.isEmpty()) { logger.info("暂无命令历史记录"); System.out.println("暂无命令历史记录"); return; } logger.info("用户查看命令历史"); System.out.println("===== 命令历史 ====="); for (int i = 0; i < commandHistory.size(); i++) { System.out.println((i + 1) + ". " + commandHistory.get(i)); } } public void addCommand(String cmd) { commandHistory.add(cmd); } }