question: private static List < Comment > orderComments ( List < Comment > comments ) { Map < String , List < Comment > > parentMap = new HashMap < > ( ) ; List < Comment > rootComments = new ArrayList < > ( ) ; for ( Comment c : comments ) { String parentUuid = c . parentUuid ; List < Comment > l = parentMap . get ( parentUuid ) ; if ( l == null ) { l = new ArrayList < > ( ) ; parentMap . put ( parentUuid , l ) ; } l . add ( c ) ; if ( parentUuid == null ) { rootComments . add ( c ) ; } } List < Comment > result = new ArrayList < > ( ) ; addChildren ( parentMap , rootComments , result ) ; return result ; }
target:  Order the comments based on their parent_uuid parent.  It is possible to do this by iterating over the list only once but it's probably overkill since the number of comments on a given line will be small most of the time.