Package org.smooks.api.memento
Interface MementoCaretaker
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcapture(Memento memento)Stores a copy of aMemento.booleanexists(Memento memento)voidforget(Fragment<?> fragment)Removes allMementos bound to theFragmentparameter.voidforget(Memento memento)Removes theMementohaving an ID equal to theMementoparameter's ID as returned byMemento.getAnchor().voidrestore(Memento memento)Mutates aMementoto match the state of a savedMemento.<T extends Memento>
Tstash(T defaultMemento, Function<T,T> function)
-
-
-
Method Detail
-
capture
void capture(Memento memento)
Stores a copy of aMemento. It is the client's responsibility to remove the savedMementoonce it is no longer needed either by callingforget(Fragment)orforget(Memento).- Parameters:
memento- theMementoto copy and store. After saving, mutations to thisMementoshould not alter the saved copy.
-
restore
void restore(Memento memento)
Mutates aMementoto match the state of a savedMemento. TheMementoparameter is restored from a savedMementohaving an ID equal to its ID as returned byMemento.getAnchor(). TheMementoparameter remains unchanged if no such savedMementoexists.- Parameters:
memento- theMementoto restore
-
exists
boolean exists(Memento memento)
-
forget
void forget(Memento memento)
Removes theMementohaving an ID equal to theMementoparameter's ID as returned byMemento.getAnchor().- Parameters:
memento- theMementoto be removed
-
forget
void forget(Fragment<?> fragment)
Removes allMementos bound to theFragmentparameter.- Parameters:
fragment- the fragment
-
stash
<T extends Memento> T stash(T defaultMemento, Function<T,T> function)
Invokes aConsumerwith a restoredMementoand then saves theMemento. This method offers a convenient way to aggregate and save data instead of writing:mementoCaretaker.restore(Memento); // add data to memento // ... mementoCaretaker.save(memento);
- Parameters:
defaultMemento- theMementoto be restoredfunction- the function acting on the restoredMementoand returning a newMemento replacing the earlier memento- See Also:
restore(Memento),capture(Memento)
-
-