Package org.smooks.engine.memento
Class DefaultMementoCaretaker
- java.lang.Object
-
- org.smooks.engine.memento.DefaultMementoCaretaker
-
- All Implemented Interfaces:
MementoCaretaker
@NotThreadSafe public class DefaultMementoCaretaker extends Object implements MementoCaretaker
-
-
Constructor Summary
Constructors Constructor Description DefaultMementoCaretaker(TypedMap typedMap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
capture(Memento memento)
Stores a copy of aMemento
.boolean
exists(Memento memento)
void
forget(Fragment<?> fragment)
Removes allMemento
s bound to theFragment
parameter.void
forget(Memento visitorMemento)
Removes theMemento
having an ID equal to theMemento
parameter's ID as returned byMemento.getAnchor()
.void
restore(Memento memento)
Mutates aMemento
to match the state of a savedMemento
.<T extends Memento>
Tstash(T defaultMemento, Function<T,T> function)
-
-
-
Constructor Detail
-
DefaultMementoCaretaker
public DefaultMementoCaretaker(TypedMap typedMap)
-
-
Method Detail
-
capture
public void capture(Memento memento)
Description copied from interface:MementoCaretaker
Stores a copy of aMemento
. It is the client's responsibility to remove the savedMemento
once it is no longer needed either by callingMementoCaretaker.forget(Fragment)
orMementoCaretaker.forget(Memento)
.- Specified by:
capture
in interfaceMementoCaretaker
- Parameters:
memento
- theMemento
to copy and store. After saving, mutations to thisMemento
should not alter the saved copy.
-
restore
public void restore(Memento memento)
Description copied from interface:MementoCaretaker
Mutates aMemento
to match the state of a savedMemento
. TheMemento
parameter is restored from a savedMemento
having an ID equal to its ID as returned byMemento.getAnchor()
. TheMemento
parameter remains unchanged if no such savedMemento
exists.- Specified by:
restore
in interfaceMementoCaretaker
- Parameters:
memento
- theMemento
to restore
-
exists
public boolean exists(Memento memento)
- Specified by:
exists
in interfaceMementoCaretaker
-
forget
public void forget(Memento visitorMemento)
Description copied from interface:MementoCaretaker
Removes theMemento
having an ID equal to theMemento
parameter's ID as returned byMemento.getAnchor()
.- Specified by:
forget
in interfaceMementoCaretaker
- Parameters:
visitorMemento
- theMemento
to be removed
-
forget
public void forget(Fragment<?> fragment)
Description copied from interface:MementoCaretaker
Removes allMemento
s bound to theFragment
parameter.- Specified by:
forget
in interfaceMementoCaretaker
- Parameters:
fragment
- the fragment
-
stash
public <T extends Memento> T stash(T defaultMemento, Function<T,T> function)
Description copied from interface:MementoCaretaker
Invokes aConsumer
with a restoredMemento
and 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);
- Specified by:
stash
in interfaceMementoCaretaker
- Parameters:
defaultMemento
- theMemento
to be restoredfunction
- the function acting on the restoredMemento
and returning a newMemento replacing the earlier memento
- See Also:
MementoCaretaker.restore(Memento)
,MementoCaretaker.capture(Memento)
-
-