question: public Object [ ] findTreeRoots ( Object parent , boolean isolate , boolean invert ) { List < Object > roots = new ArrayList < Object > ( ) ; if ( parent != null ) { int childCount = model . getChildCount ( parent ) ; Object best = null ; int maxDiff = 0 ; for ( int i = 0 ; i < childCount ; i ++ ) { Object cell = model . getChildAt ( parent , i ) ; if ( model . isVertex ( cell ) && isCellVisible ( cell ) ) { Object [ ] conns = getConnections ( cell , ( isolate ) ? parent : null ) ; int fanOut = 0 ; int fanIn = 0 ; for ( int j = 0 ; j < conns . length ; j ++ ) { Object src = view . getVisibleTerminal ( conns [ j ] , true ) ; if ( src == cell ) { fanOut ++ ; } else { fanIn ++ ; } } if ( ( invert && fanOut == 0 ) || ( ! invert && fanIn == 0 ) ) { roots . add ( cell ) ; } int diff = ( invert ) ? fanIn - fanOut : fanOut - fanIn ; if ( diff > maxDiff ) { maxDiff = diff ; best = cell ; } } } if ( roots . isEmpty ( ) && best != null ) { roots . add ( best ) ; } } return roots . toArray ( ) ; }
target:  Returns all visible children in the given parent which do not have incoming edges. If the result is empty then the children with the maximum difference between incoming and outgoing edges are returned. This takes into account edges that are being promoted to the given root due to invisible children or collapsed cells.