Skip to content

Commit

Permalink
Create CommandHistory.java
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingsalsa committed Oct 18, 2024
1 parent 9728194 commit 7f18962
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/seedu/address/ui/CommandHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.address.ui;
import java.util.ArrayList;


/**
* Container for previous commands
*/
public class CommandHistory {
private ArrayList<String> commandHistory = new ArrayList<>();
private int currentHistoryIndex = -1;

public void addCommand(String command) {
commandHistory.add(command);
currentHistoryIndex = commandHistory.size(); // Reset index to point after the latest command
}

public String getPreviousCommand() {
if (currentHistoryIndex > 0) {
currentHistoryIndex--;
return commandHistory.get(currentHistoryIndex);
}
return null; // No previous command
}

public String getNextCommand() {
if (currentHistoryIndex < commandHistory.size() - 1) {
currentHistoryIndex++;
return commandHistory.get(currentHistoryIndex);
}
return null; // No next command
}
}

0 comments on commit 7f18962

Please sign in to comment.