Class VariableValueCopier
java.lang.Object
net.ssehub.easy.varModel.cstEvaluation.VariableValueCopier
Copies specified variable values, i.e., single variables to a single variable or a compatible container or a
container to a container. In case of a container as source, the first value will be copied.
May create further variables in case of target reference types. Actually, this functionality might be done by
a more generic VIL function, but for now a simpler (internal) implementation is sufficient.
- Author:
- Holger Eichelberger
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefines a copy specification.static classA default freeze provider for but-expressions based on attributes of type enum.static interfaceOptional listener interface to generically track primary value assignments.static interfaceAn interface providing information to create freeze blocks for new variables.private static classA freeze provider based on known frozen assignment states. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate Stringprivate IAssignmentStateprivate Map<IDatatype, Map<String, VariableValueCopier.CopySpec>> -
Constructor Summary
ConstructorsConstructorDescriptionVariableValueCopier(String namePrefix, IAssignmentState newState, VariableValueCopier.CopySpec... copySpecs) Creates an instance with given assignment state.VariableValueCopier(String namePrefix, VariableValueCopier.CopySpec... copySpecs) Creates an instance for copying with stateAssignmentState.ASSIGNED. -
Method Summary
Modifier and TypeMethodDescription(package private) static IDecisionVariablecopy(IDecisionVariable variable, String namePrefix) Copies the given variable.private Valuecopy(IDecisionVariable source, IDecisionVariable target, VariableValueCopier.IFreezeProvider freezeProvider) Copies the value ofsourcevariable to targetvariable.private ValuecopySingleVariable(IDecisionVariable source, IDecisionVariable target, VariableValueCopier.IFreezeProvider freezeProvider, boolean adding) Copies a single variable fromsourceto target and ensures in case of a reference target that a respective variable is created.static booleandoCreateNewVars(String namePrefix) Whether new variables shall be created.private voiddoFreeze(VariableValueCopier.IFreezeProvider freezeProvider, Configuration cfg, IDecisionVariable var, IFreezable freezable) Tries to freezefreezable.private ContainerVariableEnsures that the given container variable is configured and empty.static IDecisionVariablefindVariable(IDecisionVariable base, String qname) Finds a variable via its (qualified access) name.protected net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerReturns the logger of this class.private voidhandleFurther(IDecisionVariable base, String[] names, Value value) Assignsvalueto the further variables onbasegiven innamesat index positions larger than 0.private static ValueKeeps the first value ofactualandnewValue.private voidnotifyAssigned(IDecisionVariable target, Value value, boolean added) Notifies about assigned values.private voidnotifyCreated(IDecisionVariable origin, IDecisionVariable target) Notifies the listener about a new variable created for a given origin variable.voidprocess(Configuration config) Processes a configuration according to the copy specifications.private voidprocess(IDecisionVariable variable, IDecisionVariable base, String prefix, Map<String, VariableValueCopier.CopySpec> fieldSpecs, Set<IDecisionVariable> done) Processes a decision variable.voidDefines the assignment listener.
-
Field Details
-
specs
-
namePrefix
-
count
private int count -
newState
-
listener
-
-
Constructor Details
-
VariableValueCopier
Creates an instance for copying with stateAssignmentState.ASSIGNED.- Parameters:
namePrefix- the name prefix for new variables (no new variables will be created if null or empty).copySpecs- the copy specifications to take into account, individual specs may be null but will be ignored then
-
VariableValueCopier
public VariableValueCopier(String namePrefix, IAssignmentState newState, VariableValueCopier.CopySpec... copySpecs) Creates an instance with given assignment state.- Parameters:
namePrefix- the name prefix for new variables (no new variables will be created if null or empty).newState- the state to use (if null,AssignmentState.ASSIGNEDis used)copySpecs- the copy specifications to take into account
-
-
Method Details
-
setAssignmentListener
Defines the assignment listener.- Parameters:
listener- the listener (may be null to disable notifications)
-
getLogger
protected net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger getLogger()Returns the logger of this class.- Returns:
- the logger
-
process
public void process(Configuration config) throws ConfigurationException, ValueDoesNotMatchTypeException, CSTSemanticException Processes a configuration according to the copy specifications.- Parameters:
config- the configuration to process- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions such as freeze-buts are not correctly constructed
-
process
private void process(IDecisionVariable variable, IDecisionVariable base, String prefix, Map<String, VariableValueCopier.CopySpec> fieldSpecs, Set<IDecisionVariable> done) throws ConfigurationException, ValueDoesNotMatchTypeException, CSTSemanticExceptionProcesses a decision variable.- Parameters:
variable- the variable to processbase- the base variable where processing initially startedprefix- the prefix access name processed so farfieldSpecs- the field specifications forbasedone- already processed variables - avoiding cycles- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions such as freeze-buts are not correctly constructed
-
handleFurther
private void handleFurther(IDecisionVariable base, String[] names, Value value) throws ConfigurationException Assignsvalueto the further variables onbasegiven innamesat index positions larger than 0.- Parameters:
base- the base variablenames- the further variable names to initializevalue- the value to use for initialization- Throws:
ConfigurationException- in case that the configuration is not possible
-
findVariable
Finds a variable via its (qualified access) name.- Parameters:
base- the base variable to search onqname- the variable name to search for- Returns:
- the resulting variable or null if there is none
-
copy
private Value copy(IDecisionVariable source, IDecisionVariable target, VariableValueCopier.IFreezeProvider freezeProvider) throws ConfigurationException, ValueDoesNotMatchTypeException, CSTSemanticException Copies the value ofsourcevariable to targetvariable.- Parameters:
source- the source variable to copy fromtarget- the target variable to copy tofreezeProvider- optional freeze provider to be applied to new variables (may be null for no freezing)- Returns:
- the first value set (may be null)
- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions such as freeze-buts are not correctly constructed
-
keepFirst
Keeps the first value ofactualandnewValue.- Parameters:
actual- the actual valuenewValue- the new value- Returns:
actualifactualwas previously null,newValueelse
-
ensureContainerVariable
private ContainerVariable ensureContainerVariable(ContainerVariable target) throws ConfigurationException, ValueDoesNotMatchTypeException Ensures that the given container variable is configured and empty.- Parameters:
target- the variable- Returns:
target- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not match
-
doCreateNewVars
Whether new variables shall be created.- Parameters:
namePrefix- the name prefix- Returns:
truefor new variables,falseelse
-
copySingleVariable
private Value copySingleVariable(IDecisionVariable source, IDecisionVariable target, VariableValueCopier.IFreezeProvider freezeProvider, boolean adding) throws ConfigurationException, ValueDoesNotMatchTypeException, CSTSemanticException Copies a single variable fromsourceto target and ensures in case of a reference target that a respective variable is created.- Parameters:
source- the source variabletarget- the target variable (may be a nested variable, e.g., of a collection)freezeProvider- optional freeze provider to be applied to new variables (may be null for no freezing)adding- whether the value is being added to a collection or just set- Returns:
- the actual value set
- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions such as freeze-buts are not correctly constructed
-
doFreeze
private void doFreeze(VariableValueCopier.IFreezeProvider freezeProvider, Configuration cfg, IDecisionVariable var, IFreezable freezable) throws ValueDoesNotMatchTypeException, CSTSemanticException Tries to freezefreezable.- Parameters:
freezeProvider- the freeze provider (may be null, ignored then)cfg- the configuration to freeze onvar- the variable to freezefreezable- the freezeable (the declaration ofvar, used for constructing a temporary freeze block of no direct freeze selector is available- Throws:
ValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions such as freeze-buts are not correctly constructed
-
notifyAssigned
Notifies about assigned values.- Parameters:
target- the target variablevalue- the new valueadded- whether value is being added to a collection or set as the single absolute value
-
notifyCreated
Notifies the listener about a new variable created for a given origin variable. AnotifyAssigned(IDecisionVariable, Value, boolean)shall follow.- Parameters:
origin- the origin variabletarget- the new variable
-
copy
static IDecisionVariable copy(IDecisionVariable variable, String namePrefix) throws CSTSemanticException, ValueDoesNotMatchTypeException, ConfigurationException Copies the given variable.- Parameters:
variable- the variable to copynamePrefix- the name prefix for new variables.- Returns:
- the created (local, temporary) variable including value; further variables may have been created
- Throws:
ConfigurationException- in case that the configuration is not possibleValueDoesNotMatchTypeException- in case that value types do not matchCSTSemanticException- in case that expressions are not correctly constructed
-