public static void addActionsTo ( SourceBuilder code , Set < MergeAction > mergeActions , boolean forBuilder ) { SetMultimap < String , String > nounsByVerb = TreeMultimap . create ( ) ; mergeActions . forEach ( mergeAction -> { if ( forBuilder || ! mergeAction . builderOnly ) { nounsByVerb . put ( mergeAction . verb , mergeAction . noun ) ; } } ) ; List < String > verbs = ImmutableList . copyOf ( nounsByVerb . keySet ( ) ) ; String lastVerb = getLast ( verbs , null ) ; for ( String verb : nounsByVerb . keySet ( ) ) { code . add ( ", %s%s" , ( verbs . size ( ) > 1 && verb . equals ( lastVerb ) ) ? "and " : "" , verb ) ; List < String > nouns = ImmutableList . copyOf ( nounsByVerb . get ( verb ) ) ; for ( int i = 0 ; i < nouns . size ( ) ; ++ i ) { String separator = ( i == 0 ) ? "" : ( i == nouns . size ( ) - 1 ) ? " and" : "," ; code . add ( "%s %s" , separator , nouns . get ( i ) ) ; } } }
Emits a sentence fragment combining all the merge actions .