java.lang.Object
org.maxicp.state.trail.Trailer
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetLevel()Returns the current level.longgetMagic()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 theStateManager.restoreState()is called.voidpushState(StateEntry entry) 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 1toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.maxicp.state.StateManager
withNewState, withNewState
-
Constructor Details
-
Trailer
public Trailer()
-
-
Method Details
-
onRestore
Description copied from interface:StateManagerAdd a listener that is notified each time theStateManager.restoreState()is called.- Specified by:
onRestorein interfaceStateManager- Parameters:
listener- the listener to be notified
-
getMagic
public long getMagic() -
pushState
-
getLevel
public int getLevel()Description copied from interface:StateManagerReturns the current level. It is increased at eachStateManager.saveState()and decreased at eachStateManager.restoreState(). It is initially equal to -1.- Specified by:
getLevelin interfaceStateManager- Returns:
- the level
-
saveState
public void saveState()Description copied from interface:StateManagerStores the current state such that it can be recovered using restoreState() Increase the level by 1- Specified by:
saveStatein interfaceStateManager
-
restoreState
public void restoreState()Description copied from interface:StateManagerRestores state as it was at getLevel()-1 Decrease the level by 1- Specified by:
restoreStatein interfaceStateManager
-
restoreStateUntil
public void restoreStateUntil(int level) Description copied from interface:StateManagerRestores the state up the the given level.- Specified by:
restoreStateUntilin interfaceStateManager- Parameters:
level- the level, a non negative number between 0 andStateManager.getLevel()
-
makeStateRef
Description copied from interface:StateManagerCreates a Stateful reference (restorable)- Specified by:
makeStateRefin interfaceStateManager- Parameters:
initValue- the initial setValue- Returns:
- a State object wrapping the initValue
-
makeStateInt
Description copied from interface:StateManagerCreates a Stateful integer (restorable)- Specified by:
makeStateIntin interfaceStateManager- Parameters:
initValue- the initial setValue- Returns:
- a StateInt object wrapping the initValue
-
makeStateLong
Description copied from interface:StateManagerCreates a Stateful long (restorable)- Specified by:
makeStateLongin interfaceStateManager- Parameters:
initValue- the initial setValue- Returns:
- a StateLong object wrapping the initValue
-
makeStateMap
Description copied from interface:StateManagerCreates a Stateful map (restorable)- Specified by:
makeStateMapin interfaceStateManager- Returns:
- a reference to the map.
-
toString
-