Source:
<code>public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (shortScheme.equalsIgnoreCase("https://")) { currentPos += "https://".length(); } else if (shortScheme.equalsIgnoreCase("http://")) { currentPos += "http://".length(); } else if (longScheme.equalsIgnoreCase("rtsp://")) { currentPos += "rtsp://".length(); } else { return startPos; } currentPos = matchUserInfoIfAvailable(text, currentPos); <START> int matchedAuthorityEnd = Math.max(tryMatchDomainName(text, currentPos), <END> Math.max(tryMatchIpv4Address(text, currentPos, true), tryMatchIpv6Address(text, currentPos))); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }</code><technical_language>Math.max() business this super hard read. need attempt another match if of methods successful. I suggest extract of this a separate method check return call tryMatch*() return early if a match found</technical_language>

Target:
public int linkifyUri(String text, int startPos, StringBuffer outputBuffer) { int currentPos = startPos; String shortScheme = text.substring(currentPos, Math.min(currentPos + 7, text.length())); String longScheme = text.substring(currentPos, Math.min(currentPos + 8, text.length())); if (shortScheme.equalsIgnoreCase("https://")) { currentPos += "https://".length(); } else if (shortScheme.equalsIgnoreCase("http://")) { currentPos += "http://".length(); } else if (longScheme.equalsIgnoreCase("rtsp://")) { currentPos += "rtsp://".length(); } else { return startPos; } int matchedAuthorityEnd = tryMatchAuthority(text, currentPos); if (matchedAuthorityEnd == currentPos) { return startPos; } currentPos = matchedAuthorityEnd; if (currentPos < text.length() && text.charAt(currentPos) == '/') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, "/:@"); } if (currentPos < text.length() && text.charAt(currentPos) == '?') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } if (currentPos < text.length() && text.charAt(currentPos) == '#') { currentPos = matchUnreservedPCTEncodedSubDelimClassesGreedy(text, currentPos + 1, ":@/?"); } String httpUri = text.substring(startPos, currentPos); outputBuffer.append("<a href=\"") .append(httpUri) .append("\">") .append(httpUri) .append("</a>"); return currentPos; }