Endpoint implements Comparable<Endpoint>, EndpointGroup { public Endpoint withPort(int port) { validatePort("port", port); if (this.port == port) { return this; } return new Endpoint(host, ipAddr, port, weight, hostType); } private  Endpoint(String host, @Nullable String ipAddr, int port, int weight, HostType hostType); static Endpoint parse(String authority); static Endpoint of(String host, int port); static Endpoint of(String host); @Override List<Endpoint> endpoints(); @Override EndpointSelectionStrategy selectionStrategy(); @Override Endpoint selectNow(ClientRequestContext ctx); @Override CompletableFuture<Endpoint> select(ClientRequestContext ctx,
                                              ScheduledExecutorService executor,
                                              long timeoutMillis); @Override CompletableFuture<List<Endpoint>> whenReady(); String host(); @Nullable String ipAddr(); boolean hasIpAddr(); boolean isIpAddrOnly(); @Nullable StandardProtocolFamily ipFamily(); int port(); int port(int defaultValue); boolean hasPort(); Endpoint withPort(int port); Endpoint withoutPort(); Endpoint withDefaultPort(int defaultPort); Endpoint withoutDefaultPort(int defaultPort); Endpoint withIpAddr(@Nullable String ipAddr); Endpoint withWeight(int weight); int weight(); String authority(); URI toUri(String scheme); URI toUri(String scheme, @Nullable String path); URI toUri(SessionProtocol sessionProtocol); URI toUri(SessionProtocol sessionProtocol, @Nullable String path); URI toUri(Scheme scheme); URI toUri(Scheme scheme, @Nullable String path); @Override CompletableFuture<?> closeAsync(); @Override void close(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); @Override int compareTo(Endpoint that); @Override String toString();  }
@Test void withPort() { final Endpoint foo = Endpoint.of("foo"); final Endpoint foo80 = Endpoint.of("foo", 80); assertThat(foo.withPort(80)).isEqualTo(foo80); assertThat(foo80.withPort(80)).isSameAs(foo80); assertThatThrownBy(() -> foo.withPort(0)).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("port"); }