Module org.maxicp

Class Trailer

java.lang.Object
org.maxicp.state.trail.Trailer
All Implemented Interfaces:
StateManager

public class Trailer extends Object implements StateManager
StateManager that will lazily store the state of state object at each saveState() call. Only the one that effectively change are stored and at most once between any to call to saveState(). This can be seen as an optimized version of Copier.
  • Constructor Details

    • Trailer

      public Trailer()
  • Method Details

    • onRestore

      public void onRestore(Runnable listener)
      Description copied from interface: StateManager
      Add a listener that is notified each time the StateManager.restoreState() is called.
      Specified by:
      onRestore in interface StateManager
      Parameters:
      listener - the listener to be notified
    • getMagic

      public long getMagic()
    • pushState

      public void pushState(StateEntry entry)
    • getLevel

      public int getLevel()
      Description copied from interface: StateManager
      Returns the current level. It is increased at each StateManager.saveState() and decreased at each StateManager.restoreState(). It is initially equal to -1.
      Specified by:
      getLevel in interface StateManager
      Returns:
      the level
    • saveState

      public void saveState()
      Description copied from interface: StateManager
      Stores the current state such that it can be recovered using restoreState() Increase the level by 1
      Specified by:
      saveState in interface StateManager
    • restoreState

      public void restoreState()
      Description copied from interface: StateManager
      Restores state as it was at getLevel()-1 Decrease the level by 1
      Specified by:
      restoreState in interface StateManager
    • restoreStateUntil

      public void restoreStateUntil(int level)
      Description copied from interface: StateManager
      Restores the state up the the given level.
      Specified by:
      restoreStateUntil in interface StateManager
      Parameters:
      level - the level, a non negative number between 0 and StateManager.getLevel()
    • makeStateRef

      public <T> State<T> makeStateRef(T initValue)
      Description copied from interface: StateManager
      Creates a Stateful reference (restorable)
      Specified by:
      makeStateRef in interface StateManager
      Parameters:
      initValue - the initial setValue
      Returns:
      a State object wrapping the initValue
    • makeStateInt

      public StateInt makeStateInt(int initValue)
      Description copied from interface: StateManager
      Creates a Stateful integer (restorable)
      Specified by:
      makeStateInt in interface StateManager
      Parameters:
      initValue - the initial setValue
      Returns:
      a StateInt object wrapping the initValue
    • makeStateLong

      public StateLong makeStateLong(long initValue)
      Description copied from interface: StateManager
      Creates a Stateful long (restorable)
      Specified by:
      makeStateLong in interface StateManager
      Parameters:
      initValue - the initial setValue
      Returns:
      a StateLong object wrapping the initValue
    • makeStateMap

      public <K, V> StateMap<K,V> makeStateMap()
      Description copied from interface: StateManager
      Creates a Stateful map (restorable)
      Specified by:
      makeStateMap in interface StateManager
      Returns:
      a reference to the map.
    • toString

      public String toString()
      Overrides:
      toString in class Object