Class AttributeValues
- java.lang.Object
-
- net.ssehub.easy.reasoning.core.reasoner.AttributeValues
-
public class AttributeValues extends java.lang.ObjectStores 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 ofAttributeValues. 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAttributeValues.ResolutionVisitorA visitor for resolving attribute values.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<java.lang.String>>unresolvedAssignmentsprivate java.util.Map<Attribute,java.util.List<Value>>valueAssignments
-
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 voidaddUnresolved(java.lang.String attribute, java.util.List<java.lang.String> values)Adds unresolved attributes and values.voidaddValue(Attribute attribute, Value value)Adds avaluefor a given attribute.private static voidappendError(java.lang.StringBuilder builder, java.lang.String text)Appendstexttobuilder.voidclear()Deletes all value assignments.booleancontains(Attribute attribute)Returns whether the givenattributeis 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.intgetAttributesCount()Returns the number of attributes for which value assignments are stored in this instance.ValuegetAttributeValue(Attribute attribute, int index)Returns the specific value assigned toattribute.intgetAttributeValuesCount(Attribute attribute)Returns the number of values assigned toattribute.booleanhasValue(AbstractVariable attribute, Value value)Returns whether there is an assignment ofvaluetoattribute.booleanisEmpty()Returns whether there are value assignments.static booleanisEmpty(AttributeValues values)Returns whether there are value assignments invalues.voidremoveValue(Attribute attribute, Value value)Remove a givenvaluefrom the value assignment ofattribute.voidresolveUsing(Project project, boolean clear)Resolve unresolved attributes inproject.voidsetValue(Attribute attribute, Value value, int index)Adds avaluefor a given attribute.voidsetValues(Attribute target, Attribute source)Transfers all value assignments fromsourcetotarget.java.lang.StringtoString()Returns a textual description of this object.static java.lang.StringtoString(Value value)Turns avalueinto a string.
-
-
-
Method Detail
-
setValue
public void setValue(Attribute attribute, Value value, int index) throws AttributeException
Adds avaluefor a given attribute.- Parameters:
attribute- the attribute to assign thevalueforvalue- the value to assignindex- the index of the value to be returned- Throws:
java.lang.IndexOutOfBoundsException- in case thatindex<0 || index>=with called samegetAttributeValuesCount(Attribute)attribute(!)AttributeException- in case that value cannot be assigned to attribute
-
addValue
public void addValue(Attribute attribute, Value value) throws AttributeException
Adds avaluefor a given attribute.- Parameters:
attribute- the attribute to assign thevalueforvalue- 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 givenvaluefrom the value assignment ofattribute.- Parameters:
attribute- the attribute to remove the value fromvalue- 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 toattribute.- Parameters:
attribute- the attribute to return the number of values for- Returns:
- the number of assigned values,
-1if attribute does not exist
-
getAttributeValue
public Value getAttributeValue(Attribute attribute, int index)
Returns the specific value assigned toattribute.- Parameters:
attribute- the attribute to return the number of values forindex- the index of the value to be returned- Returns:
- the assigned value, null if
attributedoes not exist - Throws:
java.lang.IndexOutOfBoundsException- in case thatindex<0 || index>=with called samegetAttributeValuesCount(Attribute)attribute(!)
-
hasValue
public boolean hasValue(AbstractVariable attribute, Value value)
Returns whether there is an assignment ofvaluetoattribute.- 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 withinattribute- Returns:
trueif value is set forattribute,falseelse
-
clear
public void clear()
Deletes all value assignments.
-
isEmpty
public boolean isEmpty()
Returns whether there are value assignments.- Returns:
trueif there are no value assignments,falseelse
-
isEmpty
public static boolean isEmpty(AttributeValues values)
Returns whether there are value assignments invalues.- Parameters:
values- the value assignments instance to be tested- Returns:
trueif there are no value assignments (orvalues == null,falseelse
-
setValues
public void setValues(Attribute target, Attribute source)
Transfers all value assignments fromsourcetotarget.- 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 givenattributeis contained in this value set.- Parameters:
attribute- the attribute to search for- Returns:
trueif it is contained,falseelse
-
toString
public java.lang.String toString()
Returns a textual description of this object.- Overrides:
toStringin classjava.lang.Object- Returns:
- a textual description
-
resolveUsing
public void resolveUsing(Project project, boolean clear) throws AttributeException
Resolve unresolved attributes inproject. In case that resolution works properly,valueAssignmentswill be changed andunresolvedAssignmentswill be set to null.- Parameters:
project- the project used to resolve unresolved attributes added byaddUnresolved(String, List)clear- clear the contents of this instance before resolving- Throws:
AttributeException- in case that the resolution fails and this instance was not changed
-
appendError
private static void appendError(java.lang.StringBuilder builder, java.lang.String text)Appendstexttobuilder.- Parameters:
builder- the builder to append totext- 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 usingresolveUsing(Project, boolean).- Parameters:
attribute- the name of the attributevalues- the individual values
-
toString
public static java.lang.String toString(Value value)
Turns avalueinto a string. Do not directly print a Value.- Parameters:
value- the value to be converted- Returns:
- the textual representation
-
-