Source:
<code>private AnalyzeSentimentResult convertToAnalyzeSentimentResult(DocumentSentiment documentSentiment) { final TextSentiment documentSentimentLabel = TextSentiment.fromString( documentSentiment.getSentiment().toString()); if (documentSentimentLabel == null) { logger.logExceptionAsWarning( new RuntimeException(String.format(Locale.ROOT, "'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getConfidenceScores(); final List<SentenceSentiment> sentenceSentiments = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { final TextSentiment sentenceSentimentLabel = TextSentiment.fromString( sentenceSentiment.getSentiment().toString()); if (sentenceSentimentLabel == null) { logger.logExceptionAsWarning( new RuntimeException(String.format(Locale.ROOT, "'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getConfidenceScores(); return new SentenceSentiment(sentenceSentiment.getText(), sentenceSentimentLabel, new SentimentConfidenceScores(confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive())); }).collect(Collectors.toList()); final List<TextAnalyticsWarning> warnings = documentSentiment.getWarnings().stream().map( warning -> new TextAnalyticsWarning(WarningCode.fromString(warning.getCode().toString()), warning.getMessage())).collect(Collectors.toList()); return new AnalyzeSentimentResult( documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : toTextDocumentStatistics(documentSentiment.getStatistics()), null, new com.azure.ai.textanalytics.models.DocumentSentiment( documentSentimentLabel, new SentimentConfidenceScores( confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive()), <START> new IterableStream<>(sentenceSentiments), <END> new IterableStream<>(warnings)), new IterableStream<>(documentSentiment.getWarnings().stream().map(warning -> new TextAnalyticsWarning(WarningCode.fromString(warning.getCode().toString()), warning.getMessage())) .collect(Collectors.toList())) ); }</code><technical_language>a mapping helper method continues grow. top API impl simple possible</technical_language>

Target:
private AnalyzeSentimentResult convertToAnalyzeSentimentResult(DocumentSentiment documentSentiment) { final TextSentiment documentSentimentLabel = TextSentiment.fromString( documentSentiment.getSentiment().toString()); if (documentSentimentLabel == null) { logger.logExceptionAsWarning( new RuntimeException(String.format(Locale.ROOT, "'%s' is not valid text sentiment.", documentSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerLabel = documentSentiment.getConfidenceScores(); final List<SentenceSentiment> sentenceSentiments = documentSentiment.getSentences().stream() .map(sentenceSentiment -> { final TextSentiment sentenceSentimentLabel = TextSentiment.fromString( sentenceSentiment.getSentiment().toString()); if (sentenceSentimentLabel == null) { logger.logExceptionAsWarning( new RuntimeException(String.format(Locale.ROOT, "'%s' is not valid text sentiment.", sentenceSentiment.getSentiment()))); } final SentimentConfidenceScorePerLabel confidenceScorePerSentence = sentenceSentiment.getConfidenceScores(); return new SentenceSentiment(sentenceSentiment.getText(), sentenceSentimentLabel, new SentimentConfidenceScores(confidenceScorePerSentence.getNegative(), confidenceScorePerSentence.getNeutral(), confidenceScorePerSentence.getPositive())); }).collect(Collectors.toList()); final List<TextAnalyticsWarning> warnings = documentSentiment.getWarnings().stream().map( warning -> new TextAnalyticsWarning(WarningCode.fromString(warning.getCode().toString()), warning.getMessage())).collect(Collectors.toList()); return new AnalyzeSentimentResult( documentSentiment.getId(), documentSentiment.getStatistics() == null ? null : toTextDocumentStatistics(documentSentiment.getStatistics()), null, new com.azure.ai.textanalytics.models.DocumentSentiment( documentSentimentLabel, new SentimentConfidenceScores( confidenceScorePerLabel.getNegative(), confidenceScorePerLabel.getNeutral(), confidenceScorePerLabel.getPositive()), new IterableStream<>(sentenceSentiments), new IterableStream<>(warnings))); }