org.carrot2.util.attribute
Class AttributeValueSet

java.lang.Object
  extended by org.carrot2.util.attribute.AttributeValueSet

public class AttributeValueSet
extends Object

Maintains a named set of attribute values. Allows one AttributeValueSet (A) to be "based" on another AttributeValueSet (B), whereby the main AttributeValueSet (A) inherits all values from the base AttributeValueSet (B) and can override some of them. Any depth of the base attribute sets hierarchy is possible.


Field Summary
 String description
          Human-readable description of this attribute value set.
 String label
          Human-readable value of this attribute value set.
 
Constructor Summary
AttributeValueSet(String label)
          Creates a new empty AttributeValueSet with a null description and a null base attribute value set.
AttributeValueSet(String label, AttributeValueSet base)
          Creates a new empty AttributeValueSet with a null description.
AttributeValueSet(String label, String description, AttributeValueSet base)
          Creates a new empty AttributeValueSet.
 
Method Summary
 Object getAttributeValue(String key)
          Returns value of the attribute with the provided key.
 Map<String,Object> getAttributeValues()
          Returns attribute values defined by this AttributeValueSet and all other AttributeValueSets that this set is based on.
static Map<String,Object> getAttributeValues(AttributeValueSet attributeValueSet)
          Returns attribute values from the provided AttributeValueSet or null if the provided AttributeValueSet is null.
 Object setAttributeValue(String key, Object value)
          Sets a value corresponding to the provided key in this attribute value set.
 void setAttributeValues(Map<String,Object> values)
          Copies all values to this attribute value set.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

label

public String label
Human-readable value of this attribute value set. Only for read-only use.


description

public String description
Human-readable description of this attribute value set. Only for read-only use.

Constructor Detail

AttributeValueSet

public AttributeValueSet(String label)
Creates a new empty AttributeValueSet with a null description and a null base attribute value set.

Parameters:
label - human-readable label for this attribute value set

AttributeValueSet

public AttributeValueSet(String label,
                         AttributeValueSet base)
Creates a new empty AttributeValueSet with a null description.

Parameters:
label - human-readable label for this attribute value set
base - the attribute value set this set should be based on.

AttributeValueSet

public AttributeValueSet(String label,
                         String description,
                         AttributeValueSet base)
Creates a new empty AttributeValueSet.

Parameters:
label - human-readable label for this attribute value set
description - human-readable description for this attribute value set, can be null
base - the attribute value set this set should be based on, can be null.
Method Detail

getAttributeValue

public Object getAttributeValue(String key)
Returns value of the attribute with the provided key. Attribute values are resolved in the following order:

Parameters:
key - key of the attribute for which value is to be returned
Returns:
value of the attribute or null.

getAttributeValues

public Map<String,Object> getAttributeValues()
Returns attribute values defined by this AttributeValueSet and all other AttributeValueSets that this set is based on. The returned map is independent of this AttributeValueSet, so any modifications to that map will not be reflected in this AttributeValueSet.


setAttributeValue

public Object setAttributeValue(String key,
                                Object value)
Sets a value corresponding to the provided key in this attribute value set. If the set previously contained some value under the provided key, that value is returned. Values set using this method override values found in the base attribute sets of this set.

Parameters:
key - attribute key
value - attribute value
Returns:
previous value of the attribute or null

setAttributeValues

public void setAttributeValues(Map<String,Object> values)
Copies all values to this attribute value set. If this attribute value set already contains mappings for some of the provided key, the mappings will be overwritten. Values set using this method override values found in the base attribute sets of this set.

Parameters:
values - values to be set on this attribute value set.

getAttributeValues

public static Map<String,Object> getAttributeValues(AttributeValueSet attributeValueSet)
Returns attribute values from the provided AttributeValueSet or null if the provided AttributeValueSet is null.


toString

public String toString()
Overrides:
toString in class Object


Copyright (c) Dawid Weiss, Stanislaw Osinski