public class Trailer extends Object implements StateManager
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 and Description |
|---|
Trailer() |
| Modifier and Type | Method and Description |
|---|---|
int |
getLevel()
Returns the current level.
|
long |
getMagic() |
StateBool |
makeStateBool(boolean initValue)
Creates a Stateful boolean (restorable)
|
StateInt |
makeStateInt(int initValue)
Creates a Stateful integer (restorable)
|
StateMap |
makeStateMap()
Creates a Stateful map (restorable)
|
void |
onRestore(Procedure listener)
Add a listener that is notified each time the
StateManager.restoreState()
is called. |
void |
pushState(StateEntry entry) |
void |
restoreAllState()
Restores the state as it was at level 0 (first saveState)
The level is now -1.
|
void |
restoreState()
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 |
saveState()
Stores the current state
such that it can be recovered using restoreState()
Increase the level by 1
|
void |
withNewState(Procedure body)
Higher-order function that preserves the state prior to calling body and restores it after.
|
public void onRestore(Procedure listener)
StateManagerStateManager.restoreState()
is called.onRestore in interface StateManagerlistener - the listener to be notifiedpublic long getMagic()
public void pushState(StateEntry entry)
public int getLevel()
StateManagerStateManager.saveState()
and decreased at each StateManager.restoreState().
It is initially equal to -1.getLevel in interface StateManagerpublic void saveState()
StateManagersaveState in interface StateManagerpublic void restoreState()
StateManagerrestoreState in interface StateManagerpublic void withNewState(Procedure body)
StateManagerwithNewState in interface StateManagerbody - the first-order function to execute.public void restoreAllState()
StateManagerrestoreAllState in interface StateManagerpublic void restoreStateUntil(int level)
StateManagerrestoreStateUntil in interface StateManagerlevel - the level, a non negative number between 0 and StateManager.getLevel()public StateInt makeStateInt(int initValue)
StateManagermakeStateInt in interface StateManagerinitValue - the initial setValuepublic StateBool makeStateBool(boolean initValue)
StateManagermakeStateBool in interface StateManagerinitValue - the initial setValuepublic StateMap makeStateMap()
StateManagermakeStateMap in interface StateManagerCopyright © 2018 Laurent Michel, Pierre Schaus, Pascal Van Hentenryck. All rights reserved.