Class HistoryList<T>

java.lang.Object
top.girlkisser.lazuli.api.collections.HistoryList<T>
Type Parameters:
T - The list's entry type.

public class HistoryList<T> extends Object
A helper class for storing and managing a list with undo/redo capabilities.

See Minefactorial's TweakerulerHistory for a usage example.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected List<T>
    The contained elements.
    protected int
    The maximum combined length of each list.
    protected Stack<T>
    A stack containing the elements to add to data when redo() is invoked.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HistoryList(int maxLength)
    A helper class for storing and managing a list with undo/redo capabilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Get whether a redo() will do anything when invoked.
    boolean
    Get whether an undo() will do anything when invoked.
    void
    Clears all data and history from this list.
    int
    Get the current amount of elements.
    int
    Get the current amount of elements stored in history.
    protected void
    onRedo(T redoneItem)
    Invoked any time redo() is called successfully.
    protected void
    onUndo(T undoneItem)
    Invoked any time undo() is called successfully.
    void
    push(T it)
    Pushes an item onto the history.
    void
    Undo the lastest undo().
    void
    Undo the lastest push(Object).

    Methods inherited from class java.lang.Object

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

    • redoHistory

      protected Stack<T> redoHistory
      A stack containing the elements to add to data when redo() is invoked.
    • data

      protected List<T> data
      The contained elements.
    • maxLength

      protected int maxLength
      The maximum combined length of each list.
  • Constructor Details

    • HistoryList

      public HistoryList(int maxLength)
      A helper class for storing and managing a list with undo/redo capabilities.

      See Minefactorial's TweakerulerHistory for a usage example.

      Parameters:
      maxLength - The maximum length for the list.
  • Method Details

    • clear

      public void clear()
      Clears all data and history from this list.
    • dataSize

      public int dataSize()
      Get the current amount of elements.
      Returns:
      The amount.
    • historySize

      public int historySize()
      Get the current amount of elements stored in history.
      Returns:
      The amount.
    • push

      public void push(T it)
      Pushes an item onto the history. This will remove elements after the index, if there are any.
      Parameters:
      it - The item to add.
    • canUndo

      public boolean canUndo()
      Get whether an undo() will do anything when invoked.
      Returns:
      `true` if there is data to undo.
    • undo

      public void undo()
      Undo the lastest push(Object).
    • canRedo

      public boolean canRedo()
      Get whether a redo() will do anything when invoked.
      Returns:
      `true` if there is data to redo.
    • redo

      public void redo()
      Undo the lastest undo().
    • onUndo

      protected void onUndo(T undoneItem)
      Invoked any time undo() is called successfully.
      Parameters:
      undoneItem - The undone item.
    • onRedo

      protected void onRedo(T redoneItem)
      Invoked any time redo() is called successfully.
      Parameters:
      redoneItem - The redone item.