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 TypeMethodDescriptionintgetLevel()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)voidAdd a listener that is notified each time therestoreState()is called.voidRestores state as it was at getLevel()-1 Decrease the level by 1voidrestoreStateUntil(int level) Restores the state up the the given level.voidStores the current state such that it can be recovered using restoreState() Increase the level by 1default voidwithNewState(Runnable body) Higher-order function that preserves the state prior to calling body and restores it after.default <T> TwithNewState(Supplier<T> body)
-
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 andgetLevel()
-
onRestore
Add a listener that is notified each time therestoreState()is called.- Parameters:
listener- the listener to be notified
-
getLevel
int getLevel()Returns the current level. It is increased at eachsaveState()and decreased at eachrestoreState(). It is initially equal to -1.- Returns:
- the level
-
makeStateRef
Creates a Stateful reference (restorable)- Parameters:
initValue- the initial setValue- Returns:
- a State object wrapping the initValue
-
makeStateInt
Creates a Stateful integer (restorable)- Parameters:
initValue- the initial setValue- Returns:
- a StateInt object wrapping the initValue
-
makeStateLong
Creates a Stateful long (restorable)- Parameters:
initValue- the initial setValue- Returns:
- a StateLong object wrapping the initValue
-
makeStateMap
Creates a Stateful map (restorable)- Returns:
- a reference to the map.
-
withNewState
Higher-order function that preserves the state prior to calling body and restores it after.- Parameters:
body- the first-order function to execute.
-
withNewState
-