@@ -571,20 +571,22 @@ public E next() {
571571 }
572572
573573 private void primeIterator () {
574- if (edgeIterator != null && edgeIterator .hasNext ()) {
575- hasNext = true ; // technically, we shouldn't need to put this here, but let's be safe
576- } else if (connectionIterator != null && connectionIterator .hasNext ()) {
577- Map .Entry <V , List <E >> nextConnection = connectionIterator .next ();
578- edgeIterator = nextConnection .getValue ().iterator ();
579- currentTarget = nextConnection .getKey ();
580- primeIterator ();
581- } else if (vertexIterator != null && vertexIterator .hasNext ()) {
582- Map .Entry <V , Map <V , List <E >>> nextVertex = vertexIterator .next ();
583- connectionIterator = nextVertex .getValue ().entrySet ().iterator ();
584- currentSource = nextVertex .getKey ();
585- primeIterator ();
586- } else {
587- hasNext = false ;
574+ while (true ) {
575+ if (edgeIterator != null && edgeIterator .hasNext ()) {
576+ hasNext = true ; // technically, we shouldn't need to put this here, but let's be safe
577+ return ;
578+ } else if (connectionIterator != null && connectionIterator .hasNext ()) {
579+ Map .Entry <V , List <E >> nextConnection = connectionIterator .next ();
580+ edgeIterator = nextConnection .getValue ().iterator ();
581+ currentTarget = nextConnection .getKey ();
582+ } else if (vertexIterator != null && vertexIterator .hasNext ()) {
583+ Map .Entry <V , Map <V , List <E >>> nextVertex = vertexIterator .next ();
584+ connectionIterator = nextVertex .getValue ().entrySet ().iterator ();
585+ currentSource = nextVertex .getKey ();
586+ } else {
587+ hasNext = false ;
588+ return ;
589+ }
588590 }
589591 }
590592
0 commit comments