MCPcopy
hub / github.com/arduino/Arduino / addCommand

Method addCommand

app/src/processing/app/CommandHistory.java:34–58  ·  view source on GitHub ↗

Adds the given command to the history and resets the history traversal position to the latest command. If the latest command in the history is equal to the given command, it will not be added to the history. If the max history size is exceeded, the oldest command will be removed from the history. @p

(String command)

Source from the content-addressed store, hash-verified

32 * @param command - The command to add.
33 */
34 public void addCommand(String command) {
35 if (this.maxHistorySize == 0) {
36 return;
37 }
38
39 // Remove 'current' command.
40 this.commandHistory.removeLast();
41
42 // Add new command if it differs from the latest command.
43 if (this.commandHistory.isEmpty()
44 || !this.commandHistory.getLast().equals(command)) {
45
46 // Remove oldest command if max history size is exceeded.
47 if (this.commandHistory.size() >= this.maxHistorySize) {
48 this.commandHistory.removeFirst();
49 }
50
51 // Add new command and reset 'current' command.
52 this.commandHistory.addLast(command);
53 }
54
55 // Re-add 'current' command and reset command iterator.
56 this.commandHistory.addLast(""); // Current command placeholder.
57 this.iterator = null;
58 }
59
60 /**
61 * Gets whether a next (more recent) command is available in the history.

Callers 1

SerialMonitorMethod · 0.80

Calls 3

sizeMethod · 0.80
isEmptyMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected