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.

38 lines
848 B

package model;
import java.util.ArrayList;
import java.util.List;
/**
* 单例模式:全局唯一记录用户所有输入命令
*/
public class HistoryCommand {
// 保存所有命令
private final List<String> commandList;
// 单例实例
private static HistoryCommand instance;
// 私有构造
private HistoryCommand() {
commandList = new ArrayList<>();
}
// 获取唯一实例
public static HistoryCommand getInstance() {
if (instance == null) {
instance = new HistoryCommand();
}
return instance;
}
// 添加命令
public void addCommand(String command) {
commandList.add(command);
}
// 获取所有历史命令
public List<String> getAllCommand() {
return commandList;
}
}