Class AttributeValues


  • public class AttributeValues
    extends java.lang.Object
    Stores attributes and their assigned values as an additional information to be considered while reasoning. Multiple values are possible in order to reflect a history of assigned values, e.g. due to multiple instantiations over several binding times. Value assignments made in this object are considered as an additional information and do no not directly change an existing configuration.
    Please note that persistent loading mechanisms may not have direct access to a model in order to properly resolve a persisted set of AttributeValues. However, this is indirectly supported by this class by support for storing values (toString(Value)), support for storing strings read from a persistent storage (addUnresolved(String, List) and by finally resolving the values in the context of a given model (resolveUsing(Project, boolean).
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Constructor Description
      AttributeValues()
      Creates a new set of attribute values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addUnresolved​(java.lang.String attribute, java.util.List<java.lang.String> values)
      Adds unresolved attributes and values.
      void addValue​(Attribute attribute, Value value)
      Adds a value for a given attribute.
      private static void appendError​(java.lang.StringBuilder builder, java.lang.String text)
      Appends text to builder.
      void clear()
      Deletes all value assignments.
      boolean contains​(Attribute attribute)
      Returns whether the given attribute is contained in this value set.
      java.util.Iterator<Attribute> getAttributes()
      Returns all attributes for which value assignments are stored.
      java.util.List<Attribute> getAttributesAsList()
      Returns all attributes for which value assignments are stored.
      java.util.Set<Attribute> getAttributesAsSet()
      Returns all attributes for which value assignments are stored.
      int getAttributesCount()
      Returns the number of attributes for which value assignments are stored in this instance.
      Value getAttributeValue​(Attribute attribute, int index)
      Returns the specific value assigned to attribute.
      int getAttributeValuesCount​(Attribute attribute)
      Returns the number of values assigned to attribute.
      boolean hasValue​(AbstractVariable attribute, Value value)
      Returns whether there is an assignment of value to attribute.
      boolean isEmpty()
      Returns whether there are value assignments.
      static boolean isEmpty​(AttributeValues values)
      Returns whether there are value assignments in values.
      void removeValue​(Attribute attribute, Value value)
      Remove a given value from the value assignment of attribute.
      void resolveUsing​(Project project, boolean clear)
      Resolve unresolved attributes in project.
      void setValue​(Attribute attribute, Value value, int index)
      Adds a value for a given attribute.
      void setValues​(Attribute target, Attribute source)
      Transfers all value assignments from source to target.
      java.lang.String toString()
      Returns a textual description of this object.
      static java.lang.String toString​(Value value)
      Turns a value into a string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • valueAssignments

        private java.util.Map<Attribute,​java.util.List<Value>> valueAssignments
      • unresolvedAssignments

        private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> unresolvedAssignments
    • Constructor Detail

      • AttributeValues

        public AttributeValues()
        Creates a new set of attribute values.
    • Method Detail

      • setValue

        public void setValue​(Attribute attribute,
                             Value value,
                             int index)
                      throws AttributeException
        Adds a value for a given attribute.
        Parameters:
        attribute - the attribute to assign the value for
        value - the value to assign
        index - the index of the value to be returned
        Throws:
        java.lang.IndexOutOfBoundsException - in case that index<0 || index>=getAttributeValuesCount(Attribute) with called same attribute (!)
        AttributeException - in case that value cannot be assigned to attribute
      • addValue

        public void addValue​(Attribute attribute,
                             Value value)
                      throws AttributeException
        Adds a value for a given attribute.
        Parameters:
        attribute - the attribute to assign the value for
        value - the value to assign
        Throws:
        AttributeException - in case that value cannot be assigned to attribute
      • removeValue

        public void removeValue​(Attribute attribute,
                                Value value)
        Remove a given value from the value assignment of attribute.
        Parameters:
        attribute - the attribute to remove the value from
        value - the value to be removed
      • getAttributesCount

        public int getAttributesCount()
        Returns the number of attributes for which value assignments are stored in this instance.
        Returns:
        the number of attributes
      • getAttributes

        public java.util.Iterator<Attribute> getAttributes()
        Returns all attributes for which value assignments are stored.
        Returns:
        all attributes as an iterator
      • getAttributesAsList

        public java.util.List<Attribute> getAttributesAsList()
        Returns all attributes for which value assignments are stored.
        Returns:
        all attributes as a list
      • getAttributesAsSet

        public java.util.Set<Attribute> getAttributesAsSet()
        Returns all attributes for which value assignments are stored.
        Returns:
        all attributes as a set
      • getAttributeValuesCount

        public int getAttributeValuesCount​(Attribute attribute)
        Returns the number of values assigned to attribute.
        Parameters:
        attribute - the attribute to return the number of values for
        Returns:
        the number of assigned values, -1 if attribute does not exist
      • getAttributeValue

        public Value getAttributeValue​(Attribute attribute,
                                       int index)
        Returns the specific value assigned to attribute.
        Parameters:
        attribute - the attribute to return the number of values for
        index - the index of the value to be returned
        Returns:
        the assigned value, null if attribute does not exist
        Throws:
        java.lang.IndexOutOfBoundsException - in case that index<0 || index>=getAttributeValuesCount(Attribute) with called same attribute (!)
      • hasValue

        public boolean hasValue​(AbstractVariable attribute,
                                Value value)
        Returns whether there is an assignment of value to attribute.
        Parameters:
        attribute - the attribute to check (we use the more common type to avoid superfluous type casts in the caller)
        value - the value to check for within attribute
        Returns:
        true if value is set for attribute, false else
      • clear

        public void clear()
        Deletes all value assignments.
      • isEmpty

        public boolean isEmpty()
        Returns whether there are value assignments.
        Returns:
        true if there are no value assignments, false else
      • isEmpty

        public static boolean isEmpty​(AttributeValues values)
        Returns whether there are value assignments in values.
        Parameters:
        values - the value assignments instance to be tested
        Returns:
        true if there are no value assignments (or values == null, false else
      • setValues

        public void setValues​(Attribute target,
                              Attribute source)
        Transfers all value assignments from source to target.
        Parameters:
        target - the target of the transfer (value assignments may be modified)
        source - the attribute where to take the assginments from
      • contains

        public boolean contains​(Attribute attribute)
        Returns whether the given attribute is contained in this value set.
        Parameters:
        attribute - the attribute to search for
        Returns:
        true if it is contained, false else
      • toString

        public java.lang.String toString()
        Returns a textual description of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a textual description
      • appendError

        private static void appendError​(java.lang.StringBuilder builder,
                                        java.lang.String text)
        Appends text to builder.
        Parameters:
        builder - the builder to append to
        text - the text to be appended
      • addUnresolved

        public void addUnresolved​(java.lang.String attribute,
                                  java.util.List<java.lang.String> values)
        Adds unresolved attributes and values. This method is intended if attribute values are about to be stored in a configuration file, read back from a mechanism which does not have access to the variability model and are then later resolved using resolveUsing(Project, boolean).
        Parameters:
        attribute - the name of the attribute
        values - the individual values
      • toString

        public static java.lang.String toString​(Value value)
        Turns a value into a string. Do not directly print a Value.
        Parameters:
        value - the value to be converted
        Returns:
        the textual representation