Class CrossComponentIterator<V,E,D>
java.lang.Object
org.jgrapht.traverse.AbstractGraphIterator<V,E>
org.jgrapht.traverse.CrossComponentIterator<V,E,D>
- Type Parameters:
V- vertex typeE- edge typeD- type of data associated to seen vertices
- All Implemented Interfaces:
Iterator<V>, GraphIterator<V,E>
- Direct Known Subclasses:
BreadthFirstIterator, ClosestFirstIterator, DepthFirstIterator
Provides a cross-connected-component traversal functionality for iterator subclasses.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractGraphIterator
AbstractGraphIterator.FlyweightEdgeEvent<E>, AbstractGraphIterator.FlyweightVertexEvent<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConnectedComponentTraversalEventprivate static final intprivate static final intprivate static final intprivate final ConnectedComponentTraversalEventIterator which provides start vertices for cross-component iteration.Stores the vertices that have been seen during iteration and (optionally) some additional traversal info regarding each vertex.private VThe current vertex.Iterator which provides start vertices for specified start vertices.private intThe connected component stateFields inherited from class AbstractGraphIterator
crossComponentTraversal, graph, nListeners, reusableEdgeEvent, reusableVertexEvent, reuseEvents -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new iterator for the specified graph.Creates a new iterator for the specified graph.CrossComponentIterator(Graph<V, E> g, V startVertex) Creates a new iterator for the specified graph. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddUnseenChildrenOf(V vertex) private voidprotected abstract voidencounterVertex(V vertex, E edge) Update data structures the first time we see a vertex.protected abstract voidencounterVertexAgain(V vertex, E edge) Called whenever we re-encounter a vertex.protected voidfinishVertex(V vertex) Called when a vertex has been finished (meaning is dependent on traversal represented by subclass).Lazily instantiatesentireGraphVertexIterator.protected DgetSeenData(V vertex) Access the data stored for a seen vertex.booleanhasNext()protected abstract booleanReturnstrueif there are no more uniterated vertices in the currently iterated connected component;falseotherwise.protected booleanisSeenVertex(V vertex) Determines whether a vertex has been seen yet by this traversal.next()protected abstract VReturns the vertex to be returned in the following call to the iteratornextmethod.protected DputSeenData(V vertex, D data) Stores iterator-dependent data for a vertex that has been seen.selectOutgoingEdges(V vertex) Selects the outgoing edges for a given vertex based on the source vertex and other traversal state.Methods inherited from class AbstractGraphIterator
addTraversalListener, createEdgeTraversalEvent, createVertexTraversalEvent, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, getGraph, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEventsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterator
forEachRemaining
-
Field Details
-
CCS_BEFORE_COMPONENT
private static final int CCS_BEFORE_COMPONENT- See Also:
-
CCS_WITHIN_COMPONENT
private static final int CCS_WITHIN_COMPONENT- See Also:
-
CCS_AFTER_COMPONENT
private static final int CCS_AFTER_COMPONENT- See Also:
-
ccFinishedEvent
-
ccStartedEvent
-
seen
-
entireGraphVertexIterator
-
startVertexIterator
-
startVertex
The current vertex. -
state
private int stateThe connected component state
-
-
Constructor Details
-
CrossComponentIterator
-
CrossComponentIterator
Creates a new iterator for the specified graph. Iteration will start at the specified start vertex. If the specified start vertex isnull, Iteration will start at an arbitrary graph vertex.- Parameters:
g- the graph to be iterated.startVertex- the vertex iteration to be started.- Throws:
IllegalArgumentException- ifg==nullor does not containstartVertex
-
CrossComponentIterator
Creates a new iterator for the specified graph. Iteration will start at the specified start vertices. If the specified start vertices isnull, Iteration will start at an arbitrary graph vertex.- Parameters:
g- the graph to be iterated.startVertices- the vertices iteration to be started.- Throws:
IllegalArgumentException- ifg==nullor does not containstartVertex
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
-
getEntireGraphVertexIterator
-
isConnectedComponentExhausted
protected abstract boolean isConnectedComponentExhausted()Returnstrueif there are no more uniterated vertices in the currently iterated connected component;falseotherwise.- Returns:
trueif there are no more uniterated vertices in the currently iterated connected component;falseotherwise.
-
encounterVertex
-
provideNextVertex
Returns the vertex to be returned in the following call to the iteratornextmethod.- Returns:
- the next vertex to be returned by this iterator.
-
getSeenData
Access the data stored for a seen vertex.- Parameters:
vertex- a vertex which has already been seen.- Returns:
- data associated with the seen vertex or
nullif no data was associated with the vertex. Anullreturn can also indicate that the vertex was explicitly associated withnull.
-
isSeenVertex
Determines whether a vertex has been seen yet by this traversal.- Parameters:
vertex- vertex in question- Returns:
trueif vertex has already been seen
-
encounterVertexAgain
-
putSeenData
Stores iterator-dependent data for a vertex that has been seen.- Parameters:
vertex- a vertex which has been seen.data- data to be associated with the seen vertex.- Returns:
- previous value associated with specified vertex or
nullif no data was associated with the vertex. Anullreturn can also indicate that the vertex was explicitly associated withnull.
-
finishVertex
Called when a vertex has been finished (meaning is dependent on traversal represented by subclass).- Parameters:
vertex- vertex which has been finished
-
selectOutgoingEdges
-
addUnseenChildrenOf
-
encounterStartVertex
private void encounterStartVertex()
-