import java.util.ArrayList; import java.util.List; /** * 命令历史记录类(MVC-控制层辅助) */ public class HistoryCommand { // 私有化List,避免外部直接修改 private static final List commandList = new ArrayList<>(); // 新增命令记录 public static void addCommand(String command) { if (command != null && !command.trim().isEmpty()) { commandList.add(command); } } // 获取所有命令记录(返回副本,避免外部修改原集合) public static List getCommandList() { return new ArrayList<>(commandList); } // 清空命令记录 public static void clearHistory() { commandList.clear(); } }