mapss.dif
Class AttributeContainer

java.lang.Object
  extended by mapss.dif.AttributeContainer

public class AttributeContainer
extends java.lang.Object

Container class for attributes used in DIFGraph. This class contains the implementation details of how attributes are handled in DIFGraph. For each mocgraph.Edge, mocgraph.Node, or DIFGraph object, there is an associated AttributeContainer containing all the attributes of that object. Also there are setName(java.lang.String) and getName() methods of the AttributeContainer which is for storing the name of the object (Edge/Node) in a graph.

Each DIFAttribute is recognized by its name.

The AttributeContainer utilizes LinkedHashMap to store DIFAttributes. To retrive a DIFAttribute, using DIFAttribute.getName() as key. (Note that it is updated from using both name and type as a key to just name. In general, every actor attribute should have a unique name, and type is just used as supplementary information. However, in this case, an actor having multiple attributes with same name and different types is not supported.) To get the list of DIFAttributes, the "linked" property can maintain the order of insertion.

Version:
$Id: AttributeContainer.java 409 2007-05-13 19:47:16Z plishker $
Author:
Chia-Jui Hsu based on the first version by Fuat Keceli
See Also:
DIFGraph, DIFAttribute

Constructor Summary
AttributeContainer()
           
AttributeContainer(java.lang.String name)
           
 
Method Summary
protected  void _setContainer(java.lang.Object container)
           
 java.lang.Object clone()
          Clone the AttributeContainer and return the cloned version.
 java.lang.Object clone(java.lang.Object map)
          Clone the AttributeContainer and return the cloned version basedon map that contains the mapping from the original reference value to the cloned reference value.
 boolean equals(java.lang.Object container)
          Test if an attribute container is equal to this one.
 DIFAttribute getAttribute(java.lang.String name)
          Returns the DIFAttribute in this container with the given name.
 DIFAttribute getAttributeByContent(java.lang.Object value)
          Returns the first DIFAttribute with the same value, ie, getValue() == value.
 java.util.LinkedList getAttributeNames()
          Returns a LinkedList of the names of all DIFAttributes in this container.
 java.util.LinkedList getAttributes()
          Returns the LinkedList of DIFAttributes in this container.
 java.util.LinkedList getAttributesByContent(java.lang.Object value)
          Returns the DIFAttributes in this container with the same value, ie, getValue() == value.
 java.lang.Object getContainer()
          Returns the object contains this AttributeContainer.
 java.lang.String getName()
          Returns the name of this container set by setName method.
 int hashCode()
          Returns the hash code for this object.
 void removeAllAttributes()
          Reset this attribute container.
 DIFAttribute removeAttribute(DIFAttribute attribute)
          Removes the DIFAttribute from the container.
 DIFAttribute removeAttribute(java.lang.String name)
          Removes the DIFAttribute with the given name.
 DIFAttribute setAttribute(DIFAttribute attribute)
          Set the attribute with the given name and DIFAttribute.
 java.lang.String setName(java.lang.String name)
          Sets the name of this container.
 java.lang.String toString()
          Returns the description of this attribute container.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeContainer

public AttributeContainer()

AttributeContainer

public AttributeContainer(java.lang.String name)
Method Detail

clone

public java.lang.Object clone()
Clone the AttributeContainer and return the cloned version. All the DIFAttributes in the AttributeContainer are cloned by calling DIFAttribute.clone()

Overrides:
clone in class java.lang.Object
Returns:
The cloned AttributeContainer.

clone

public java.lang.Object clone(java.lang.Object map)
Clone the AttributeContainer and return the cloned version basedon map that contains the mapping from the original reference value to the cloned reference value. All the DIFAttributes in the AttributeContainer are cloned by calling DIFAttribute.clone(Object). The cloned version of object that contains this AttributeContainer should call _setContainer of this class.

Parameters:
map - The HashMap that contains the mapping from the original reference value to the cloned reference value.
Returns:
The cloned AttributeContainer.
See Also:
DIFAttribute

equals

public boolean equals(java.lang.Object container)
Test if an attribute container is equal to this one. It is equal if it is of the same class and all the attributes are the same. For two attributes to be the same they should have the same names and same values but not necessarily the same objects.

Overrides:
equals in class java.lang.Object
Parameters:
container - The attribute container with which to compare this container.
Returns:
True if the container is equal to this one.

getAttribute

public DIFAttribute getAttribute(java.lang.String name)
Returns the DIFAttribute in this container with the given name.

Parameters:
name - Name of the attribute.
Returns:
The DIFAttribute. Null if it doesn't exist.

getAttributeByContent

public DIFAttribute getAttributeByContent(java.lang.Object value)
Returns the first DIFAttribute with the same value, ie, getValue() == value. Or if DIFAttribute contains a list of objects and that list contains the same value object.

Parameters:
value - The value object.
Returns:
The DIFAttribute. Null if it doesn't exist.

getAttributesByContent

public java.util.LinkedList getAttributesByContent(java.lang.Object value)
Returns the DIFAttributes in this container with the same value, ie, getValue() == value. Or if DIFAttribute contains a list of objects and that list contains the same value object.

Parameters:
value - The value object.
Returns:
The LinkedList of DIFAttributes containes the value. Or an empty LinkedList if not found.

getAttributes

public java.util.LinkedList getAttributes()
Returns the LinkedList of DIFAttributes in this container.

Returns:
The LinkedList of DIFAttributes.

getAttributeNames

public java.util.LinkedList getAttributeNames()
Returns a LinkedList of the names of all DIFAttributes in this container.

Returns:
A LinkedList of Strings.

getContainer

public java.lang.Object getContainer()
Returns the object contains this AttributeContainer. Note that this AttributeContainer may associate with a node, an edge, or the graph itself.

Returns:
the object contains this AttributeContainer.

getName

public java.lang.String getName()
Returns the name of this container set by setName method.


hashCode

public int hashCode()
Returns the hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash code for this object.

removeAttribute

public DIFAttribute removeAttribute(java.lang.String name)
Removes the DIFAttribute with the given name.

Parameters:
name - Name of the attribute.
Returns:
The previous attribute. Null if it didn't exist.

removeAttribute

public DIFAttribute removeAttribute(DIFAttribute attribute)
Removes the DIFAttribute from the container.

Parameters:
attribute - The DIFAttribute object.
Returns:
The previous attribute. Null if it didn't exist.

removeAllAttributes

public void removeAllAttributes()
Reset this attribute container.


setAttribute

public DIFAttribute setAttribute(DIFAttribute attribute)
Set the attribute with the given name and DIFAttribute.

Parameters:
attribute - The DIFAttribute.
Returns:
The previous DIFAttribute with the same name (and type) if it existed before. Null otherwise.

setName

public java.lang.String setName(java.lang.String name)
Sets the name of this container. Note that DIFGraph use this name to recognize the name of edges and nodes.

Returns:
The previous name of this container.
Throws:
java.lang.IllegalArgumentException - If Conventions.labelConvention(java.lang.String) returns an error.

toString

public java.lang.String toString()
Returns the description of this attribute container. The description contains the name of the object as defined by setName(java.lang.String) method and names and values of the attributes. Attributes are sorted according to their names so this description is canonical.

Overrides:
toString in class java.lang.Object
Returns:
Description of this container.

_setContainer

protected void _setContainer(java.lang.Object container)