org._3pq.jgrapht.graph

Class DefaultListenableGraph

Implemented Interfaces:
Cloneable, Graph, ListenableGraph, Serializable
Known Direct Subclasses:
ListenableDirectedGraph, ListenableUndirectedGraph

public class DefaultListenableGraph
extends GraphDelegator
implements ListenableGraph, Cloneable

A graph backed by the the graph specified at the constructor, which can be listened by GraphListeners and by VertexSetListeners. Operations on this graph "pass through" to the to the backing graph. Any modification made to this graph or the backing graph is reflected by the other.

This graph does not pass the hashCode and equals operations through to the backing graph, but relies on Object's equals and hashCode methods.

Author:
Barak Naveh
Since:
Jul 20, 2003
See Also:
GraphListener, VertexSetListener

Constructor Summary

DefaultListenableGraph(Graph g)
Creates a new listenable graph.
DefaultListenableGraph(Graph g, boolean reuseEvents)
Creates a new listenable graph.

Method Summary

Edge
addEdge(Object sourceVertex, Object targetVertex)
boolean
addEdge(Edge e)
void
addGraphListener(GraphListener l)
boolean
addVertex(Object v)
void
addVertexSetListener(VertexSetListener l)
Object
clone()
protected void
fireEdgeAdded(Edge edge)
Notify listeners that the specified edge was added.
protected void
fireEdgeRemoved(Edge edge)
Notify listeners that the specified edge was removed.
protected void
fireVertexAdded(Object vertex)
Notify listeners that the specified vertex was added.
protected void
fireVertexRemoved(Object vertex)
Notify listeners that the specified vertex was removed.
boolean
isReuseEvents()
Tests whether the reuseEvents flag is set.
Edge
removeEdge(Object sourceVertex, Object targetVertex)
boolean
removeEdge(Edge e)
void
removeGraphListener(GraphListener l)
boolean
removeVertex(Object v)
void
removeVertexSetListener(VertexSetListener l)
void
setReuseEvents(boolean reuseEvents)
If the reuseEvents flag is set to true this class will reuse previously fired events and will not create a new object for each event.

Methods inherited from class org._3pq.jgrapht.graph.GraphDelegator

addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, inDegreeOf, incomingEdgesOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, toString, vertexSet

Methods inherited from class org._3pq.jgrapht.graph.AbstractGraph

addAllEdges, addAllVertices, assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets

Constructor Details

DefaultListenableGraph

public DefaultListenableGraph(Graph g)
Creates a new listenable graph.
Parameters:
g - the backing graph.

DefaultListenableGraph

public DefaultListenableGraph(Graph g,
                              boolean reuseEvents)
Creates a new listenable graph. If the reuseEvents flag is set to true this class will reuse previously fired events and will not create a new object for each event. This option increases performance but should be used with care, especially in multithreaded environment.
Parameters:
g - the backing graph.
reuseEvents - whether to reuse previously fired event objects instead of creating a new event object for each event.

Method Details

addEdge

public Edge addEdge(Object sourceVertex,
                    Object targetVertex)
Specified by:
addEdge in interface Graph
Overrides:
addEdge in interface GraphDelegator

addEdge

public boolean addEdge(Edge e)
Specified by:
addEdge in interface Graph
Overrides:
addEdge in interface GraphDelegator

addGraphListener

public void addGraphListener(GraphListener l)
Specified by:
addGraphListener in interface ListenableGraph

addVertex

public boolean addVertex(Object v)
Specified by:
addVertex in interface Graph
Overrides:
addVertex in interface GraphDelegator

addVertexSetListener

public void addVertexSetListener(VertexSetListener l)
Specified by:
addVertexSetListener in interface ListenableGraph

clone

public Object clone()
See Also:
java.lang.Object.clone()

fireEdgeAdded

protected void fireEdgeAdded(Edge edge)
Notify listeners that the specified edge was added.
Parameters:
edge - the edge that was added.

fireEdgeRemoved

protected void fireEdgeRemoved(Edge edge)
Notify listeners that the specified edge was removed.
Parameters:
edge - the edge that was removed.

fireVertexAdded

protected void fireVertexAdded(Object vertex)
Notify listeners that the specified vertex was added.
Parameters:
vertex - the vertex that was added.

fireVertexRemoved

protected void fireVertexRemoved(Object vertex)
Notify listeners that the specified vertex was removed.
Parameters:
vertex - the vertex that was removed.

isReuseEvents

public boolean isReuseEvents()
Tests whether the reuseEvents flag is set. If the flag is set to true this class will reuse previously fired events and will not create a new object for each event. This option increases performance but should be used with care, especially in multithreaded environment.
Returns:
the value of the reuseEvents flag.

removeEdge

public Edge removeEdge(Object sourceVertex,
                       Object targetVertex)
Specified by:
removeEdge in interface Graph
Overrides:
removeEdge in interface GraphDelegator

removeEdge

public boolean removeEdge(Edge e)
Specified by:
removeEdge in interface Graph
Overrides:
removeEdge in interface GraphDelegator

removeGraphListener

public void removeGraphListener(GraphListener l)
Specified by:
removeGraphListener in interface ListenableGraph

removeVertex

public boolean removeVertex(Object v)
Specified by:
removeVertex in interface Graph
Overrides:
removeVertex in interface GraphDelegator

removeVertexSetListener

public void removeVertexSetListener(VertexSetListener l)
Specified by:
removeVertexSetListener in interface ListenableGraph

setReuseEvents

public void setReuseEvents(boolean reuseEvents)
If the reuseEvents flag is set to true this class will reuse previously fired events and will not create a new object for each event. This option increases performance but should be used with care, especially in multithreaded environment.
Parameters:
reuseEvents - whether to reuse previously fired event objects instead of creating a new event object for each event.