Source:
<code>private String processMessage(Matcher matcher, String message, List<Pair<Integer, Integer>> backReferences, List<Pair<Integer, Integer>> suggestions, List<Match> matches) { int closestSuggestionPosition = -1; boolean allSuggestionsPassed = true; if (!suggestions.isEmpty()) { allSuggestionsPassed = false; closestSuggestionPosition = 0; } <START> <END> boolean insideSuggestion; StringBuilder processedMessage = new StringBuilder(); int startOfProcessingPart = 0; for (int i = 0; i < backReferences.size(); i++) { Pair<Integer, Integer> reference = backReferences.get(i); while (!allSuggestionsPassed && (reference.getLeft() > suggestions.get(closestSuggestionPosition).getRight())) { closestSuggestionPosition += 1; if (closestSuggestionPosition == suggestions.size()) { allSuggestionsPassed = true; } } insideSuggestion = !allSuggestionsPassed && reference.getLeft() >= suggestions.get(closestSuggestionPosition).getLeft(); int inXMLMatchReferenceNo = Integer.parseInt(message.substring(reference.getLeft(), reference.getRight()).split("\\\\")[1]); int actualMatchReferenceNo = inXMLMatchReferenceNo - (insideSuggestion ? MATCHES_IN_SUGGESTIONS_NUMBERED_FROM : 0); String matchReferenceStringValue = matcher.group(actualMatchReferenceNo); if (matchReferenceStringValue == null){ matchReferenceStringValue = ""; } Match currentProcessingMatch = matches.get(i); String regexReplace = currentProcessingMatch.getRegexReplace(); String suggestion; if (regexReplace != null) { suggestion = currentProcessingMatch.getRegexMatch().matcher(matchReferenceStringValue).replaceFirst(regexReplace); suggestion = CaseConversionHelper.convertCase(currentProcessingMatch.getCaseConversionType(), suggestion, matchReferenceStringValue, getLanguage()); } else { suggestion = matchReferenceStringValue; } processedMessage.append(message.substring(startOfProcessingPart, reference.getLeft())).append(suggestion); startOfProcessingPart = reference.getRight(); } processedMessage.append(message.substring(startOfProcessingPart)); return processedMessage.toString(); }</code><technical_language>remark: This is a bit shorter: boolean allSuggestionsPassed = suggestions.isEmpty(); if (!suggestions.isEmpty()) { closestSuggestionPosition = 0; }</technical_language>

Target:
private String processMessage(Matcher matcher, String message, List<Pair<Integer, Integer>> backReferences, List<Pair<Integer, Integer>> suggestions, List<Match> matches) { int closestSuggestionPosition = -1; boolean allSuggestionsPassed = suggestions.isEmpty(); if (!suggestions.isEmpty()) { closestSuggestionPosition = 0; } boolean insideSuggestion; StringBuilder processedMessage = new StringBuilder(); int startOfProcessingPart = 0; for (int i = 0; i < backReferences.size(); i++) { Pair<Integer, Integer> reference = backReferences.get(i); while (!allSuggestionsPassed && (reference.getLeft() > suggestions.get(closestSuggestionPosition).getRight())) { closestSuggestionPosition += 1; if (closestSuggestionPosition == suggestions.size()) { allSuggestionsPassed = true; } } insideSuggestion = !allSuggestionsPassed && reference.getLeft() >= suggestions.get(closestSuggestionPosition).getLeft(); int inXMLMatchReferenceNo = Integer.parseInt(message.substring(reference.getLeft(), reference.getRight()).split("\\\\")[1]); int actualMatchReferenceNo = inXMLMatchReferenceNo - (insideSuggestion ? MATCHES_IN_SUGGESTIONS_NUMBERED_FROM : 0); String matchReferenceStringValue = matcher.group(actualMatchReferenceNo); if (matchReferenceStringValue == null){ matchReferenceStringValue = ""; } Match currentProcessingMatch = matches.get(i); String regexReplace = currentProcessingMatch.getRegexReplace(); String suggestion; if (regexReplace != null) { suggestion = currentProcessingMatch.getRegexMatch().matcher(matchReferenceStringValue).replaceFirst(regexReplace); suggestion = CaseConversionHelper.convertCase(currentProcessingMatch.getCaseConversionType(), suggestion, matchReferenceStringValue, getLanguage()); } else { suggestion = matchReferenceStringValue; } processedMessage.append(message.substring(startOfProcessingPart, reference.getLeft())).append(suggestion); startOfProcessingPart = reference.getRight(); } processedMessage.append(message.substring(startOfProcessingPart)); return processedMessage.toString(); }