public class CommandHistory
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
commandIndex
The current command index.
|
private java.util.List<java.lang.String> |
commands
The commands.
|
private static int |
HISTORY_SIZE
The maximum number of commands to store.
|
Constructor and Description |
---|
CommandHistory(java.lang.String ident)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addCommand(java.lang.String command)
Adds a new command.
|
java.lang.String |
down()
Returns the next command.
|
java.lang.CharSequence |
last(int index)
Returns the last executed command.
|
private void |
removeCommand(java.lang.String command)
Removes a command.
|
private void |
trimToMaxSize()
Cut off old entries if more than
HISTORY_SIZE commands are
present. |
java.lang.String |
up()
Returns the previous command.
|
private int commandIndex
@NotNull private final java.util.List<java.lang.String> commands
private static final int HISTORY_SIZE
public CommandHistory(@NotNull java.lang.String ident)
ident
- the identification string for backing up to filepublic void addCommand(@NotNull java.lang.String command)
command
- the command to add@Nullable public java.lang.String down()
null
if no previous command exists@Nullable public java.lang.CharSequence last(int index)
index
- the index of the command; 0=last command, 1=second to last,
etc.null
if the index is invalidprivate void removeCommand(@NotNull java.lang.String command)
command
- the command to removeprivate void trimToMaxSize()
HISTORY_SIZE
commands are
present.@Nullable public java.lang.String up()
null
if no previous command
exists