Class AbstractIvmlVariable
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.configuration.IvmlElement
-
- net.ssehub.easy.instantiation.core.model.vilTypes.configuration.AbstractIvmlVariable
-
- All Implemented Interfaces:
IResolvable,IActualTypeProvider,IStringValueProvider,IVilType
- Direct Known Subclasses:
Attribute,DecisionVariable
public abstract class AbstractIvmlVariable extends IvmlElement implements IActualTypeProvider
Wraps a decision variable. Primitive values may be obtained using the getter methods. Complex values such as compounds or containers may be provided by subclasses.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractIvmlVariable.DecVarImplements a dynamic mapping of nested (container) values to temporary decision variables.-
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 Configurationconfigprotected IVariableFilterfilterprivate DecisionVariable[]nestedprotected IDecisionVariableorigVariableprivate static ValueVisitorVALUE_VISITORprotected IDecisionVariablevariable
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIvmlVariable(Configuration cfg, IDecisionVariable variable, IVariableFilter filter)Creates a new IVML variable.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DecisionVariableaddValue()Adds a value if the actual variable represents an IVML collection.DecisionVariableaddValue(TypeDescriptor<?> type)Adds a value if the actual variable represents an IVML collection.private DecisionVariableaddValue(IDatatype type)adds a value of a given type to a container.abstract Set<Attribute>annotations()Returns the annotations for this variable.abstract Set<Attribute>attributes()Returns the annotations for this variable.private voidchangeValue(IDecisionVariable toChange, java.lang.Object value)Changes the value of the given variable.voidclearValue()Clears the actual variable.voidcreateValue(boolean override)Creates a value matching to this variable and tries to assign it.voidcreateValue(TypeDescriptor<?> type, boolean override)Creates a value matching to this variable and tries to assign it.private voidcreateValue(IDecisionVariable var, IDatatype type)Creates a value for the giventypeviaa safe reasoner adapter.IDatatypedetermineActualTypeName()The more actual type name of this object.booleanequals(java.lang.Object object)IDatatypegetActualType()Returns the actual IVML type ofdecVar.java.lang.BooleangetBooleanValue()Returns the boolean value of the decision variable.DecisionVariablegetByName(java.lang.String name)Returns the decision variable with the given (qualified) name.ConfigurationgetConfiguration()Returns the configuration.IDecisionVariablegetDecisionVariable()Return the underlying decision variable for internal purpose, such as velocity.IvmlDeclarationgetDeclaration()Returns the declaration of this variable in terms of VIL/VTL instances.IvmlElementgetElement(java.lang.String name)Returns the element matching the given (qualified) name.EnumValuegetEnumValue()Returns the boolean value of the decision variable.java.lang.StringgetInstanceName()Returns the instance name of this element.java.lang.IntegergetIntegerValue()Returns the integer value of the decision variable.IDatatypegetIvmlType()Returns the declared IVML type of the (dereferenced) decision variable (VIL view).private EASyLoggerFactory.EASyLoggergetLogger()Returns the logger for this class.java.lang.StringgetName()Returns the simple name of the decision variable.java.lang.ObjectgetOriginalValue()Returns the original value before any change.IvmlElementgetParent()Returns the parent of this variable.java.lang.StringgetQualifiedName()Returns the qualified name of the decision variable.java.lang.StringgetQualifiedType()Returns the qualified type name of the decision variable.java.lang.StringgetQualifiedVarName()Returns the name of the underlying decision variable.java.lang.DoublegetRealValue()Returns the real value of the decision variable.java.lang.StringgetStringValue()Returns the string value of the decision variable.TypeDescriptor<?>getType()Returns the type of the (dereferenced) decision variable (VIL view).java.lang.StringgetTypeName()Returns the simple type name of the (dereferenced) decision variable (VIL view).java.lang.ObjectgetValue()Returns the (untyped) value of the decision variable.IDecisionVariablegetVariable()Returns the underlying IVML (un-dereferenced) variable.java.lang.StringgetVarName()Returns the name of the underlying decision variable.inthashCode()protected voidinitializeNested()Lazily initializes the nested parts.booleanisConfigured()Returns whether the underlying decision variable is configured.booleanisFrozen()Returns whether this element is frozen.booleanisVariable(IDecisionVariable var)Returns whether this instances holdsvar.ConfigurationselectAll()Returns a projected configuration on all nested variables.voidsetValue(java.lang.Object value)Changes the value of this variable.static java.lang.ObjecttoObject(Value value)Returns value into the corresponding (VIL) object value.java.lang.StringtoString()private static voidtransferState(IDecisionVariable source, IDecisionVariable target)Transfers the states betweensourceandtarget.Sequence<DecisionVariable>variables()Returns the decision variables contained in this variable.Set<DecisionVariable>variablesSet()Returns the decision variables contained in this variable as a set.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.configuration.IvmlElement
checkElement, equals, equals2, getAnnotation, getAnnotation, getAttribute, getAttribute, getAttribute, getAttributeCount, getStringValue, getTypeDescriptor, initializeAttributes, isEnacting, isNull, isValid, search, unequals, unequals2
-
-
-
-
Field Detail
-
VALUE_VISITOR
private static final ValueVisitor VALUE_VISITOR
-
origVariable
protected IDecisionVariable origVariable
-
variable
protected IDecisionVariable variable
-
filter
protected IVariableFilter filter
-
nested
private DecisionVariable[] nested
-
config
private Configuration config
-
-
Constructor Detail
-
AbstractIvmlVariable
protected AbstractIvmlVariable(Configuration cfg, IDecisionVariable variable, IVariableFilter filter)
Creates a new IVML variable.- Parameters:
cfg- the parent configurationvariable- the variable to be wrappedfilter- the variable filter to apply
-
-
Method Detail
-
getConfiguration
public Configuration getConfiguration()
Returns the configuration.- Returns:
- the configuration
-
isVariable
public boolean isVariable(IDecisionVariable var)
Returns whether this instances holdsvar.- Parameters:
var- the variable to look for- Returns:
trueifvaris held by this instance,falseelse
-
getParent
public IvmlElement getParent()
Returns the parent of this variable.- Returns:
- the parent if it exists
-
initializeNested
protected void initializeNested()
Description copied from class:IvmlElementLazily initializes the nested parts.- Specified by:
initializeNestedin classIvmlElement
-
getVariable
public IDecisionVariable getVariable()
Returns the underlying IVML (un-dereferenced) variable.- Returns:
- the underlying IVML variable
-
getActualType
public IDatatype getActualType()
Returns the actual IVML type ofdecVar.- Returns:
- the IVML type, if possible the actual, dynamic type, else the declared type
-
getName
public java.lang.String getName()
Returns the simple name of the decision variable.- Specified by:
getNamein interfaceIResolvable- Specified by:
getNamein classIvmlElement- Returns:
- the simple name
-
getQualifiedName
public java.lang.String getQualifiedName()
Returns the qualified name of the decision variable.- Specified by:
getQualifiedNamein classIvmlElement- Returns:
- the qualified name
-
getVarName
public java.lang.String getVarName()
Returns the name of the underlying decision variable. If the variable is referenced (via a reference), then the name of the referenced variable will be returned instead of the variable representing the reference.- Returns:
- the name of the underlying decision variable
-
getQualifiedVarName
public java.lang.String getQualifiedVarName()
Returns the name of the underlying decision variable. If the variable is referenced (via a reference), then the qualified name of the referenced variable will be returned instead of the variable representing the reference.- Returns:
- the qualified name of the underlying decision variable
-
getType
public TypeDescriptor<?> getType()
Returns the type of the (dereferenced) decision variable (VIL view).- Specified by:
getTypein interfaceIActualTypeProvider- Specified by:
getTypein classIvmlElement- Returns:
- the type (if configured the dynamic, actual type), else the defined type
-
getTypeName
public java.lang.String getTypeName()
Returns the simple type name of the (dereferenced) decision variable (VIL view).- Specified by:
getTypeNamein classIvmlElement- Returns:
- the simple type name
-
getIvmlType
public IDatatype getIvmlType()
Returns the declared IVML type of the (dereferenced) decision variable (VIL view).- Returns:
- the IVML type
-
getQualifiedType
public java.lang.String getQualifiedType()
Returns the qualified type name of the decision variable.- Specified by:
getQualifiedTypein classIvmlElement- Returns:
- the qualified type name
-
isConfigured
public boolean isConfigured()
Returns whether the underlying decision variable is configured. Please note that this is different fromIvmlElement.isNull()as a null value is considered as configured.- Returns:
trueif the variable is configured,falseelse
-
isFrozen
public boolean isFrozen()
Returns whether this element is frozen.- Returns:
trueif it is frozen,falseelse
-
clearValue
public void clearValue()
Clears the actual variable. Has no effect if frozen.
-
setValue
public void setValue(java.lang.Object value)
Changes the value of this variable. This method works only if the variable is notfrozen, in particular at runtime.- Parameters:
value- the new value
-
changeValue
private void changeValue(IDecisionVariable toChange, java.lang.Object value)
Changes the value of the given variable.- Parameters:
toChange- the variable to changevalue- the new value
-
getOriginalValue
public java.lang.Object getOriginalValue()
Returns the original value before any change. Intended for runtime reconfiguration. In VIL, this always returns the value ofgetValue()- Returns:
- the original value
-
toObject
public static java.lang.Object toObject(Value value)
Returns value into the corresponding (VIL) object value.- Parameters:
value- the value- Returns:
- the object value
-
getValue
public java.lang.Object getValue()
Description copied from class:IvmlElementReturns the (untyped) value of the decision variable.- Specified by:
getValuein classIvmlElement- Returns:
- the value (may be null)
-
getStringValue
public java.lang.String getStringValue()
Description copied from class:IvmlElementReturns the string value of the decision variable.- Specified by:
getStringValuein classIvmlElement- Returns:
- the value (may be null)
-
getIntegerValue
public java.lang.Integer getIntegerValue()
Description copied from class:IvmlElementReturns the integer value of the decision variable.- Specified by:
getIntegerValuein classIvmlElement- Returns:
- the value (may be null)
-
getRealValue
public java.lang.Double getRealValue()
Description copied from class:IvmlElementReturns the real value of the decision variable.- Specified by:
getRealValuein classIvmlElement- Returns:
- the value (may be null)
-
getBooleanValue
public java.lang.Boolean getBooleanValue()
Description copied from class:IvmlElementReturns the boolean value of the decision variable.- Specified by:
getBooleanValuein classIvmlElement- Returns:
- the value (may be null)
-
getEnumValue
public EnumValue getEnumValue()
Description copied from class:IvmlElementReturns the boolean value of the decision variable.- Specified by:
getEnumValuein classIvmlElement- Returns:
- the value (may be null)
-
variables
public Sequence<DecisionVariable> variables()
Returns the decision variables contained in this variable. This shall be a sequence to implicitly handle IVML sequences. Primitive values may be obtained using the getter methods. Complex values such as compounds or containers may be accessed viavariables().- Returns:
- the decision variables (unmodifiable)
-
variablesSet
public Set<DecisionVariable> variablesSet()
Returns the decision variables contained in this variable as a set.- Returns:
- the decision variables (unmodifiable)
-
selectAll
public Configuration selectAll()
Returns a projected configuration on all nested variables.- Returns:
- the projected configuration
-
attributes
public abstract Set<Attribute> attributes()
Returns the annotations for this variable.- Returns:
- the decision variables
-
annotations
public abstract Set<Attribute> annotations()
Returns the annotations for this variable.- Returns:
- the decision variables
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
getElement
public IvmlElement getElement(java.lang.String name)
Description copied from class:IvmlElementReturns the element matching the given (qualified) name.- Specified by:
getElementin classIvmlElement- Parameters:
name- the name to search for- Returns:
- the matching element or null if not found
-
getByName
public DecisionVariable getByName(java.lang.String name)
Returns the decision variable with the given (qualified) name.- Parameters:
name- the name of the variable to return- Returns:
- the variable or null if not found
-
getDecisionVariable
public IDecisionVariable getDecisionVariable()
Return the underlying decision variable for internal purpose, such as velocity.- Returns:
- the decision variable
-
getDeclaration
public IvmlDeclaration getDeclaration()
Returns the declaration of this variable in terms of VIL/VTL instances.- Returns:
- the declaration
-
getInstanceName
public java.lang.String getInstanceName()
Description copied from class:IvmlElementReturns the instance name of this element.- Overrides:
getInstanceNamein classIvmlElement- Returns:
- the instance name
-
getLogger
private EASyLoggerFactory.EASyLogger getLogger()
Returns the logger for this class.- Returns:
- the logger
-
createValue
public void createValue(boolean override)
Creates a value matching to this variable and tries to assign it. Failures will be logged and ignored.- Parameters:
override- try overriding the existing value (true) or just do nothing if a value already exists (false)
-
createValue
public void createValue(TypeDescriptor<?> type, boolean override)
Creates a value matching to this variable and tries to assign it. Failures will be logged and ignored.- Parameters:
type- the type of value to createoverride- try overriding the existing value (true) or just do nothing if a value already exists (false)
-
createValue
private void createValue(IDecisionVariable var, IDatatype type)
Creates a value for the giventypeviaa safe reasoner adapter.- Parameters:
var- the target variable to modifytype- the type to create the value for- See Also:
createValue(IDecisionVariable, IDatatype)
-
transferState
private static void transferState(IDecisionVariable source, IDecisionVariable target)
Transfers the states betweensourceandtarget. May be required if the configuration initialization just freezes everything without evaluating constraints. The given variables must be of the same type.- Parameters:
source- the source variable to take the states fromtarget- the target the target variable to apply the states to
-
addValue
public DecisionVariable addValue()
Adds a value if the actual variable represents an IVML collection. The declared element type is used as type of the new value.- Returns:
- the added variable
-
addValue
public DecisionVariable addValue(TypeDescriptor<?> type)
Adds a value if the actual variable represents an IVML collection.- Parameters:
type- the desired type of the new variable (must be compatible to the element type of the underlying collection)- Returns:
- the added variable
-
addValue
private DecisionVariable addValue(IDatatype type)
adds a value of a given type to a container.- Parameters:
type- the type- Returns:
- the created variable
- See Also:
createValue(IDecisionVariable, IDatatype)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
determineActualTypeName
public IDatatype determineActualTypeName()
Description copied from interface:IActualTypeProviderThe more actual type name of this object.- Specified by:
determineActualTypeNamein interfaceIActualTypeProvider- Returns:
- the more actual type name (may be null if none can be determined)
-
-