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.
 
 

26 lines
931 B

package com.example.datacollect;
import java.util.ArrayList;
import java.util.List;
// 工具类:专门记录命令历史,属于MVC的辅助层
public class HistoryCommand {
// 1. 私有化List,避免外部直接修改(安全)
// static:整个程序只有一份,所有地方共用这个历史列表
private static List<String> commandHistory = new ArrayList<>();
// 2. 添加命令到历史(外部调用这个方法记录命令)
public static void addCommand(String command) {
commandHistory.add(command);
}
// 3. 获取所有历史命令(返回副本,避免原列表被外部篡改)
public static List<String> getCommandHistory() {
return new ArrayList<>(commandHistory); // 返回副本,原列表不会被改
}
// 4. 清空历史命令(可选,方便测试)
public static void clearHistory() {
commandHistory.clear();
}
}