Class BreadthFirstIteratorWithLevel<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type
    All Implemented Interfaces:
    java.util.Iterator<V>, org.jgrapht.traverse.GraphIterator<V,​E>

    public class BreadthFirstIteratorWithLevel<V,​E>
    extends org.jgrapht.traverse.CrossComponentIterator<V,​E,​java.lang.Integer>
    A breadth-first iterator for a directed or undirected graph which supports querying the depth of a vertex in the search tree.

    For this iterator to work correctly the graph must not be modified during iteration. Currently there are no means to ensure that, nor to fail-fast. The results of such modifications are undefined.

    Since:
    April 21, 2018
    Author:
    Joris Kinable
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.jgrapht.traverse.CrossComponentIterator

        org.jgrapht.traverse.CrossComponentIterator.VisitColor
    • Field Summary

      • Fields inherited from class org.jgrapht.traverse.AbstractGraphIterator

        nListeners
    • Constructor Summary

      Constructors 
      Constructor Description
      BreadthFirstIteratorWithLevel​(org.jgrapht.Graph<V,​E> g)
      Creates a new breadth-first iterator for the specified graph.
      BreadthFirstIteratorWithLevel​(org.jgrapht.Graph<V,​E> g, V startVertex)
      Creates a new breadth-first iterator for the specified graph.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void encounterVertex​(V vertex, E edge)  
      protected void encounterVertexAgain​(V vertex, E edge)  
      int getDepth​(V v)  
      protected boolean isConnectedComponentExhausted()  
      protected V provideNextVertex()  
      • Methods inherited from class org.jgrapht.traverse.CrossComponentIterator

        finishVertex, getGraph, getSeenData, hasNext, isSeenVertex, next, putSeenData
      • Methods inherited from class org.jgrapht.traverse.AbstractGraphIterator

        addTraversalListener, fireConnectedComponentFinished, fireConnectedComponentStarted, fireEdgeTraversed, fireVertexFinished, fireVertexTraversed, isCrossComponentTraversal, isReuseEvents, remove, removeTraversalListener, setCrossComponentTraversal, setReuseEvents
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • BreadthFirstIteratorWithLevel

        public BreadthFirstIteratorWithLevel​(org.jgrapht.Graph<V,​E> g)
        Creates a new breadth-first iterator for the specified graph.
        Parameters:
        g - the graph to be iterated.
      • BreadthFirstIteratorWithLevel

        public BreadthFirstIteratorWithLevel​(org.jgrapht.Graph<V,​E> g,
                                             V startVertex)
        Creates a new breadth-first iterator for the specified graph. Iteration will start at the specified start vertex and will be limited to the connected component that includes that vertex. If the specified start vertex is null, iteration will start at an arbitrary vertex and will not be limited, that is, will be able to traverse all the graph.
        Parameters:
        g - the graph to be iterated.
        startVertex - the vertex iteration to be started.
    • Method Detail

      • isConnectedComponentExhausted

        protected boolean isConnectedComponentExhausted()
        Specified by:
        isConnectedComponentExhausted in class org.jgrapht.traverse.CrossComponentIterator<V,​E,​java.lang.Integer>
        See Also:
        CrossComponentIterator.isConnectedComponentExhausted()
      • encounterVertex

        protected void encounterVertex​(V vertex,
                                       E edge)
        Specified by:
        encounterVertex in class org.jgrapht.traverse.CrossComponentIterator<V,​E,​java.lang.Integer>
        See Also:
        CrossComponentIterator.encounterVertex(Object, Object)
      • encounterVertexAgain

        protected void encounterVertexAgain​(V vertex,
                                            E edge)
        Specified by:
        encounterVertexAgain in class org.jgrapht.traverse.CrossComponentIterator<V,​E,​java.lang.Integer>
        See Also:
        CrossComponentIterator.encounterVertexAgain(Object, Object)
      • provideNextVertex

        protected V provideNextVertex()
        Specified by:
        provideNextVertex in class org.jgrapht.traverse.CrossComponentIterator<V,​E,​java.lang.Integer>
        See Also:
        CrossComponentIterator.provideNextVertex()
      • getDepth

        public int getDepth​(V v)