private String buildMessage ( Set < String > unhandled ) { StringBuilder message = new StringBuilder ( "Non-exhaustive switch; either add a default or handle the remaining cases: " ) ; int numberToShow = unhandled . size ( ) > MAX_CASES_TO_PRINT ? 3 // if there are too many to print, only show three examples. : unhandled . size ( ) ; message . append ( unhandled . stream ( ) . limit ( numberToShow ) . collect ( Collectors . joining ( ", " ) ) ) ; if ( numberToShow < unhandled . size ( ) ) { message . append ( String . format ( ", and %d others" , unhandled . size ( ) - numberToShow ) ) ; } return message . toString ( ) ; }
Build the diagnostic message .