Class ContainerValue

All Implemented Interfaces:
Cloneable

public class ContainerValue extends StructuredValue implements Cloneable
ContainerValue class.
Author:
Marcel Lueder, El-Sharkawy, Holger Eichelberger
  • Field Details

    • nestedElements

      private List<Value> nestedElements
  • Constructor Details

    • ContainerValue

      ContainerValue()
      Constructor for serialization.
    • ContainerValue

      ContainerValue(Container container, 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, 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

      protected ContainerValue(Container container, ContainerValue source) throws ValueDoesNotMatchTypeException
      Creates a new compound value by copying the values from source.
      Parameters:
      container - the container type
      source - 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 Details

    • 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 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 String nestedValuesToString()
      Turns the nested values into a string.
      Returns:
      the nested values as string
    • toString

      public 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
    • setValue

      public void setValue(Object value) throws ValueDoesNotMatchTypeException
      Description copied from class: Value
      Abstract setValue-method.
      Specified by:
      setValue in class Value
      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: 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
    • copyValuesFrom

      public void copyValuesFrom(ContainerValue source) throws ValueDoesNotMatchTypeException
      Copies the values from source.
      Parameters:
      source - the source type
      Throws:
      ValueDoesNotMatchTypeException - in case that values do not match
    • 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:
      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 a Sequence.
      Returns:
      true if this value belongs to a Set, otherwise false.
    • duplicateValues

      private boolean duplicateValues(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.
      IllegalArgumentException - if some property of the specified element prevents it from being added to this Value
      IndexOutOfBoundsException - if the index is out of range (index &lt; 0 || index &gt;= {@link #getElementSize()})
    • hashCode

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

      public boolean equals(Object other)
      Overrides:
      equals in class Value
    • doAll

      private void doAll(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
      IndexOutOfBoundsException - in case that pos is invalid
    • checkContainedType

      private void checkContainedType(Value value) throws ValueDoesNotMatchTypeException
      Checks whether value is type compliant with the getContainedType().
      Parameters:
      value - the value to check for
      Throws:
      ValueDoesNotMatchTypeException - in case that the type of value does 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 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:
      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 Iterator<Value> iterator()
      Returns an iterator over all values.
      Returns:
      the iterator