Source:
<code>public static ZookeeperConnection valueOf(final String connStr) { final Matcher m = ZK_CONN_PATTERN.matcher(connStr); if (!m.matches()) { throw new RuntimeException("Unsupported format of zk connection string " + connStr); } final String typeString = m.group(1); final Optional<ZookeeperConnectionType> optType = Arrays.stream(ZookeeperConnectionType.values()) .filter(v -> v.name().equalsIgnoreCase(typeString)) .findAny(); if (!optType.isPresent()) { throw new RuntimeException("Can not detect type of connection from " + typeString + " in " + connStr); <START> } <END> final ZookeeperConnectionType type = optType.get(); final String[] hostsPorts = m.group(2).split(","); final List<Integer> ports = Arrays.stream(hostsPorts) .filter(v -> v.contains(":")) .map(v -> v.substring(v.lastIndexOf(':') + 1)) .map(Integer::parseInt) .collect(Collectors.toList()); if (ports.isEmpty()) { throw new RuntimeException("Ports are not defined for hosts, no default port could be found in " + connStr); } final Integer defaultPort = ports.get(ports.size() - 1); final List<AddressPort> addresses = Arrays.stream(hostsPorts).map(hostPort -> { final int sepIndex = hostPort.lastIndexOf(':'); if (sepIndex > 0) { return new AddressPort( hostPort.substring(0, sepIndex), Integer.parseInt(hostPort.substring(sepIndex + 1))); } else { return new AddressPort(hostPort, defaultPort); } }).collect(Collectors.toList()); final String path = m.groupCount() >= 3 ? m.group(3) : null; return new ZookeeperConnection(type, addresses, path); }</code><technical_language>I easier do java try { typeString = ZookeeperConnectionType.valueOf(typeString); } catch (IllegalArgumentException e) { throw new RuntimeException("Can detect type of connection " + typeString + " in " + connStr); }</technical_language>

Target:
public static ZookeeperConnection valueOf(final String connStr) { final Matcher m = ZK_CONN_PATTERN.matcher(connStr); if (!m.matches()) { throw new RuntimeException("Unsupported format of zk connection string " + connStr); } final String typeString = m.group(1); final ZookeeperConnectionType type = Arrays.stream(ZookeeperConnectionType.values()) .filter(v -> v.name().equalsIgnoreCase(typeString)) .findAny() .orElseThrow(() -> new RuntimeException("Can not detect type of connection" + typeString + " in " + connStr)); final String[] hostsPorts = m.group(2).split(","); final List<Integer> ports = Arrays.stream(hostsPorts) .filter(v -> v.contains(":")) .map(v -> v.substring(v.lastIndexOf(':') + 1)) .map(Integer::parseInt) .collect(Collectors.toList()); if (ports.isEmpty()) { throw new RuntimeException("Ports are not defined for hosts, no default port could be found in " + connStr); } final Integer defaultPort = ports.get(ports.size() - 1); final List<AddressPort> addresses = Arrays.stream(hostsPorts).map(hostPort -> { final int sepIndex = hostPort.lastIndexOf(':'); if (sepIndex > 0) { return new AddressPort( hostPort.substring(0, sepIndex), Integer.parseInt(hostPort.substring(sepIndex + 1))); } else { return new AddressPort(hostPort, defaultPort); } }).collect(Collectors.toList()); final String path = m.groupCount() >= 3 ? m.group(3) : null; return new ZookeeperConnection(type, addresses, path); }