ptolemy.graph
Class Element

java.lang.Object
  extended by ptolemy.graph.Element
Direct Known Subclasses:
Edge, Node

public abstract class Element
extends java.lang.Object

A base class for graph elements (nodes and edges). A graph element consists of an optional weight (an arbitrary object that is associated with the element). We say that an element is unweighted if it does not have an assigned weight. It is an error to attempt to access the weight of an unweighted element. Element weights must be non-null objects.

Since:
Ptolemy II 2.0
Version:
$Id: Element.java 41477 2006-03-29 00:03:58Z cxh $
Author:
Shuvra S. Bhattacharyya
See Also:
Edge, Node
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
protected  java.lang.Object _weight
          The weight that is associated with the element if the element is weighted.
 
Constructor Summary
Element()
          Construct an unweighted element.
Element(java.lang.Object weight)
          Construct an element with a given weight.
 
Method Summary
 java.lang.String descriptor()
          A one-word description of the type of this graph element.
 java.lang.Object getWeight()
          Return the weight that has been associated with this element.
 boolean hasWeight()
          Return true if and only if this is a weighted element.
 void removeWeight()
          Make the element unweighted.
 void setWeight(java.lang.Object weight)
          Set or change the weight of an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_weight

protected java.lang.Object _weight
The weight that is associated with the element if the element is weighted. If the element is not weighted, the value of this field is null.

Constructor Detail

Element

public Element()
Construct an unweighted element.


Element

public Element(java.lang.Object weight)
Construct an element with a given weight.

Parameters:
weight - The given weight.
Throws:
java.lang.IllegalArgumentException - If the specified weight is null.
Method Detail

descriptor

public java.lang.String descriptor()
A one-word description of the type of this graph element.

Returns:
The description.

getWeight

public final java.lang.Object getWeight()
Return the weight that has been associated with this element.

Returns:
The associated weight.
Throws:
java.lang.IllegalStateException - If this is an unweighted element.
See Also:
setWeight(Object)

hasWeight

public final boolean hasWeight()
Return true if and only if this is a weighted element.

Returns:
True if and only if this is a weighted element.

removeWeight

public final void removeWeight()
Make the element unweighted. This method should be used with caution since it may make the element incompatible with graphs that already contain it. The method has no effect if the element is already unweighted.

See Also:
Graph.validEdgeWeight(Object), Graph.validNodeWeight(Object), Graph.validateWeight(Node)

setWeight

public final void setWeight(java.lang.Object weight)
Set or change the weight of an element. This method should be used with caution since it may make the element incompatible with graphs that already contain it.

Parameters:
weight - The new weight.
Throws:
java.lang.IllegalArgumentException - If the object that is passed as argument is null.
See Also:
Graph.validEdgeWeight(Object), Graph.validNodeWeight(Object), Graph.validateWeight(Node), getWeight()