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 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
    • pushWithTimestamp

      protected void pushWithTimestamp(int[] entry, long timestamp)
      Push an entry with a specific timestamp. Used by FileHistory to restore timestamps from the history file.
      Parameters:
      entry - the history entry
      timestamp - the timestamp in epoch milliseconds
    • 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
    • previousFetch

      public Optional<int[]> previousFetch()
      Description copied from class: History
      Fetch the previous history entry.
      Specified by:
      previousFetch in class History
      Returns:
      an Optional containing the previous history entry, or empty if at the start
    • nextFetch

      public Optional<int[]> nextFetch()
      Description copied from class: History
      Fetch the next history entry.
      Specified by:
      nextFetch in class History
      Returns:
      an Optional containing the next history entry, or empty 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
    • getTimestamps

      public List<Long> getTimestamps()
      Description copied from class: History
      Gets the timestamps (epoch millis) for all entries in the history. The returned list is parallel to History.getAll() — same size and order.

      The default implementation returns null, indicating timestamps are not available.

      Overrides:
      getTimestamps in class History
      Returns:
      a list of timestamps, or null if timestamps are not tracked
    • 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