Class InMemoryHistory

java.lang.Object
org.aesh.readline.history.History
org.aesh.readline.history.InMemoryHistory
Direct Known Subclasses:
FileHistory

public class InMemoryHistory extends History
A simple in-memory history implementation By default max size is 500
Author:
Ståle W. Pedersen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an InMemoryHistory with the default maximum size of 500 entries.
    InMemoryHistory(int maxSize)
    Creates an InMemoryHistory with the specified maximum size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all entries from the history.
    int[]
    find(int[] search)
    Finds an entry in the history that matches the search.
    int[]
    get(int index)
    Gets the history entry at the specified index.
    List<int[]>
    Gets all entries in the history.
    int[]
    Gets the current line being edited.
    int[]
    Gets the next entry in the history (moving forward).
    int[]
    Gets the previous entry in the history (moving backward).
    Gets the current search direction.
    void
    push(int[] entry)
    Pushes a new entry to the history.
    int[]
    search(int[] search)
    Searches for an entry in the history that contains the search pattern.
    void
    setCurrent(int[] line)
    Sets the current line being edited (used for history navigation).
    void
    Sets the search direction for history searches.
    int
    Returns the number of entries in the history.
    void
    Stops the history and performs any necessary cleanup (e.g., saving to file).

    Methods inherited from class History

    disable, enable, isEnabled

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • InMemoryHistory

      public InMemoryHistory()
      Creates an InMemoryHistory with the default maximum size of 500 entries.
    • InMemoryHistory

      public InMemoryHistory(int maxSize)
      Creates an InMemoryHistory with the specified maximum size.
      Parameters:
      maxSize - the maximum number of history entries, or -1 for unlimited
  • Method Details

    • push

      public void push(int[] entry)
      Description copied from class: History
      Pushes a new entry to the history.
      Specified by:
      push in class History
      Parameters:
      entry - the entry to add
    • find

      public int[] find(int[] search)
      Description copied from class: History
      Finds an entry in the history that matches the search.
      Specified by:
      find in class History
      Parameters:
      search - the search pattern
      Returns:
      the matching entry, or null if not found
    • get

      public int[] get(int index)
      Description copied from class: History
      Gets the history entry at the specified index.
      Specified by:
      get in class History
      Parameters:
      index - the index of the entry to retrieve
      Returns:
      the history entry at the specified index
    • size

      public int size()
      Description copied from class: History
      Returns the number of entries in the history.
      Specified by:
      size in class History
      Returns:
      the size of the history
    • setSearchDirection

      public void setSearchDirection(SearchDirection direction)
      Description copied from class: History
      Sets the search direction for history searches.
      Specified by:
      setSearchDirection in class History
      Parameters:
      direction - the search direction
    • getSearchDirection

      public SearchDirection getSearchDirection()
      Description copied from class: History
      Gets the current search direction.
      Specified by:
      getSearchDirection in class History
      Returns:
      the current search direction
    • getPreviousFetch

      public int[] getPreviousFetch()
      Description copied from class: History
      Gets the previous entry in the history (moving backward).
      Specified by:
      getPreviousFetch in class History
      Returns:
      the previous history entry, or empty array if at the beginning
    • getNextFetch

      public int[] getNextFetch()
      Description copied from class: History
      Gets the next entry in the history (moving forward).
      Specified by:
      getNextFetch in class History
      Returns:
      the next history entry, or null if at the end
    • search

      public int[] search(int[] search)
      Description copied from class: History
      Searches for an entry in the history that contains the search pattern.
      Specified by:
      search in class History
      Parameters:
      search - the search pattern
      Returns:
      the matching entry, or null if not found
    • setCurrent

      public void setCurrent(int[] line)
      Description copied from class: History
      Sets the current line being edited (used for history navigation).
      Specified by:
      setCurrent in class History
      Parameters:
      line - the current line
    • getCurrent

      public int[] getCurrent()
      Description copied from class: History
      Gets the current line being edited.
      Specified by:
      getCurrent in class History
      Returns:
      the current line
    • getAll

      public List<int[]> getAll()
      Description copied from class: History
      Gets all entries in the history.
      Specified by:
      getAll in class History
      Returns:
      a list of all history entries
    • clear

      public void clear()
      Description copied from class: History
      Clears all entries from the history.
      Specified by:
      clear in class History
    • stop

      public void stop()
      Description copied from class: History
      Stops the history and performs any necessary cleanup (e.g., saving to file).
      Specified by:
      stop in class History