HostAndPort implements Serializable { public int getPortOrDefault(int defaultPort) { return hasPort() ? port : defaultPort; } private  HostAndPort(String host, int port, boolean hasBracketlessColons); String getHost(); boolean hasPort(); int getPort(); int getPortOrDefault(int defaultPort); static HostAndPort fromParts(String host, int port); static HostAndPort fromHost(String host); static HostAndPort fromString(String hostPortString); HostAndPort withDefaultPort(int defaultPort); HostAndPort requireBracketsForIPv6(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString();  }
@Test public void testGetPortOrDefault() { assertEquals(80, HostAndPort.fromString("host:80").getPortOrDefault(123)); assertEquals(123, HostAndPort.fromString("host").getPortOrDefault(123)); }