Package ptolemy.graph
Class Element
- java.lang.Object
-
- ptolemy.graph.Element
-
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Object
_weight
The weight that is associated with the element if the element is weighted.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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()
Returntrue
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.
-
-
-
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()
Returntrue
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.
-
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()
-
-