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.
40 lines
1019 B
40 lines
1019 B
package Article;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class HistoryCommand {
|
|
private List<String> commandHistory;
|
|
|
|
public HistoryCommand() {
|
|
this.commandHistory = new ArrayList<>();
|
|
}
|
|
|
|
public void addCommand(String command) {
|
|
if (command != null && !command.trim().isEmpty()) {
|
|
commandHistory.add(command);
|
|
}
|
|
}
|
|
|
|
public List<String> getAllCommands() {
|
|
return new ArrayList<>(commandHistory); // 返回副本,保护内部数据
|
|
}
|
|
|
|
public String getLastCommand() {
|
|
return commandHistory.isEmpty() ? null : commandHistory.get(commandHistory.size() - 1);
|
|
}
|
|
|
|
public void printHistory() {
|
|
for (int i = 0; i < commandHistory.size(); i++) {
|
|
System.out.println((i + 1) + ". " + commandHistory.get(i));
|
|
}
|
|
}
|
|
|
|
public void clear() {
|
|
commandHistory.clear();
|
|
}
|
|
|
|
public int size() {
|
|
return commandHistory.size();
|
|
}
|
|
}
|