org.carrot2.util.attribute
Class AttributeValueSets

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

public class AttributeValueSets
extends Object

Maintains a collection of AttributeValueSets and provides methods for serializing and deserializing attribute value sets from XML streams.


Constructor Summary
AttributeValueSets()
          Creates an empty collection of attribute value sets.
 
Method Summary
 void addAttributeValueSet(String id, AttributeValueSet attributeValueSet)
          Adds an AttributeValueSet to this collection.
 void addAttributeValueSet(String id, AttributeValueSet attributeValueSet, String newLabel, String newDescription)
          Adds an AttributeValueSet to this collection replacing its label and description.
static AttributeValueSets deserialize(InputStream inputStream)
          Deserializes a collection of AttributeValueSets from an XML stream.
 AttributeValueSet getAttributeValueSet(String id)
          Returns the AttributeValueSet corresponding to the provided id or null if no AttributeValueSet corresponds to the id.
 AttributeValueSet getAttributeValueSet(String id, boolean useDefault)
          Returns the AttributeValueSet corresponding to the provided id or the default AttributeValueSet (possibly null) if no AttributeValueSet corresponds to the id.
 Set<String> getAttributeValueSetIds()
          Returns identifiers of all AttributeValueSets in this collection.
 Set<AttributeValueSet> getAttributeValueSetsBasedOn(AttributeValueSet baseAttributeValueSet)
          Returns all AttributeValueSets from this collection that are based, directly or indirectly, on the provided baseAttributeValueSet.
 AttributeValueSet getDefaultAttributeValueSet()
          Returns the default AttributeValueSet of this AttributeValueSets or the first available AttributeValueSet if getDefaultAttributeValueSetId() is null.
 String getDefaultAttributeValueSetId()
          Returns the identifier of the default AttributeValueSet within this AttributeValueSets.
 void removeAttributeValueSet(String id)
          Removes the AttributeValueSet corresponding to the provided id from this collection.
 void serialize(OutputStream stream)
          Serializes this collection of AttributeValueSets to an XML stream.
 void setDefaultAttributeValueSetId(String defaultAttributeValueSetId)
          Sets the default attribute value set id for this AttributeValueSets.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeValueSets

public AttributeValueSets()
Creates an empty collection of attribute value sets.

Method Detail

addAttributeValueSet

public void addAttributeValueSet(String id,
                                 AttributeValueSet attributeValueSet)
Adds an AttributeValueSet to this collection.

Parameters:
id - unique identifier of the AttributeValueSet within the collection.
attributeValueSet - AttributeValueSet to be added

addAttributeValueSet

public void addAttributeValueSet(String id,
                                 AttributeValueSet attributeValueSet,
                                 String newLabel,
                                 String newDescription)
Adds an AttributeValueSet to this collection replacing its label and description. This method may sometimes be useful because AttributeValueSets are immutable with respect to their label and description.

Parameters:
id - unique identifier of the AttributeValueSet within the collection.
attributeValueSet - AttributeValueSet to be added
newLabel - new label for the AttributeValueSet
newDescription - new description for the AttributeValueSet

getAttributeValueSetIds

public Set<String> getAttributeValueSetIds()
Returns identifiers of all AttributeValueSets in this collection.

Returns:
identifiers of all AttributeValueSets in this collection.

getDefaultAttributeValueSetId

public String getDefaultAttributeValueSetId()
Returns the identifier of the default AttributeValueSet within this AttributeValueSets. The default identifier can be null.


setDefaultAttributeValueSetId

public void setDefaultAttributeValueSetId(String defaultAttributeValueSetId)
Sets the default attribute value set id for this AttributeValueSets. An AttributeValueSet with this id must exist in this AttributeValueSets.


getAttributeValueSet

public AttributeValueSet getAttributeValueSet(String id)
Returns the AttributeValueSet corresponding to the provided id or null if no AttributeValueSet corresponds to the id.

Returns:
the AttributeValueSet corresponding to the provided id or null if no AttributeValueSet corresponds to the id.

getAttributeValueSet

public AttributeValueSet getAttributeValueSet(String id,
                                              boolean useDefault)
Returns the AttributeValueSet corresponding to the provided id or the default AttributeValueSet (possibly null) if no AttributeValueSet corresponds to the id.

Parameters:
id - identifier of the AttributeValueSet to return
useDefault - if true, the default AttributeValueSet will be returned if the AttributeValueSet with the provided id does not exist.
Returns:
the AttributeValueSet corresponding to the provided id or the default AttributeValueSet (possibly null) if no AttributeValueSet corresponds to the id.

getDefaultAttributeValueSet

public AttributeValueSet getDefaultAttributeValueSet()
Returns the default AttributeValueSet of this AttributeValueSets or the first available AttributeValueSet if getDefaultAttributeValueSetId() is null. If this AttributeValueSets is empty, null will be returned.


removeAttributeValueSet

public void removeAttributeValueSet(String id)
Removes the AttributeValueSet corresponding to the provided id from this collection. If any other AttributeValueSets in this collection are based on the set being removed, the associations are corrected accordingly, i.e. sets based on the set being removed become based on the set the removed set is based on. Also, if the removed AttributeValueSet was the default, null will be set as this AttributeValueSets' default AttributeValueSet. If no AttributeValueSet corresponds to the provided id, no action is taken.

Parameters:
id - identifier of the AttributeValueSet to be removed

getAttributeValueSetsBasedOn

public Set<AttributeValueSet> getAttributeValueSetsBasedOn(AttributeValueSet baseAttributeValueSet)
Returns all AttributeValueSets from this collection that are based, directly or indirectly, on the provided baseAttributeValueSet.

Parameters:
baseAttributeValueSet - the base attribute value set

serialize

public void serialize(OutputStream stream)
               throws Exception
Serializes this collection of AttributeValueSets to an XML stream.

Parameters:
stream - the stream to serialize this AttributeValueSets to. The stream will not be closed.
Throws:
Exception - in case of any problems with serialization

deserialize

public static AttributeValueSets deserialize(InputStream inputStream)
                                      throws Exception
Deserializes a collection of AttributeValueSets from an XML stream.

Parameters:
inputStream - the InputStream to deserialize a AttributeValueSets from. The stream will not be closed.
Returns:
Deserialized collection of AttributeValueSets
Throws:
Exception - is case of any problems with deserialization.

toString

public String toString()
Overrides:
toString in class Object


Copyright (c) Dawid Weiss, Stanislaw Osinski