Source:
<code>private Response<RecognizePiiEntitiesResultCollection> toRecognizePiiEntitiesResultCollectionResponse( final Response<EntitiesResult> response) { final EntitiesResult entitiesResult = response.getValue(); final List<RecognizePiiEntitiesResult> recognizeEntitiesResults = new ArrayList<>(); entitiesResult.getDocuments().forEach(documentEntities -> recognizeEntitiesResults.add(new RecognizePiiEntitiesResult( documentEntities.getId(), documentEntities.getStatistics() == null ? null : toTextDocumentStatistics(documentEntities.getStatistics()), null, new PiiEntityCollection( new IterableStream<>(documentEntities.getEntities().stream().map(entity -> new PiiEntity(entity.getText(), EntityCategory.fromString(entity.getCategory()), entity.getSubcategory(), entity.getOffset(), entity.getLength(), entity.getConfidenceScore())) .collect(Collectors.toList())), <START> new IterableStream<>(documentEntities.getWarnings().stream() <END> .map(warning -> { final WarningCodeValue warningCodeValue = warning.getCode(); return new TextAnalyticsWarning( WarningCode.fromString(warningCodeValue == null ? null : warningCodeValue.toString()), warning.getMessage()); }).collect(Collectors.toList()))) ))); entitiesResult.getErrors().forEach(documentError -> { if (documentError.getId().isEmpty()) { throw logger.logExceptionAsError( new HttpResponseException(documentError.getError().getInnererror().getMessage(), getEmptyErrorIdHttpResponse(new SimpleResponse<>(response, response.getValue())), documentError.getError().getInnererror().getCode())); } recognizeEntitiesResults.add( new RecognizePiiEntitiesResult(documentError.getId(), null, toTextAnalyticsError(documentError.getError()), null)); }); return new SimpleResponse<>(response, new RecognizePiiEntitiesResultCollection(recognizeEntitiesResults, entitiesResult.getModelVersion(), entitiesResult.getStatistics() == null ? null : toBatchStatistics(entitiesResult.getStatistics()))); }</code><technical_language>nit: this code is get warnings, code getStatistics earlier on, good move a separate util function? i this is slightly scope of this PR, wondering if this is clean flow</technical_language>

Target:
private Response<RecognizePiiEntitiesResultCollection> toRecognizePiiEntitiesResultCollectionResponse( final Response<EntitiesResult> response) { final EntitiesResult entitiesResult = response.getValue(); final List<RecognizePiiEntitiesResult> recognizeEntitiesResults = new ArrayList<>(); entitiesResult.getDocuments().forEach(documentEntities -> { final List<PiiEntity> piiEntities = documentEntities.getEntities().stream().map(entity -> new PiiEntity(entity.getText(), EntityCategory.fromString(entity.getCategory()), entity.getSubcategory(), entity.getConfidenceScore(), entity.getOffset(), entity.getLength())) .collect(Collectors.toList()); final List<TextAnalyticsWarning> warnings = documentEntities.getWarnings().stream() .map(warning -> { final WarningCodeValue warningCodeValue = warning.getCode(); return new TextAnalyticsWarning( WarningCode.fromString(warningCodeValue == null ? null : warningCodeValue.toString()), warning.getMessage()); }).collect(Collectors.toList()); recognizeEntitiesResults.add(new RecognizePiiEntitiesResult( documentEntities.getId(), documentEntities.getStatistics() == null ? null : toTextDocumentStatistics(documentEntities.getStatistics()), null, new PiiEntityCollection(new IterableStream<>(piiEntities), new IterableStream<>(warnings)) )); }); entitiesResult.getErrors().forEach(documentError -> { recognizeEntitiesResults.add( new RecognizePiiEntitiesResult(documentError.getId(), null, toTextAnalyticsError(documentError.getError()), null)); }); return new SimpleResponse<>(response, new RecognizePiiEntitiesResultCollection(recognizeEntitiesResults, entitiesResult.getModelVersion(), entitiesResult.getStatistics() == null ? null : toBatchStatistics(entitiesResult.getStatistics()))); }