Provide a default port if the parsed string contained only a host. You can chain this after #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..6553
(int defaultPort)
| 251 | * @return a HostAndPort instance, guaranteed to have a defined port. |
| 252 | */ |
| 253 | public HostAndPort withDefaultPort(int defaultPort) { |
| 254 | checkArgument(isValidPort(defaultPort)); |
| 255 | if (hasPort() || port == defaultPort) { |
| 256 | return this; |
| 257 | } |
| 258 | return new HostAndPort(host, defaultPort, hasBracketlessColons); |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Generate an error if the host might be a non-bracketed IPv6 literal. |
nothing calls this directly
no test coverage detected