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.
28 lines
713 B
28 lines
713 B
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class HistoryCommand {
|
|
private List<String> commandHistory = new ArrayList<>();
|
|
|
|
// 添加命令到历史
|
|
public void addCommand(String command) {
|
|
commandHistory.add(command);
|
|
}
|
|
|
|
// 获取所有历史命令
|
|
public List<String> getHistory() {
|
|
return new ArrayList<>(commandHistory); // 返回副本,保护原数据
|
|
}
|
|
|
|
// 打印历史记录
|
|
public void printHistory() {
|
|
for (int i = 0; i < commandHistory.size(); i++) {
|
|
System.out.println((i + 1) + ". " + commandHistory.get(i));
|
|
}
|
|
}
|
|
|
|
// 清空历史
|
|
public void clear() {
|
|
commandHistory.clear();
|
|
}
|
|
}
|