public Graph < T > transpose ( ) { Builder < T > builder = new Builder <> ( ) ; builder . addNodes ( nodes ) ; // reverse edges edges . keySet ( ) . forEach ( u -> { edges . get ( u ) . stream ( ) . forEach ( v -> builder . addEdge ( v , u ) ) ; } ) ; return builder . build ( ) ; }
Returns a transposed graph from this graph