Class ChangeHistory

  • All Implemented Interfaces:
    IStringValueProvider, IVilType

    public class ChangeHistory
    extends java.lang.Object
    implements IVilType, IStringValueProvider
    Implements a checkpointing change history of variable changes. Changes are traced in a kind of transaction marked by start(), and ending with commit(), rollback() or commitAll() on a change set stack. On committed, they are either committed in the next change set on the stack or into the global set of committed variables.
    Author:
    Holger Eichelberger
    • Constructor Detail

      • ChangeHistory

        ChangeHistory​(Configuration configuration)
        Creates a change history.
        Parameters:
        configuration - the configuration to track changes for
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • hasChanges

        public boolean hasChanges()
        Returns whether the current change set has direct changes (i.e., no indirect commits from other change sets).
        Returns:
        whether there were direct changes
      • start

        public void start()
        Starts a new change set.
      • rollback

        public void rollback()
        Rolls back the most recent change set. Nothing happens if the stack is empty.
      • changes

        public void changes​(IChangeHistoryVisitor visitor)
        Visits the most recent changes into the top-most change set. Does not modify the change set.
        Parameters:
        visitor - the visitor to be called for each change
      • allChanges

        public void allChanges​(IChangeHistoryVisitor visitor)
        Visits all changes. Does not modify the change set.
        Parameters:
        visitor - the visitor to be called for each change
      • commit

        public void commit()
        Commits the most recent change set into the one before or if there is none into the committed set. Clears the most recent change set. Nothing happens if the stack is empty.
      • commitAll

        public void commitAll()
        Commits the changes of all stacked change sets into the committed change set.
      • rollbackAll

        public void rollbackAll()
        Rolls back all the changes in the uncommitted stack.
      • getOriginalValue

        public Value getOriginalValue​(AbstractIvmlVariable variable)
        Returns the original value of a variable before any explicit change. This method is made accessible through variable itself. Following the idea of VIL, reference values are transparently dereferenced.
        Parameters:
        variable - the
        Returns:
        the original value
      • rollbackSimulation

        public void rollbackSimulation()
        Rolls back all all changes.
      • isSameValue

        private static boolean isSameValue​(Value value1,
                                           Value value2)
        Returns whether value1 and value2 are the same.
        Parameters:
        value1 - the first value (may be null)
        value2 - the second value (may be null)
        Returns:
        true if value1 is considered to be the same as value2, false else
      • notifyChanged

        void notifyChanged​(AbstractIvmlVariable variable,
                           Value value)
        Notifies the change set about a changed variable.
        Parameters:
        variable - the variable
        value - the old value (clone assumed)
      • changed

        java.util.Set<AbstractIvmlVariable> changed()
        Returns all changed variables.
        Returns:
        all changed variables
      • changedFilter

        IVariableFilter changedFilter()
        Returns a filter for all changed variables.
        Returns:
        a filter for all changed variables
      • getStringValue

        public java.lang.String getStringValue​(IStringValueProvider.StringComparator comparator)
        Description copied from interface: IStringValueProvider
        Returns the string value of this object.
        Specified by:
        getStringValue in interface IStringValueProvider
        Parameters:
        comparator - if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned
        Returns:
        the string value
      • clear

        public void clear​(boolean resetOriginalValues)
        Clears the history.
        Parameters:
        resetOriginalValues - also reset original values
      • setTracer

        public IChangeHistoryTracer setTracer​(IChangeHistoryTracer tracer)
        Defines or unsets the configuration tracer.
        Parameters:
        tracer - the tracer (may be null for unsetting)
        Returns:
        the tracer before setting
      • getTracer

        public IChangeHistoryTracer getTracer()
        Returns the current tracer.
        Returns:
        the tracer