Source:
<code>public String getQuestionResultStatisticsCsv( List<FeedbackResponseAttributes> responses, FeedbackQuestionAttributes question, FeedbackSessionResultsBundle bundle) { if (responses.isEmpty()) { return ""; } StringBuilder fragments = new StringBuilder(); Map<String, List<Integer>> recipientRanks = generateOptionRanksMapping(responses); <START> boolean showAvgExcludingSelf = showAverageExcludingSelf(question); <END> Map<String, List<Integer>> recipientRanksExcludingSelf = null; if (showAvgExcludingSelf) { List<FeedbackResponseAttributes> responsesExcludingSelf = getResponsesExcludingSelf(responses); recipientRanksExcludingSelf = generateOptionRanksMapping(responsesExcludingSelf); } DecimalFormat df = new DecimalFormat("#.##"); for (Entry<String, List<Integer>> entry : recipientRanks.entrySet()) { String teamName = bundle.getTeamNameForEmail(entry.getKey()); String recipientName = bundle.getNameForEmail(entry.getKey()); String option = SanitizationHelper.sanitizeForCsv(teamName) + "," + SanitizationHelper.sanitizeForCsv(recipientName); Double averageExcludingSelf = null; if (showAvgExcludingSelf) { List<Integer> ranksExcludingSelf = recipientRanksExcludingSelf.get(entry.getKey()); if (ranksExcludingSelf != null) { averageExcludingSelf = computeAverage(ranksExcludingSelf); } } String userAverageExcludingSelfText = getAverageExcludingSelfText(showAvgExcludingSelf, df, averageExcludingSelf); List<Integer> ranks = entry.getValue(); double average = computeAverage(ranks); fragments.append(option).append(',').append(df.format(average)); if (showAvgExcludingSelf) { fragments.append(',').append(userAverageExcludingSelfText); } fragments.append(Const.EOL); } String rankQuestionHeaderSelf = ""; if (showAvgExcludingSelf) { rankQuestionHeaderSelf = ", Average Rank Excluding Self"; } return "Team, Recipient" + ", Average Rank" + rankQuestionHeaderSelf + Const.EOL + fragments + Const.EOL; }</code><technical_language>extract this a method? is code duplication here</technical_language>

Target:
public String getQuestionResultStatisticsCsv( List<FeedbackResponseAttributes> responses, FeedbackQuestionAttributes question, FeedbackSessionResultsBundle bundle) { if (responses.isEmpty()) { return ""; } StringBuilder fragments = new StringBuilder(); Map<String, List<Integer>> recipientRanks = generateOptionRanksMapping(responses); Map<String, List<Integer>> recipientRanksExcludingSelf = getRecipientRanksExcludingSelf(responses, question); DecimalFormat df = new DecimalFormat("#.##"); for (Entry<String, List<Integer>> entry : recipientRanks.entrySet()) { String teamName = bundle.getTeamNameForEmail(entry.getKey()); String recipientName = bundle.getNameForEmail(entry.getKey()); String option = SanitizationHelper.sanitizeForCsv(teamName) + "," + SanitizationHelper.sanitizeForCsv(recipientName); String userAverageExcludingSelfText = getAverageExcludingSelfText(df, recipientRanksExcludingSelf, entry.getKey()); List<Integer> ranks = entry.getValue(); double average = computeAverage(ranks); fragments.append(option).append(',').append(df.format(average)); if (shouldSelfBeExcludedFromRankings(question)) { fragments.append(',').append(userAverageExcludingSelfText); } fragments.append(Const.EOL); } String rankQuestionHeaderSelf = shouldSelfBeExcludedFromRankings(question) ? ", Average Rank Excluding Self" : ""; return "Team, Recipient, Average Rank" + rankQuestionHeaderSelf + Const.EOL + fragments + Const.EOL; }