private List < List < Cycle > > groupByLength ( final RelevantCycles relevant ) { LinkedList < List < Cycle >> cyclesByLength = new LinkedList < List < Cycle > > ( ) ; for ( int [ ] path : relevant . paths ( ) ) { if ( cyclesByLength . isEmpty ( ) || path . length > cyclesByLength . getLast ( ) . get ( 0 ) . path ( ) . length ) { cyclesByLength . add ( new ArrayList < Cycle > ( ) ) ; } cyclesByLength . getLast ( ) . add ( new MyCycle ( path ) ) ; } return cyclesByLength ; }
Reconstruct all relevant cycles and group then by length .