Class CompoundValue
- java.lang.Object
-
- net.ssehub.easy.varModel.model.values.Value
-
- net.ssehub.easy.varModel.model.values.StructuredValue
-
- net.ssehub.easy.varModel.model.values.CompoundValue
-
- All Implemented Interfaces:
java.lang.Cloneable
public class CompoundValue extends StructuredValue implements java.lang.Cloneable
CompoundValue class.- Author:
- Marcel Lueder, El-Sharkawy, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<java.lang.String,Value>nestedElementsstatic java.lang.StringSPECIAL_SLOT_NAME_TYPEDenotes an internal compound slot name during initialization which specifies the actual type of the compound (in case of container initializations defined on a refined compound).
-
Constructor Summary
Constructors Modifier Constructor Description (package private)CompoundValue()Constructor for serialization.(package private)CompoundValue(Compound compound)Constructor for a new CompoundValue.(package private)CompoundValue(Compound compound, java.lang.Object... value)Constructor for a new CompoundValue.protectedCompoundValue(Compound compound, CompoundValue source)Creates a new compound value by copying the values fromsource.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IValueVisitor visitor)Abstract accept method.private booleancheckAssignments(IDecisionVariableContainer container, CompoundValue otherValue, boolean ignoreUndefinedInObject)Checks the assignments for equality.private booleancheckElements(IDecisionVariableContainer container, CompoundValue otherValue, boolean ignoreUndefinedInObject)Checks the elements for equality.CompoundValueclone()Clones the this value.voidconfigureValue(java.lang.String name, java.lang.Object value)Method to get the object which a specific name of the hashMap.voidcopyValuesFrom(CompoundValue source)Copies the values fromsource.booleanequals(java.lang.Object object)private booleanequals(java.lang.Object object, boolean ignoreUndefinedInObject)Checks for equality potentially ignoring undefined values in the givenobject.private booleanequals(Compound type, CompoundValue otherValue, boolean ignoreUndefinedInObject)Checks for equality potentially ignoring undefined values in the giventype.booleanequalsPartially(Value value)Returns whether the providedvalueis partially equal to this value, i.e., whether the nested elements ofvalue(if they exist) have the same contents as in this value.static IDatatypegetActualType(java.lang.Object[] slotValues)Returns the actual type if stored asSPECIAL_SLOT_NAME_TYPEparameter in the given array.java.lang.BooleangetBooleanValue(java.lang.String slot)Returns the boolean value ofslot.intgetNestedElementsSize()Get the number of nested elements.ValuegetNestedValue(java.lang.String name)Returns the value for the variable with the given name.java.util.Collection<java.lang.String>getSlotNames()Returns the names of the assigned slots in this value.java.lang.StringgetStringValue(java.lang.String slot)Returns the string value ofslot.java.lang.ObjectgetValue()Abstract getValue method.inthashCode()private inthashCode(Compound type)Returns the hashCode for a compound type.private voidinitialize(IDecisionVariableContainer container, java.util.Map<java.lang.String,java.lang.Object> initialValues)Initializes a variable container.private voidinitializeAttributeAssignment(AttributeAssignment assng, java.util.Map<java.lang.String,java.lang.Object> initialValues)Initializes an attribute assignment.booleanisFullyConfigured()Method to check, whether each object of the Value has a value assigned.voidsetValue(java.lang.Object value)Abstract setValue-method.java.lang.StringtoString()-
Methods inherited from class net.ssehub.easy.varModel.model.values.StructuredValue
getValueParent, isConfigured, setValueParent
-
Methods inherited from class net.ssehub.easy.varModel.model.values.Value
equals, equalsPartially, getContainedType, getType, stringValueOf
-
-
-
-
Field Detail
-
SPECIAL_SLOT_NAME_TYPE
public static final java.lang.String SPECIAL_SLOT_NAME_TYPE
Denotes an internal compound slot name during initialization which specifies the actual type of the compound (in case of container initializations defined on a refined compound).- See Also:
- Constant Field Values
-
nestedElements
private java.util.HashMap<java.lang.String,Value> nestedElements
-
-
Constructor Detail
-
CompoundValue
CompoundValue()
Constructor for serialization.
-
CompoundValue
CompoundValue(Compound compound) throws ValueDoesNotMatchTypeException
Constructor for a new CompoundValue.- Parameters:
compound- compound which extends this CompoundValue- Throws:
ValueDoesNotMatchTypeException- if one of the default values do not comply to the respective types
-
CompoundValue
CompoundValue(Compound compound, java.lang.Object... value) throws ValueDoesNotMatchTypeException
Constructor for a new CompoundValue.- Parameters:
compound- compound which extends this CompoundValuevalue- initial value(s), two entries for each compound given as name and value- Throws:
ValueDoesNotMatchTypeException- if one of the default values do not comply to the respective types
-
CompoundValue
protected CompoundValue(Compound compound, CompoundValue source)
Creates a new compound value by copying the values fromsource.- Parameters:
compound- the compound typesource- the value which acts as a source for data
-
-
Method Detail
-
initializeAttributeAssignment
private void initializeAttributeAssignment(AttributeAssignment assng, java.util.Map<java.lang.String,java.lang.Object> initialValues) throws ValueDoesNotMatchTypeException
Initializes an attribute assignment.- Parameters:
assng- the assignment to initializeinitialValues- the initial values- Throws:
ValueDoesNotMatchTypeException- if one of the default values do not comply to the respective types
-
initialize
private void initialize(IDecisionVariableContainer container, java.util.Map<java.lang.String,java.lang.Object> initialValues) throws ValueDoesNotMatchTypeException
Initializes a variable container.- Parameters:
container- the variable containerinitialValues- the initial values- Throws:
ValueDoesNotMatchTypeException- if one of the default values do not comply to the respective types
-
getActualType
public static final IDatatype getActualType(java.lang.Object[] slotValues)
Returns the actual type if stored asSPECIAL_SLOT_NAME_TYPEparameter in the given array.- Parameters:
slotValues- the slot values, may be null- Returns:
- the actual type or null
-
getNestedValue
public Value getNestedValue(java.lang.String name)
Returns the value for the variable with the given name.- Parameters:
name- the name of the variable.- Returns:
- the value to which the specified name is mapped, or null if this Compound contains no variable with the specified name
-
getValue
public java.lang.Object getValue()
Description copied from class:ValueAbstract getValue method. The result of this method must comply to the input conventions ofValueFactoryand the constructor of the respective implementing class.
-
accept
public void accept(IValueVisitor visitor)
Description copied from class:ValueAbstract accept method.
-
configureValue
public void configureValue(java.lang.String name, java.lang.Object value) throws ValueDoesNotMatchTypeExceptionMethod to get the object which a specific name of the hashMap.- Parameters:
name- the key for the hashMapvalue- the value, which should be assigned to the key-object.- Throws:
ValueDoesNotMatchTypeException- if the given value does not match this type
-
copyValuesFrom
public void copyValuesFrom(CompoundValue source) throws ValueDoesNotMatchTypeException
Copies the values fromsource.- Parameters:
source- the source type- Throws:
ValueDoesNotMatchTypeException- in case that values do not match
-
setValue
public void setValue(java.lang.Object value) throws ValueDoesNotMatchTypeExceptionDescription copied from class:ValueAbstract setValue-method.- Specified by:
setValuein classValue- Parameters:
value- the value to set.- Throws:
ValueDoesNotMatchTypeException- if the given value does not match this type
-
isFullyConfigured
public boolean isFullyConfigured()
Description copied from class:StructuredValueMethod to check, whether each object of the Value has a value assigned.- Specified by:
isFullyConfiguredin classStructuredValue- Returns:
- true if all sub-elements are configured, else false
-
clone
public CompoundValue clone()
Description copied from class:ValueClones the this value.
-
hashCode
private int hashCode(Compound type)
Returns the hashCode for a compound type.- Parameters:
type- the type to calculate the hashCode for- Returns:
- the hashCode
-
equals
private boolean equals(java.lang.Object object, boolean ignoreUndefinedInObject)Checks for equality potentially ignoring undefined values in the givenobject.- Parameters:
object- the object to check forignoreUndefinedInObject- whether undefined values inobjectshall be ignored (partial equality)- Returns:
trueifobjectis considered equal to this,falseelse
-
equals
private boolean equals(Compound type, CompoundValue otherValue, boolean ignoreUndefinedInObject)
Checks for equality potentially ignoring undefined values in the giventype.- Parameters:
type- the compound to check forotherValue- the value to check forignoreUndefinedInObject- whether undefined values intypeshall be ignored (partial equality)- Returns:
trueiftypeis considered equal to this,falseelse
-
checkAssignments
private boolean checkAssignments(IDecisionVariableContainer container, CompoundValue otherValue, boolean ignoreUndefinedInObject)
Checks the assignments for equality.- Parameters:
container- the container to checkotherValue- the other value to compare againstignoreUndefinedInObject- whether undefined values inobjectshall be ignored (partial equality)- Returns:
trueifotheris considered equal to container,falseelse
-
checkElements
private boolean checkElements(IDecisionVariableContainer container, CompoundValue otherValue, boolean ignoreUndefinedInObject)
Checks the elements for equality.- Parameters:
container- the container to checkotherValue- the other value to compare againstignoreUndefinedInObject- whether undefined values inobjectshall be ignored (partial equality)- Returns:
trueifotheris considered equal to container,falseelse
-
equalsPartially
public boolean equalsPartially(Value value)
Description copied from class:ValueReturns whether the providedvalueis partially equal to this value, i.e., whether the nested elements ofvalue(if they exist) have the same contents as in this value. Other values of this value are not considered. The check is transitive on nested elements. Please consider that this method is not symmetric as opposed toequals. This method is important to cope with default values.- Specified by:
equalsPartiallyin classValue- Parameters:
value- the value to be checked for partial equality.- Returns:
trueifvalueis partially equal to this,falseelse
-
getStringValue
public java.lang.String getStringValue(java.lang.String slot)
Returns the string value ofslot. [utility method]- Parameters:
slot- the slot to return the string value for- Returns:
- the string value, null if not configured or if
slotdoes not contain a string value
-
getBooleanValue
public java.lang.Boolean getBooleanValue(java.lang.String slot)
Returns the boolean value ofslot. [utility method]- Parameters:
slot- the slot to return the string value for- Returns:
- the boolean value, null if not configured or if
slotdoes not contain a boolean value
-
getSlotNames
public java.util.Collection<java.lang.String> getSlotNames()
Returns the names of the assigned slots in this value.- Returns:
- the names of the assigned slots
-
getNestedElementsSize
public int getNestedElementsSize()
Get the number of nested elements.- Returns:
- size of nestedelements.
-
-