mapss.dif
Class DIFAttribute

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

public class DIFAttribute
extends java.lang.Object

Attribute class for DIF graphs. DIFAttribute is contained by AttributeContainer. Each element (mocgraph.Node or mocgraph.Edge) in a DIFGraph associates with an AttributeContainer containing all attributes (DIFAttribute) of that element.

A value of a DIFAttribute can be either an instance of graph element (reference type) or value object. The refenence type can be an instance of Port, Edge, Node, or DIFParameter, or a LinkedList of those graph objects. The value object of an DIFAttribute can be one of the following classes: Integer, Double, Complex, String, Boolean, int[], double[], Complex[], int[][], double[][], Complex[][], ArrayList. setDataType(java.lang.String) and getDataType() can be used to specify and get the datatype information of the value object.

A DIFAttribute can have a type. A type of a DIFAttribute is the class identifier of the object represented by that DIFAttribute. In some cases, attributes of the same actor can have the same name but different types, the type of DIFAttribute is used to distinguish between them. For example, a Ptolemy actor may have a parameter called "input" and have a IOPort called "input".

Version:
$Id: DIFAttribute.java 409 2007-05-13 19:47:16Z plishker $
Author:
Chia-Jui Hsu
See Also:
DIFGraph

Constructor Summary
protected DIFAttribute()
          Empty default constructor.
  DIFAttribute(java.lang.String name)
          Constructor.
 
Method Summary
protected  java.lang.Object _cloneValue(java.lang.Object map)
          Clone token value.
protected  void _setContainer(AttributeContainer container)
          AttributeContainer.setAttribute(mapss.dif.DIFAttribute) will set the back reference.
 java.lang.Object clone()
          Return the cloned version of DIFAttribute with the same name, same type, and same value.
 java.lang.Object clone(java.lang.Object map)
          Return the cloned version of DIFAttribute with the same name, the same type, the same value, and the reference of Node, Edge, or DIFParameter object, or the deep clone of LinkedList.
 boolean equals(java.lang.Object object)
          Compare the DIFAttribute object with the input object.
 AttributeContainer getContainer()
          Get container.
 java.lang.String getDataType()
          Get datatype of the value of attribute.
 java.lang.String getName()
          Get attribute name.
 java.lang.String getType()
          Get attribute type.
 java.lang.Object getValue()
          Get attribute value.
 int hashCode()
           
 void setDataType(java.lang.String datatype)
          Set the datatype of the value of attribute.
 void setType(java.lang.String type)
          Set the type of attribute.
 java.lang.Object setValue(java.lang.Object value)
          Set attribute value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DIFAttribute

protected DIFAttribute()
Empty default constructor.


DIFAttribute

public DIFAttribute(java.lang.String name)
Constructor.

Parameters:
name - The attribute name.
Throws:
java.lang.IllegalArgumentException - If Conventions.labelConvention(java.lang.String) returns an error for the parameter name.
Method Detail

clone

public java.lang.Object clone()
Return the cloned version of DIFAttribute with the same name, same type, and same value. For reference value referring to other element, we cannot simply copy the reference. Thus, if _value contains a reference, its cloned version is null. This clone() method does not copy the backward reference to AttributeContainer, ie, _container, instead, it is null in the cloned version. AttributeContainer.clone() will handle this backward reference.

Overrides:
clone in class java.lang.Object
Returns:
Cloned DIFAttribute instance.

clone

public java.lang.Object clone(java.lang.Object map)
Return the cloned version of DIFAttribute with the same name, the same type, the same value, and the reference of Node, Edge, or DIFParameter object, or the deep clone of LinkedList. For reference value, the mirrored object is obtained by map that contains the mapping from the original reference value to the cloned reference value. This clone() method does not copy the backward reference to AttributeContainer, ie, _container, instead, it is null in the cloned version. AttributeContainer.clone(Object) will handle this backward reference.

Parameters:
map - The Map that contains the mapping from the original reference value to the mirrored reference value.
Returns:
Cloned DIFAttribute instance.
See Also:
_cloneValue(Object)

equals

public boolean equals(java.lang.Object object)
Compare the DIFAttribute object with the input object. This method compares their name, type, and token value. To compare _value fields in both objects, we use their toString() methods to make the comparison.

Overrides:
equals in class java.lang.Object
Parameters:
object - The DIFAttribute instance.
Returns:
True if equal, otherwise, false.

getContainer

public AttributeContainer getContainer()
Get container. Note that AttributeContainer.setAttribute() will set the back reference.

Returns:
An AttributeContainer

getDataType

public java.lang.String getDataType()
Get datatype of the value of attribute.

Returns:
datatype

getName

public java.lang.String getName()
Get attribute name.

Returns:
name

getType

public java.lang.String getType()
Get attribute type. DIF provides three built-in actor attribute types: INPUT, OUTPUT, and PARAMETER. Users can also specify their own types. Another way to use attribute type is to indicate its actual class. For example, a TypedIOPort in Ptolemy actor corrosponds to an attribute with the same name and type "ptolemy.actor.TypedIOPort".

Returns:
attribute type

getValue

public java.lang.Object getValue()
Get attribute value.

Returns:
The value of this attribute or the reference (port, edge, or DIFParameter) of this attribute.
See Also:
setValue(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

setDataType

public void setDataType(java.lang.String datatype)
Set the datatype of the value of attribute. E.g., int, float, int*, float*.

Parameters:
datatype -

setType

public void setType(java.lang.String type)
Set the type of attribute. DIF provides three built-in actor attribute types: INPUT, OUTPUT, and PARAMETER. Users can also specify their own types. Another way to use attribute type is to indicate its actual class. For example, a TypedIOPort in Ptolemy actor corrosponds to an attribute with the same name and type "ptolemy.actor.TypedIOPort".

Parameters:
type -

setValue

public java.lang.Object setValue(java.lang.Object value)
Set attribute value.

Parameters:
value - A value object. The current DIF Language supports are Integer, Double, Complex, String, Boolean, int[], double[], Complex[], int[][], double[][], Complex[][], ArrayList, or an object of Port/Edge/Node/DIFParameter, or a LinkedList of objects.
Returns:
The previous value object.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String description of attribute's name, type, and value.

_cloneValue

protected java.lang.Object _cloneValue(java.lang.Object map)
Clone token value. If _value contains a reference to an element object, it finds the cloned object by using map. Note that it will return null if map does not contain the mapping. Users must be aware of this.

Parameters:
map - The HashMap object.
See Also:
clone(Object)

_setContainer

protected void _setContainer(AttributeContainer container)
AttributeContainer.setAttribute(mapss.dif.DIFAttribute) will set the back reference.

Parameters:
container - The AttributeContainer containes this DIFAttribute.