org.gersteinlab.tyna.core.graph
Class Node

java.lang.Object
  extended by org.gersteinlab.tyna.core.graph.Node
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class Node
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

        This class represents a node in a graph. Node ID is the only defined
        attribute. It has to be a non-null unique identifier. Other attributes
        such as node label (if not unique) and node color can be accessed
        through the attribute get-setters. Subclasses can be defined for node
        types that contain additional attributes, if that is more convenient
        than using the attribute get-setters.

        Edges are defined in graphs, the information is not stored in this
        class.

        The ID is to be assigned at object instantiation time only, and should
        not to be changed since it affects hashCode(), equals(), etc.

        Two nodes are the same if and only if they refer to the same object, or
        if they have the same non-null ID. hashCode() and equals() are defined
        in a way that both order-based structures (e.g. TreeSet) and hash-based
        structures (e.g. HashSet) can be used.
        

Version:
1.1 (January 14, 2006) Change History: 1.0 - Initial version 1.1 - Non-null ID becomes mandatory
Author:
Kevin Yuk-Lap Yip
See Also:
Serialized Form

Field Summary
protected  java.util.Map attrs
          The (possibly null) other attributes of the node.
protected  java.lang.Object id
          The ID of the node.
 
Constructor Summary
Node()
          Default constructor: creates a node with no ID or attributes.
Node(java.lang.Object id, java.util.Map attrs)
          Constructor: creates a node with an ID and/or attributes.
 
Method Summary
 int compareTo(java.lang.Object o)
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object getAttr(java.lang.Object attrName)
          Get the (possibly null) value of an attribute of the node.
 java.util.Map getAttrs()
          Get the (possibly null) attribute map of the node.
 java.lang.Object getId()
          Get the ID of the node.
 int hashCode()
           
 void removeAttr(java.lang.Object attrName)
          Remove the value of an attribute from the node.
 void setAttr(java.lang.Object attrName, java.lang.Object attrVal)
          Set the value of an attribute of the node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected java.lang.Object id
The ID of the node.


attrs

protected java.util.Map attrs
The (possibly null) other attributes of the node.

Constructor Detail

Node

public Node()
Default constructor: creates a node with no ID or attributes.


Node

public Node(java.lang.Object id,
            java.util.Map attrs)
Constructor: creates a node with an ID and/or attributes. Input null if not used. A copy of attrs, rather than the original object, is being stored.

Parameters:
id - The node ID
attrs - Node attributes
Method Detail

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable
Returns:
Determine by ID if present, otherwise by hashCode
See Also:
Comparable.compareTo(Object)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Returns:
true if and only if the input object refers to the same node as the current one (same non-null ID, or same object)
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
java.lang.object.hashCode if id == null, the hash code of ID otherwise. Beware not to use a node as the ID of another node, which will lead to recursive definitions.
See Also:
Object.hashCode()

getId

public java.lang.Object getId()
Get the ID of the node.

Returns:
The node ID

getAttr

public java.lang.Object getAttr(java.lang.Object attrName)
Get the (possibly null) value of an attribute of the node.

Parameters:
attrName - The name of the attribute
Returns:
The value of the attribute

getAttrs

public java.util.Map getAttrs()
Get the (possibly null) attribute map of the node. A copy of the stored map is returned.

Returns:
The attribute map

setAttr

public void setAttr(java.lang.Object attrName,
                    java.lang.Object attrVal)
Set the value of an attribute of the node.

Parameters:
attrName - The name of the attribute
attrVal - The value of the attribute

removeAttr

public void removeAttr(java.lang.Object attrName)
Remove the value of an attribute from the node.

Parameters:
attrName - The name of the attribute

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object