Package org.jgrapht.traverse
Class AbstractGraphIterator<V,E>
- java.lang.Object
-
- org.jgrapht.traverse.AbstractGraphIterator<V,E>
-
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
java.util.Iterator<V>,GraphIterator<V,E>
- Direct Known Subclasses:
CrossComponentIterator,RandomWalkIterator
public abstract class AbstractGraphIterator<V,E> extends java.lang.Object implements GraphIterator<V,E>
An empty implementation of a graph iterator to minimize the effort required to implement graph iterators.- Since:
- Jul 19, 2003
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAbstractGraphIterator.DirectedSpecifics<VV,EE>An implementation ofAbstractGraphIterator.Specificsfor a directed graph.(package private) static classAbstractGraphIterator.FlyweightEdgeEvent<VV,localE>A reusable edge event.(package private) static classAbstractGraphIterator.FlyweightVertexEvent<VV>A reusable vertex event.(package private) static classAbstractGraphIterator.Specifics<VV,EE>Provides unified interface for operations that are different in directed graphs and in undirected graphs.(package private) static classAbstractGraphIterator.UndirectedSpecifics<VV,EE>An implementation ofAbstractGraphIterator.Specificsin which edge direction (if any) is ignored.
-
Field Summary
Fields Modifier and Type Field Description private booleancrossComponentTraversalprotected intnListenersprotected AbstractGraphIterator.FlyweightEdgeEvent<V,E>reusableEdgeEventprotected AbstractGraphIterator.FlyweightVertexEvent<V>reusableVertexEventprivate booleanreuseEventsprotected AbstractGraphIterator.Specifics<V,E>specificsprivate java.util.List<TraversalListener<V,E>>traversalListeners
-
Constructor Summary
Constructors Constructor Description AbstractGraphIterator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTraversalListener(TraversalListener<V,E> l)Adds the specified traversal listener to this iterator.(package private) static <V,E>
AbstractGraphIterator.Specifics<V,E>createGraphSpecifics(Graph<V,E> g)Creates directed/undirected graph specifics according to the provided graph - directed/undirected, respectively.protected voidfireConnectedComponentFinished(ConnectedComponentTraversalEvent e)Informs all listeners that the traversal of the current connected component finished.protected voidfireConnectedComponentStarted(ConnectedComponentTraversalEvent e)Informs all listeners that a traversal of a new connected component has started.protected voidfireEdgeTraversed(EdgeTraversalEvent<E> e)Informs all listeners that a the specified edge was visited.protected voidfireVertexFinished(VertexTraversalEvent<V> e)Informs all listeners that a the specified vertex was finished.protected voidfireVertexTraversed(VertexTraversalEvent<V> e)Informs all listeners that a the specified vertex was visited.booleanisCrossComponentTraversal()Test whether this iterator is set to traverse the graph across connected components.booleanisReuseEvents()Tests whether thereuseEventsflag is set.voidremove()Unsupported.voidremoveTraversalListener(TraversalListener<V,E> l)Removes the specified traversal listener from this iterator.voidsetCrossComponentTraversal(boolean crossComponentTraversal)Sets the cross component traversal flag - indicates whether to traverse the graph across connected components.voidsetReuseEvents(boolean reuseEvents)Sets a value thereuseEventsflag.
-
-
-
Field Detail
-
traversalListeners
private java.util.List<TraversalListener<V,E>> traversalListeners
-
crossComponentTraversal
private boolean crossComponentTraversal
-
reuseEvents
private boolean reuseEvents
-
nListeners
protected int nListeners
-
reusableEdgeEvent
protected AbstractGraphIterator.FlyweightEdgeEvent<V,E> reusableEdgeEvent
-
reusableVertexEvent
protected AbstractGraphIterator.FlyweightVertexEvent<V> reusableVertexEvent
-
specifics
protected AbstractGraphIterator.Specifics<V,E> specifics
-
-
Method Detail
-
setCrossComponentTraversal
public void setCrossComponentTraversal(boolean crossComponentTraversal)
Sets the cross component traversal flag - indicates whether to traverse the graph across connected components.- Parameters:
crossComponentTraversal- iftruetraverses across connected components.
-
isCrossComponentTraversal
public boolean isCrossComponentTraversal()
Test whether this iterator is set to traverse the graph across connected components.- Specified by:
isCrossComponentTraversalin interfaceGraphIterator<V,E>- Returns:
trueif traverses across connected components, otherwisefalse.
-
setReuseEvents
public void setReuseEvents(boolean reuseEvents)
Description copied from interface:GraphIteratorSets a value thereuseEventsflag. If thereuseEventsflag is set totruethis 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.- Specified by:
setReuseEventsin interfaceGraphIterator<V,E>- Parameters:
reuseEvents- whether to reuse previously fired event objects instead of creating a new event object for each event.- See Also:
GraphIterator.setReuseEvents(boolean)
-
isReuseEvents
public boolean isReuseEvents()
Description copied from interface:GraphIteratorTests whether thereuseEventsflag is set. If the flag is set totruethis 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.- Specified by:
isReuseEventsin interfaceGraphIterator<V,E>- Returns:
- the value of the
reuseEventsflag. - See Also:
GraphIterator.isReuseEvents()
-
addTraversalListener
public void addTraversalListener(TraversalListener<V,E> l)
Adds the specified traversal listener to this iterator.- Specified by:
addTraversalListenerin interfaceGraphIterator<V,E>- Parameters:
l- the traversal listener to be added.
-
remove
public void remove()
Unsupported.- Specified by:
removein interfaceGraphIterator<V,E>- Specified by:
removein interfacejava.util.Iterator<V>
-
removeTraversalListener
public void removeTraversalListener(TraversalListener<V,E> l)
Removes the specified traversal listener from this iterator.- Specified by:
removeTraversalListenerin interfaceGraphIterator<V,E>- Parameters:
l- the traversal listener to be removed.
-
fireConnectedComponentFinished
protected void fireConnectedComponentFinished(ConnectedComponentTraversalEvent e)
Informs all listeners that the traversal of the current connected component finished.- Parameters:
e- the connected component finished event.
-
fireConnectedComponentStarted
protected void fireConnectedComponentStarted(ConnectedComponentTraversalEvent e)
Informs all listeners that a traversal of a new connected component has started.- Parameters:
e- the connected component started event.
-
fireEdgeTraversed
protected void fireEdgeTraversed(EdgeTraversalEvent<E> e)
Informs all listeners that a the specified edge was visited.- Parameters:
e- the edge traversal event.
-
fireVertexTraversed
protected void fireVertexTraversed(VertexTraversalEvent<V> e)
Informs all listeners that a the specified vertex was visited.- Parameters:
e- the vertex traversal event.
-
fireVertexFinished
protected void fireVertexFinished(VertexTraversalEvent<V> e)
Informs all listeners that a the specified vertex was finished.- Parameters:
e- the vertex traversal event.
-
createGraphSpecifics
static <V,E> AbstractGraphIterator.Specifics<V,E> createGraphSpecifics(Graph<V,E> g)
Creates directed/undirected graph specifics according to the provided graph - directed/undirected, respectively.- Parameters:
g- the graph to create specifics for- Returns:
- the created specifics
-
-