Class RunHistory

java.lang.Object
com.j3d.engine.interact.cmd.RunHistory

public class RunHistory extends Object
Manages the history of executed commands in the command palette.

It provides functionality to navigate through the command history using up() and down() methods, and to commit new commands to the history using commit(String).

Author:
Lehlogonolo Poole
See Also:
  • Field Details

  • Constructor Details

    • RunHistory

      public RunHistory()
      Constructs a new RunHistory.
  • Method Details

    • commit

      public void commit(String line)
      Commits a command line to the history.

      This clears the backup history and adds the new command to the main history.

      Parameters:
      line - The command line to commit.
    • up

      public String up()
      Navigates up through the command history.

      Moves the last command from the main history to the backup history and returns it.

      Returns:
      The previous command in the history, or an empty string if the history is empty.
    • down

      public String down()
      Navigates down through the command history.

      Moves the last command from the backup history back to the main history and returns it.

      Returns:
      The next command in the history, or an empty string if the backup history is empty.
    • removeFirstIfFull

      private void removeFirstIfFull(ArrayList<String> arr)
      Removes the first element from the given ArrayList if its size reaches the maximum limit.

      This method ensures that the history lists do not grow indefinitely.

      Parameters:
      arr - The ArrayList to check and modify.