class MongoUtil {

    protected static List<ServerAddress> parseAddresses(String addressStr) {
        List<ServerAddress> addresses = new ArrayList<>();
        if (addressStr != null) {
            addressStr = addressStr.trim();
            for (String address : ADDRESS_DELIMITER_PATTERN.split(addressStr)) {
                String hostAndPort = null;
                if (address.startsWith("[")) {
                    // Definitely an IPv6 address without a replica set name ...
                    hostAndPort = address;
                }
                else {
                    // May start with replica set name ...
                    int index = address.indexOf("/[");
                    if (index >= 0) {
                        if ((index + 2) < address.length()) {
                            // replica set name with IPv6, so use just the IPv6 address ...
                            hostAndPort = address.substring(index + 1);
                        }
                        else {
                            // replica set name with just opening bracket; this is invalid, so we'll ignore ...
                            continue;
                        }
                    }
                    else {
                        // possible replica set name with IPv4 only
                        index = address.indexOf("/");
                        if (index >= 0) {
                            if ((index + 1) < address.length()) {
                                // replica set name with IPv4, so use just the IPv4 address ...
                                hostAndPort = address.substring(index + 1);
                            }
                            else {
                                // replica set name with no address ...
                                hostAndPort = ServerAddress.defaultHost();
                            }
                        }
                        else {
                            // No replica set name with IPv4, so use the whole address ...
                            hostAndPort = address;
                        }
                    }
                }
                ServerAddress newAddress = parseAddress(hostAndPort);
                if (newAddress != null) {
                    addresses.add(newAddress);
                }
            }
        }
        return addresses;
    }

    private  MongoUtil();

}