Source:
<code>static List<RecognizedForm> toRecognizedForm(AnalyzeResult analyzeResult, boolean includeTextDetails) { List<ReadResult> readResults = analyzeResult.getReadResults(); List<DocumentResult> documentResults = analyzeResult.getDocumentResults(); List<PageResult> pageResults = analyzeResult.getPageResults(); List<RecognizedForm> extractedFormList = new ArrayList<>(); Map<String, FormField<?>> extractedFieldMap; <START> AtomicReference<PageRange> pageRange = new AtomicReference<>(); AtomicReference<String> formType = new AtomicReference<>("form-"); <END> List<FormPage> formPages = toRecognizedLayout(analyzeResult, includeTextDetails); if (!CoreUtils.isNullOrEmpty(documentResults)) { for (DocumentResult documentResultItem : documentResults) { List<Integer> documentPageRange = documentResultItem.getPageRange(); if (documentPageRange.size() == 2) { pageRange.set(new PageRange(documentPageRange.get(0), documentPageRange.get(1))); } else { pageRange.set(new PageRange(1, 1)); } formType.set(documentResultItem.getDocType()); extractedFieldMap = getUnlabeledFieldMap(documentResultItem, readResults, includeTextDetails); extractedFormList.add(new RecognizedForm( extractedFieldMap, formType.get(), pageRange.get(), new IterableStream<>(formPages.subList(pageRange.get().getStartPageNumber() - 1, pageRange.get().getEndPageNumber())))); } } if (!CoreUtils.isNullOrEmpty(pageResults)) { for (PageResult pageResultItem : pageResults) { int pageNumber = pageResultItem.getPage(); if (CoreUtils.isNullOrEmpty(documentResults)) { Integer clusterId = pageResultItem.getClusterId(); if (clusterId != null) { formType.set(formType.get() + clusterId); } extractedFieldMap = getLabeledFieldMap(includeTextDetails, readResults, pageResultItem, pageNumber); extractedFormList.add(new RecognizedForm( extractedFieldMap, formType.get(), new PageRange(pageNumber, pageNumber), new IterableStream<>(Collections.singletonList(formPages.get(pageNumber - 1))))); } } } return extractedFormList; }</code><technical_language>Do need atomic references</technical_language>

Target:
static List<RecognizedForm> toRecognizedForm(AnalyzeResult analyzeResult, boolean includeTextDetails) { List<ReadResult> readResults = analyzeResult.getReadResults(); List<DocumentResult> documentResults = analyzeResult.getDocumentResults(); List<PageResult> pageResults = analyzeResult.getPageResults(); List<RecognizedForm> extractedFormList = null; List<FormPage> formPages = toRecognizedLayout(analyzeResult, includeTextDetails); if (!CoreUtils.isNullOrEmpty(documentResults)) { extractedFormList = new ArrayList<>(); for (DocumentResult documentResultItem : documentResults) { PageRange pageRange; List<Integer> documentPageRange = documentResultItem.getPageRange(); if (documentPageRange.size() == 2) { pageRange = new PageRange(documentPageRange.get(0), documentPageRange.get(1)); } else { pageRange = new PageRange(1, 1); } Map<String, FormField<?>> extractedFieldMap = getUnlabeledFieldMap(documentResultItem, readResults, includeTextDetails); extractedFormList.add(new RecognizedForm( extractedFieldMap, documentResultItem.getDocType(), pageRange, new IterableStream<>(formPages.subList(pageRange.getStartPageNumber() - 1, pageRange.getEndPageNumber())))); } } else if (!CoreUtils.isNullOrEmpty(pageResults)) { extractedFormList = new ArrayList<>(); for (PageResult pageResultItem : pageResults) { StringBuffer formType = new StringBuffer("form-"); int pageNumber = pageResultItem.getPage(); Integer clusterId = pageResultItem.getClusterId(); if (clusterId != null) { formType.append(clusterId); } Map<String, FormField<?>> extractedFieldMap = getLabeledFieldMap(includeTextDetails, readResults, pageResultItem, pageNumber); extractedFormList.add(new RecognizedForm( extractedFieldMap, formType.toString(), new PageRange(pageNumber, pageNumber), new IterableStream<>(Collections.singletonList(formPages.get(pageNumber - 1))))); } } return extractedFormList; }