Class ChangeHistory
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.configuration.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 bystart(), and ending withcommit(),rollback()orcommitAll()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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classChangeHistory.ChangeListenerImplements a change listener to track reasoning changes to the configuration.private static classChangeHistory.CSetDefines the type of a change set.-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description private IConfigurationChangeListenerchangeListenerprivate java.util.Stack<ChangeHistory.CSet>changeSetStackprivate ChangeHistory.CSetcommittedprivate Configurationconfigurationprivate java.util.Map<IDecisionVariable,Value>originalValuesprivate IChangeHistoryTracertracer
-
Constructor Summary
Constructors Constructor Description ChangeHistory(Configuration configuration)Creates a change history.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallChanges(IChangeHistoryVisitor visitor)Visits all changes.(package private) java.util.Set<AbstractIvmlVariable>changed()Returns all changed variables.(package private) IVariableFilterchangedFilter()Returns a filter for all changed variables.voidchanges(IChangeHistoryVisitor visitor)Visits the most recent changes into the top-most change set.voidclear(boolean resetOriginalValues)Clears the history.voidcommit()Commits the most recent change set into the one before or if there is none into the committed set.voidcommitAll()Commits the changes of all stacked change sets into the committed change set.protected voidfinalize()ValuegetOriginalValue(AbstractIvmlVariable variable)Returns the original value of a variable before any explicit change.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.IChangeHistoryTracergetTracer()Returns the current tracer.booleanhasChanges()Returns whether the current change set has direct changes (i.e., no indirect commits from other change sets).private static booleanisSameValue(Value value1, Value value2)Returns whethervalue1andvalue2are the same.(package private) voidnotifyChanged(AbstractIvmlVariable variable, Value value)Notifies the change set about a changed variable.voidrollback()Rolls back the most recent change set.voidrollbackAll()Rolls back all the changes in the uncommitted stack.voidrollbackSimulation()Rolls back all all changes.IChangeHistoryTracersetTracer(IChangeHistoryTracer tracer)Defines or unsets the configuration tracer.voidstart()Starts a new change set.
-
-
-
Field Detail
-
configuration
private Configuration configuration
-
tracer
private IChangeHistoryTracer tracer
-
originalValues
private java.util.Map<IDecisionVariable,Value> originalValues
-
committed
private ChangeHistory.CSet committed
-
changeSetStack
private java.util.Stack<ChangeHistory.CSet> changeSetStack
-
changeListener
private IConfigurationChangeListener changeListener
-
-
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:
finalizein classjava.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 throughvariableitself. 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 whethervalue1andvalue2are the same.- Parameters:
value1- the first value (may be null)value2- the second value (may be null)- Returns:
trueifvalue1is considered to be the same asvalue2,falseelse
-
notifyChanged
void notifyChanged(AbstractIvmlVariable variable, Value value)
Notifies the change set about a changed variable.- Parameters:
variable- the variablevalue- 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:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- 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
-
-