Class 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 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 ContainerValue
        value - 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 ContainerValue
        check - for duplicates
        value - the value(s) to be assigned to this container
        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: Value
        Returns the data type explicitly contained in this value. This is typically a meta value, i.e. a type expression.
        Overrides:
        getContainedType in class Value
        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. Use getElement(int) instead.
        Specified by:
        getValue in class Value
        Returns:
        null always
      • nestedValuesToString

        public java.lang.String nestedValuesToString()
        Turns the nested values into a string.
        Returns:
        the nested values as string
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Value
      • accept

        public void accept​(IValueVisitor visitor)
        Description copied from class: Value
        Abstract accept method.
        Specified by:
        accept in class Value
        Parameters:
        visitor - The visitor
      • isFullyConfigured

        public boolean isFullyConfigured()
        Description copied from class: StructuredValue
        Method to check, whether each object of the Value has a value assigned.
        Specified by:
        isFullyConfigured in class StructuredValue
        Returns:
        true if all sub-elements are configured, else false
      • clone

        public ContainerValue clone()
        Description copied from class: Value
        Clones the this value.
        Overrides:
        clone in class Value
        Returns:
        the clone of the 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 - if index<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 value or -1 if not found
      • isSetValue

        private boolean isSetValue()
        Checks whether this value belongs to a Set or 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 ValueDoesNotMatchTypeException
        Sets 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 this ContainerValue represents a value of a Set and 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 Value
        java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= getElementSize())
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Value
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class Value
      • doAll

        private void doAll​(java.util.HashSet<Value> set,
                           boolean add)
        Adds/removes all elements to/from set.
        Parameters:
        set - the set to add/remove
        add - add (true) or remove (false)
      • addElement

        public void addElement​(int pos,
                               Value value)
                        throws ValueDoesNotMatchTypeException
        Adds a value at the position pos.
        Parameters:
        pos - the position after which value shall be added
        value - the value to be added
        Throws:
        ValueDoesNotMatchTypeException - in case that the type of value does not match the container type of the containers or that index shall be applied to a set
        java.lang.IndexOutOfBoundsException - in case that pos is invalid
      • 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 of value does 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: Value
        Returns whether the provided value is partially equal to this value, i.e., whether the nested elements of value (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 to equals. This method is important to cope with default values.
        Specified by:
        equalsPartially in class Value
        Parameters:
        value - the value to be checked for partial equality.
        Returns:
        true if value is partially equal to this, false else
      • clear

        public void clear()
        Clears all elements.
      • iterator

        public java.util.Iterator<Value> iterator()
        Returns an iterator over all values.
        Returns:
        the iterator