/** * Provide a default port if the parsed string contained only a host. * * <p>You can chain this after {@link #fromString(String)} to include a port in case the port was * omitted from the input string. If a port was already provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort()) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
throw new IllegalArgumentException("Unparseable port number: " + hostPortString); checkArgument(isValidPort(port), "Port number out of range: %s", hostPortString);
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. Use {@link #requireBracketsForIPv6()} to * prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, or {@code port} is out * of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * <p>You can chain this after {@link #fromString(String)} to include a port in case the port was * omitted from the input string. If a port was already provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort()) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
throw new IllegalArgumentException("Unparseable port number: " + hostPortString); checkArgument(isValidPort(port), "Port number out of range: %s", hostPortString);
/** * Provide a default port if the parsed string contained only a host. * * <p>You can chain this after {@link #fromString(String)} to include a port in case the port was * omitted from the input string. If a port was already provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort()) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. Use {@link #requireBracketsForIPv6()} to * prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, or {@code port} is out * of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
throw new IllegalArgumentException("Unparseable port number: " + hostPortString); checkArgument(isValidPort(port), "Port number out of range: %s", hostPortString);
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. Use {@link #requireBracketsForIPv6()} to * prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, or {@code port} is out * of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * You can chain this after {@link #fromString(String)} to include a port in * case the port was omitted from the input string. If a port was already * provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort() || port == defaultPort) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * You can chain this after {@link #fromString(String)} to include a port in * case the port was omitted from the input string. If a port was already * provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort() || port == defaultPort) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * <p>You can chain this after {@link #fromString(String)} to include a port in case the port was * omitted from the input string. If a port was already provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort()) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * You can chain this after {@link #fromString(String)} to include a port in * case the port was omitted from the input string. If a port was already * provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort() || port == defaultPort) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * <p>You can chain this after {@link #fromString(String)} to include a port in case the port was * omitted from the input string. If a port was already provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort()) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * You can chain this after {@link #fromString(String)} to include a port in * case the port was omitted from the input string. If a port was already * provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort() || port == defaultPort) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Provide a default port if the parsed string contained only a host. * * You can chain this after {@link #fromString(String)} to include a port in * case the port was omitted from the input string. If a port was already * provided, then this method is a no-op. * * @param defaultPort a port number, from [0..65535] * @return a HostAndPort instance, guaranteed to have a defined port. */ public HostAndPort withDefaultPort(int defaultPort) { checkArgument(isValidPort(defaultPort)); if (hasPort() || port == defaultPort) { return this; } return new HostAndPort(host, defaultPort, hasBracketlessColons); }
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. * Use {@link #requireBracketsForIPv6()} to prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, * or {@code port} is out of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. Use {@link #requireBracketsForIPv6()} to * prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, or {@code port} is out * of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. * Use {@link #requireBracketsForIPv6()} to prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, * or {@code port} is out of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port), "Port out of range: %s", port); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort(), "Host has a port: %s", host); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }
/** * Build a HostAndPort instance from separate host and port values. * * <p>Note: Non-bracketed IPv6 literals are allowed. * Use {@link #requireBracketsForIPv6()} to prohibit these. * * @param host the host string to parse. Must not contain a port number. * @param port a port number from [0..65535] * @return if parsing was successful, a populated HostAndPort object. * @throws IllegalArgumentException if {@code host} contains a port number, * or {@code port} is out of range. */ public static HostAndPort fromParts(String host, int port) { checkArgument(isValidPort(port)); HostAndPort parsedHost = fromString(host); checkArgument(!parsedHost.hasPort()); return new HostAndPort(parsedHost.host, port, parsedHost.hasBracketlessColons); }