Interface MementoCaretaker

    • Method Detail

      • capture

        void capture​(Memento memento)
        Stores a copy of a Memento. It is the client's responsibility to remove the saved Memento once it is no longer needed either by calling forget(Fragment) or forget(Memento).
        Parameters:
        memento - the Memento to copy and store. After saving, mutations to this Memento should not alter the saved copy.
      • restore

        void restore​(Memento memento)
        Mutates a Memento to match the state of a saved Memento. The Memento parameter is restored from a saved Memento having an ID equal to its ID as returned by Memento.getAnchor(). The Memento parameter remains unchanged if no such saved Memento exists.
        Parameters:
        memento - the Memento to restore
      • exists

        boolean exists​(Memento memento)
      • forget

        void forget​(Memento memento)
        Removes the Memento having an ID equal to the Memento parameter's ID as returned by Memento.getAnchor().
        Parameters:
        memento - the Memento to be removed
      • forget

        void forget​(Fragment<?> fragment)
        Removes all Mementos bound to the Fragment parameter.
        Parameters:
        fragment - the fragment
      • stash

        <T extends Memento> T stash​(T defaultMemento,
                                    Function<T,​T> function)
        Invokes a Consumer with a restored Memento and then saves the Memento. 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 - the Memento to be restored
        function - the function acting on the restored Memento and returning a new Memento replacing the earlier memento
        See Also:
        restore(Memento), capture(Memento)