beowulf.model.graph
Class AbstractGraphModel

java.lang.Object
  extended bybeowulf.model.graph.AbstractGraphModel
All Implemented Interfaces:
GraphModel
Direct Known Subclasses:
Graph, UndirectedGraph

public abstract class AbstractGraphModel
extends Object
implements GraphModel

This abstract class defines event handling procedures common to all of its implementors. This is simply another level of abstraction, and allows another class to provide all of the implementation details on the actual operation of the graph. Certain rules must be followed by its subclasses to ensure that events are delivered to the approrpriate listeners. These rules are largely limited to calling the appropriate fireXXXX method after the occurrance of a certain GraphEvent.

Version:
1.0, 6/15/2003
Author:
Andy Scukanec (ags at cs dot cornell dot edu)

Field Summary
protected  EventListenerList listenerList
          This list contains references to all interested listeners.
 
Constructor Summary
AbstractGraphModel()
           
 
Method Summary
abstract  void addEdge(Edge edge)
          This method will add a new edge to the graph.
abstract  void addEdge(Object sourceValue, Object destinationValue, Object cost)
          This method will add a new edge to the graph.
 void addGraphListener(GraphListener l)
          This method adds a GraphListener as an interested listener of events to this Graph.
abstract  void addNode(Object value)
          This method adds a new node to the graph, and associates the parameter as the value of the node.
protected  void fireEdgeAdded(Object source, Object value)
          This method must be called by all subclasses after a edge is added to the Graph.
protected  void fireEdgeRemoved(Object source, Object value)
          This method must be called by all subclasses after a edge is removed from the Graph.
protected  void fireNodeAdded(Object source, Object value)
          This method must be called by all subclasses after a node is added to the Graph.
protected  void fireNodeRemoved(Object source, Object value)
          This method must be called by all subclasses after a node is removed from the Graph.
 GraphListener[] getGraphListeners()
          Returns an array of all the graph listeners registered on this AbstractGraphModel.
 EventListener[] getListeners(Class listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this model.
abstract  Object removeEdge(Edge toRemove)
          This method will remove the edge from the graph.
abstract  Object removeEdge(Object sourceValue, Object destinationValue, Object cost)
          This method will remove the edge with the indicated source and destination values from the graph.
 void removeGraphListener(GraphListener l)
          This method removes the GraphListener as an interestd listener of events to this Graph.
abstract  void removeNode(Object value)
          Given a node's value, this method will find and remove that node, and any associated edges from the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface beowulf.model.graph.GraphModel
getEdgeCount, getEdges, getEdgesFrom, getEdgesFromTo, getEdgesTo, getNodeCount, getNodes, getUseDotEquals, isDirected, isSimple, toString
 

Field Detail

listenerList

protected transient EventListenerList listenerList
This list contains references to all interested listeners.

Constructor Detail

AbstractGraphModel

public AbstractGraphModel()
Method Detail

addGraphListener

public void addGraphListener(GraphListener l)
This method adds a GraphListener as an interested listener of events to this Graph.

Specified by:
addGraphListener in interface GraphModel
Parameters:
l - The graph listener to add.

removeGraphListener

public void removeGraphListener(GraphListener l)
This method removes the GraphListener as an interestd listener of events to this Graph.

Specified by:
removeGraphListener in interface GraphModel
Parameters:
l - The graph listener to remove.

fireNodeAdded

protected void fireNodeAdded(Object source,
                             Object value)
This method must be called by all subclasses after a node is added to the Graph.

Parameters:
source - The graph on which the even occurred.
value - The value of the node that was added.

fireNodeRemoved

protected void fireNodeRemoved(Object source,
                               Object value)
This method must be called by all subclasses after a node is removed from the Graph.

Parameters:
source - The graph on which the even occurred.
value - The value of the node that was removed.

fireEdgeAdded

protected void fireEdgeAdded(Object source,
                             Object value)
This method must be called by all subclasses after a edge is added to the Graph.

Parameters:
source - The graph on which the even occurred.
value - The value of the edge that was added.

fireEdgeRemoved

protected void fireEdgeRemoved(Object source,
                               Object value)
This method must be called by all subclasses after a edge is removed from the Graph.

Parameters:
source - The graph on which the even occurred.
value - The value of the edge that was removed.

getGraphListeners

public GraphListener[] getGraphListeners()
Returns an array of all the graph listeners registered on this AbstractGraphModel.

Returns:
all of this model's GraphListeners, or an empty array if no graph listeners are currently registered

getListeners

public EventListener[] getListeners(Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a list model m for its list data listeners with the following code:

GraphListener[] gls =
 (GraphListener[])(m.getListeners(GraphListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
Throws:
ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener

removeNode

public abstract void removeNode(Object value)
Given a node's value, this method will find and remove that node, and any associated edges from the graph.

Parameters:
value - The value of the node to be removed.

addNode

public abstract void addNode(Object value)
This method adds a new node to the graph, and associates the parameter as the value of the node. If there exists a node in the graph with a value that is the same (according to .equals()) as the parameter, a RuntimException will be thrown with an error message stating that a graph cannot have two copies of the same node.

Parameters:
value - The value of the node to be added.

removeEdge

public abstract Object removeEdge(Edge toRemove)
This method will remove the edge from the graph. The cost of the edge removed will be returned.

Parameters:
toRemove - The edge to be removed.
Returns:
The cost of the edge that was removed.

removeEdge

public abstract Object removeEdge(Object sourceValue,
                                  Object destinationValue,
                                  Object cost)
This method will remove the edge with the indicated source and destination values from the graph. The cost of the edge removed will be returned.

Parameters:
sourceValue - The value of the source node of the edge.
destinationValue - The value of the destination node of the edge.
cost - The cost of the edge to be removed.
Returns:
The cost of the edge that was removed.

addEdge

public abstract void addEdge(Object sourceValue,
                             Object destinationValue,
                             Object cost)
This method will add a new edge to the graph. The new edge will have the indicated source value, destination value, and cost. If an edge was already in place between the indicated source and destination, this function will simply replace the old cost of that edge with the new cost. If either the sourceValue or destinationValue is not a value of a node in the graph, a RuntimeException will be thrown stating so in an error message.

Parameters:
sourceValue - The value of the source node of the new edge.
destinationValue - The value of the destination node of the new edge.
cost - The cost of the new edge.

addEdge

public abstract void addEdge(Edge edge)
This method will add a new edge to the graph. If an edge was already in place between the indicated source and destination, this function will simply replace the old cost of that edge with the new cost. If either the sourceValue or destinationValue is not a value of a node in the graph, a RuntimeException will be thrown stating so in an error message.

Parameters:
edge - The edge to be added to the graph.