Source:
<code>public String getMatchSubjects () throws LoginException, IOException { StringBuilder csvBuilder = new StringBuilder(); String header = escapeRow("subject type", "subject term", "result", "ARK", "exactMatch", "closeMatch"); csvBuilder.append(header); DAMSRepository damsRepository = DAMSRepository.getRepository(); for (File rdfFile : rdfFiles) { SAXReader saxReader = new SAXReader(); try { boolean result = false; Document srcDoc = saxReader.read(rdfFile); Node labelNode = srcDoc.selectSingleNode(" String subjectTerm = labelNode.getText(); String modelName= getSubjectTypeLabel(labelNode.getParent().getName()); for (String model : models) { List<String> matchedSubjects = damsRepository.findAuthority(model, subjectTerm); <START> if (matchedSubjects != null) { <END> if(matchedSubjects.size() > 0) result = true; for (String subject : matchedSubjects) { String ark = subject; Document doc = damsClient.getRecord(ark); modelName = getSubjectTypeLabel(doc.selectSingleNode("/rdf:RDF mads:hasExactExternalAuthority/@rdf:resource")); String closeMatch = concatValues(doc.selectNodes("/rdf:RDF/*/mads:hasCloseExternalAuthority/@rdf:resource")); String row = escapeRow(modelName, subjectTerm, "match", ark, exactMatch, closeMatch); csvBuilder.append(row); } } } if (!result) { csvBuilder.append(escapeRow(modelName, subjectTerm, result?"match":"no match", "", "", "")); } } catch(Exception ex) { ex.printStackTrace(); log.error(ex.getMessage()); String row = escapeRow(rdfFile.getName(), "", "Error: " + ex.getMessage(), "", "", ""); csvBuilder.append(row); } } return csvBuilder.toString(); }</code><technical_language>flatten conditional check a guard clause? like: if (matchedSubjects == null) { continue; } ..</technical_language>

Target:
public String getMatchSubjects () throws LoginException, IOException { StringBuilder csvBuilder = new StringBuilder(); String header = escapeRow("subject type", "subject term", "result", "ARK", "exactMatch", "closeMatch"); csvBuilder.append(header); DAMSRepository damsRepository = DAMSRepository.getRepository(); for (File rdfFile : rdfFiles) { SAXReader saxReader = new SAXReader(); try { boolean result = false; Document srcDoc = saxReader.read(rdfFile); Node labelNode = srcDoc.selectSingleNode(" String subjectTerm = labelNode.getText(); String modelName= getSubjectTypeLabel(labelNode.getParent().getName()); for (String model : models) { List<String> matchedSubjects = damsRepository.findAuthority(model, subjectTerm); if (matchedSubjects == null || matchedSubjects.size() == 0) continue; result = true; for (String subject : matchedSubjects) { String ark = subject; Document doc = damsClient.getRecord(ark); modelName = getSubjectTypeLabel(doc.selectSingleNode("/rdf:RDF mads:hasExactExternalAuthority/@rdf:resource")); String closeMatch = concatValues(doc.selectNodes("/rdf:RDF/*/mads:hasCloseExternalAuthority/@rdf:resource")); String row = escapeRow(modelName, subjectTerm, "match", ark, exactMatch, closeMatch); csvBuilder.append(row); } } if (!result) { csvBuilder.append(escapeRow(modelName, subjectTerm, result?"match":"no match", "", "", "")); } } catch(Exception ex) { ex.printStackTrace(); log.error(ex.getMessage()); String row = escapeRow(rdfFile.getName(), "", "Error: " + ex.getMessage(), "", "", ""); csvBuilder.append(row); } } return csvBuilder.toString(); }