Class ContainerValue
- java.lang.Object
-
- net.ssehub.easy.varModel.model.values.Value
-
- net.ssehub.easy.varModel.model.values.StructuredValue
-
- net.ssehub.easy.varModel.model.values.ContainerValue
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ContainerValue extends StructuredValue implements java.lang.Cloneable
ContainerValue class.- Author:
- Marcel Lueder, El-Sharkawy, Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Value>nestedElements
-
Constructor Summary
Constructors Modifier Constructor Description (package private)ContainerValue()Constructor for serialization.(package private)ContainerValue(Container container)Constructor for a new ContainerValue.ContainerValue(Container container, boolean check, java.lang.Object... value)Constructor for a new ContainerValue.(package private)ContainerValue(Container container, java.lang.Object... value)Constructor for a new ContainerValue.protectedContainerValue(Container container, ContainerValue source)Creates a new compound value by copying the values fromsource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(IValueVisitor visitor)Abstract accept method.voidaddElement(int pos, Value value)Adds avalueat the positionpos.voidaddElement(Value value)Adds an element to this container.private voidcheckContainedType(Value value)Checks whethervalueis type compliant with thegetContainedType().voidclear()Clears all elements.ContainerValueclone()Clones the this value.voidcopyValuesFrom(ContainerValue source)Copies the values fromsource.private voiddoAll(java.util.HashSet<Value> set, boolean add)Adds/removes all elements to/fromset.private booleanduplicateValues(java.lang.Object[] values)Checks whether the given array has duplicated values and this value belongs to a set.booleanequals(java.lang.Object other)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.IDatatypegetContainedType()Returns the data type explicitly contained in this value.ValuegetElement(int index)Returns the specified element.intgetElementSize()Returns the number of elements in this container.java.lang.ObjectgetValue()Getter for the value.inthashCode()intindexOf(Value value)Returns the (first) index of the specified (nested) value.booleanisFullyConfigured()Method to check, whether each object of the Value has a value assigned.private booleanisSetValue()Checks whether this value belongs to aSetor an Sequence.java.util.Iterator<Value>iterator()Returns an iterator over all values.java.lang.StringnestedValuesToString()Turns the nested values into a string.voidremoveElement(int index)Removes a value from this container.voidremoveElement(Value value)Removes a value from this container.voidsetValue(int index, Value nestedValue)Sets the value for an already existent nested value.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, getType, stringValueOf
-
-
-
-
Field Detail
-
nestedElements
private java.util.List<Value> nestedElements
-
-
Constructor Detail
-
ContainerValue
ContainerValue()
Constructor for serialization.
-
ContainerValue
ContainerValue(Container container, java.lang.Object... value) throws ValueDoesNotMatchTypeException
Constructor for a new ContainerValue.- Parameters:
container- the container which extends this ContainerValuevalue- the value(s) to be assigned to this container- Throws:
ValueDoesNotMatchTypeException- if the given value does not match this type
-
ContainerValue
public ContainerValue(Container container, boolean check, java.lang.Object... value) throws ValueDoesNotMatchTypeException
Constructor for a new ContainerValue.- Parameters:
container- the container which extends this ContainerValuecheck- for duplicatesvalue- the value(s) to be assigned to this container- Throws:
ValueDoesNotMatchTypeException- if the given value does not match this type
-
ContainerValue
protected ContainerValue(Container container, ContainerValue source) throws ValueDoesNotMatchTypeException
Creates a new compound value by copying the values fromsource.- Parameters:
container- the container typesource- the value which acts as a source for data- Throws:
ValueDoesNotMatchTypeException- if the given value does not match this type
-
ContainerValue
ContainerValue(Container container)
Constructor for a new ContainerValue.- Parameters:
container- the container which extends this ContainerValue
-
-
Method Detail
-
getContainedType
public IDatatype getContainedType()
Description copied from class:ValueReturns the data type explicitly contained in this value. This is typically a meta value, i.e. a type expression.- Overrides:
getContainedTypein classValue- Returns:
- the contained type or null if there is none
-
getValue
public java.lang.Object getValue()
Getter for the value. Do not use! This value instance has substructures and does not hold a single value. UsegetElement(int)instead.
-
nestedValuesToString
public java.lang.String nestedValuesToString()
Turns the nested values into a string.- Returns:
- the nested values as string
-
accept
public void accept(IValueVisitor visitor)
Description copied from class:ValueAbstract accept method.
-
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
-
copyValuesFrom
public void copyValuesFrom(ContainerValue source) throws ValueDoesNotMatchTypeException
Copies the values fromsource.- Parameters:
source- the source type- Throws:
ValueDoesNotMatchTypeException- in case that values do not match
-
clone
public ContainerValue clone()
Description copied from class:ValueClones the this value.
-
getElementSize
public int getElementSize()
Returns the number of elements in this container.- Returns:
- the number of elements
-
getElement
public Value getElement(int index)
Returns the specified element.- Parameters:
index- the index of the element to be returned- Returns:
- the specified element
- Throws:
java.lang.IndexOutOfBoundsException- ifindex<0 || index>=getElementSize()
-
indexOf
public int indexOf(Value value)
Returns the (first) index of the specified (nested) value.- Parameters:
value- the value to search for- Returns:
- the first index of
valueor-1if not found
-
isSetValue
private boolean isSetValue()
Checks whether this value belongs to aSetor an Sequence.- Returns:
- true if this value belongs to a
Set, otherwise false.
-
duplicateValues
private boolean duplicateValues(java.lang.Object[] values)
Checks whether the given array has duplicated values and this value belongs to a set.- Parameters:
values- The values, which shall be assigned to this ContainerValue.- Returns:
- true if this value belongs to a set and the value array contains duplicates, otherwise false.
-
setValue
public void setValue(int index, Value nestedValue) throws ValueDoesNotMatchTypeExceptionSets the value for an already existent nested value.- Parameters:
index- The index of the element to be configured.nestedValue- The new value of the nested element.- Throws:
ValueDoesNotMatchTypeException- IF thisContainerValuerepresents a value of aSetand the new nestedValue is already part of this value.java.lang.IllegalArgumentException- if some property of the specified element prevents it from being added to this Valuejava.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >=getElementSize())
-
doAll
private void doAll(java.util.HashSet<Value> set, boolean add)
Adds/removes all elements to/fromset.- Parameters:
set- the set to add/removeadd- add (true) or remove (false)
-
addElement
public void addElement(int pos, Value value) throws ValueDoesNotMatchTypeExceptionAdds avalueat the positionpos.- Parameters:
pos- the position after whichvalueshall be addedvalue- the value to be added- Throws:
ValueDoesNotMatchTypeException- in case that the type ofvaluedoes not match the container type of the containers or that index shall be applied to a setjava.lang.IndexOutOfBoundsException- in case that pos is invalid
-
checkContainedType
private void checkContainedType(Value value) throws ValueDoesNotMatchTypeException
Checks whethervalueis type compliant with thegetContainedType().- Parameters:
value- the value to check for- Throws:
ValueDoesNotMatchTypeException- in case that the type ofvaluedoes not match the container type of the containers
-
addElement
public void addElement(Value value) throws ValueDoesNotMatchTypeException
Adds an element to this container. Shall only be called during dynamic execution.- Parameters:
value- the value to be added- Throws:
ValueDoesNotMatchTypeException- in case that the type ofvaluedoes not match the container type of the containers
-
removeElement
public void removeElement(Value value)
Removes a value from this container.- Parameters:
value- the value to be removed
-
removeElement
public void removeElement(int index)
Removes a value from this container.- Parameters:
index- the index position of the value to be removed- Throws:
java.lang.IndexOutOfBoundsException- in case that the index is illegal
-
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
-
clear
public void clear()
Clears all elements.
-
iterator
public java.util.Iterator<Value> iterator()
Returns an iterator over all values.- Returns:
- the iterator
-
-