class HostParser {

  public Optional<NtHostInfo> parse(String rawHost) {
    try {
      // Make sure the URI starts with http:// or https// so the URI constructor can parse it
      String str = rawHost.startsWith("http://") || rawHost.startsWith("https://") ? rawHost : "http://" + rawHost;

      URI uri = new URI(str);
      String host = uri.getHost();

      if (host == null) {
        log.warning("No host or invalid host specified: '" + rawHost + "'");
        return Optional.empty();
      }

      int port = uri.getPort();

      if (port == -1) {
        return Optional.of(NtHostInfo.onDefaultPort(host));
      } else {
        return Optional.of(new NtHostInfo(host, port));
      }
    } catch (URISyntaxException e) {
      log.log(Level.WARNING, "Invalid NetworkTables host: " + rawHost, e);
      return Optional.empty();
    }
  }

}