Module org.maxicp

Interface StateManager

All Known Implementing Classes:
Copier, Trailer

public interface StateManager
The StateManager exposes all the mechanisms and data-structures needed to implement a depth-first-search with reversible states.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the current level.
    makeStateInt(int initValue)
    Creates a Stateful integer (restorable)
    makeStateLong(long initValue)
    Creates a Stateful long (restorable)
    <K, V> StateMap<K,V>
    Creates a Stateful map (restorable)
    <T> State<T>
    makeStateRef(T initValue)
    Creates a Stateful reference (restorable)
    void
    onRestore(Runnable listener)
    Add a listener that is notified each time the restoreState() is called.
    void
    Restores state as it was at getLevel()-1 Decrease the level by 1
    void
    restoreStateUntil(int level)
    Restores the state up the the given level.
    void
    Stores the current state such that it can be recovered using restoreState() Increase the level by 1
    default void
    Higher-order function that preserves the state prior to calling body and restores it after.
    default <T> T
     
  • Method Details

    • saveState

      void saveState()
      Stores the current state such that it can be recovered using restoreState() Increase the level by 1
    • restoreState

      void restoreState()
      Restores state as it was at getLevel()-1 Decrease the level by 1
    • restoreStateUntil

      void restoreStateUntil(int level)
      Restores the state up the the given level.
      Parameters:
      level - the level, a non negative number between 0 and getLevel()
    • onRestore

      void onRestore(Runnable listener)
      Add a listener that is notified each time the restoreState() is called.
      Parameters:
      listener - the listener to be notified
    • getLevel

      int getLevel()
      Returns the current level. It is increased at each saveState() and decreased at each restoreState(). It is initially equal to -1.
      Returns:
      the level
    • makeStateRef

      <T> State<T> makeStateRef(T initValue)
      Creates a Stateful reference (restorable)
      Parameters:
      initValue - the initial setValue
      Returns:
      a State object wrapping the initValue
    • makeStateInt

      StateInt makeStateInt(int initValue)
      Creates a Stateful integer (restorable)
      Parameters:
      initValue - the initial setValue
      Returns:
      a StateInt object wrapping the initValue
    • makeStateLong

      StateLong makeStateLong(long initValue)
      Creates a Stateful long (restorable)
      Parameters:
      initValue - the initial setValue
      Returns:
      a StateLong object wrapping the initValue
    • makeStateMap

      <K, V> StateMap<K,V> makeStateMap()
      Creates a Stateful map (restorable)
      Returns:
      a reference to the map.
    • withNewState

      default void withNewState(Runnable body)
      Higher-order function that preserves the state prior to calling body and restores it after.
      Parameters:
      body - the first-order function to execute.
    • withNewState

      default <T> T withNewState(Supplier<T> body)