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)
StateManager
StateManager.restoreState()
is called.onRestore
in interface StateManager
listener
- the listener to be notifiedpublic long getMagic()
public void pushState(StateEntry entry)
public int getLevel()
StateManager
StateManager.saveState()
and decreased at each StateManager.restoreState()
.
It is initially equal to -1.getLevel
in interface StateManager
public void saveState()
StateManager
saveState
in interface StateManager
public void restoreState()
StateManager
restoreState
in interface StateManager
public void withNewState(Procedure body)
StateManager
withNewState
in interface StateManager
body
- the first-order function to execute.public void restoreAllState()
StateManager
restoreAllState
in interface StateManager
public void restoreStateUntil(int level)
StateManager
restoreStateUntil
in interface StateManager
level
- the level, a non negative number between 0 and StateManager.getLevel()
public StateInt makeStateInt(int initValue)
StateManager
makeStateInt
in interface StateManager
initValue
- the initial setValuepublic StateBool makeStateBool(boolean initValue)
StateManager
makeStateBool
in interface StateManager
initValue
- the initial setValuepublic StateMap makeStateMap()
StateManager
makeStateMap
in interface StateManager
Copyright © 2018 Laurent Michel, Pierre Schaus, Pascal Van Hentenryck. All rights reserved.