forked from AY2425S1-CS2103T-T12-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9728194
commit 7f18962
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |