Endpoint implements Comparable<Endpoint>, EndpointGroup { public URI toUri(String scheme) { requireNonNull(scheme, "scheme"); return toUri(scheme, null); } 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 toUri() { final Endpoint router = Endpoint.of("192.168.0.1"); assertThat(router.toUri("none+h1").toString()) .isEqualTo("none+h1: assertThat(router.withDefaultPort(80).toUri("none+h1").toString()) .isEqualTo("none+h1: final Endpoint google = Endpoint.of("google.com"); assertThat(google.toUri("none+https").toString()) .isEqualTo("none+https: assertThat(google.toUri(SessionProtocol.HTTPS).toString()) .isEqualTo("none+https: assertThat(google.withDefaultPort(80).toUri("none+https").toString()) .isEqualTo("none+https: final Endpoint ipv6WithHostName = Endpoint.of("google.com").withIpAddr("[::1]"); assertThat(ipv6WithHostName.toUri("none+h2").toString()) .isEqualTo("none+h2: assertThat(ipv6WithHostName.toUri(SessionProtocol.H2).toString()) .isEqualTo("none+h2: assertThat(ipv6WithHostName.withDefaultPort(80).toUri("none+h2").toString()) .isEqualTo("none+h2: final Endpoint naver = Endpoint.of("naver.com"); assertThat(naver.toUri("none+https", "/hello").toString()) .isEqualTo("none+https: assertThat(naver.toUri(SessionProtocol.HTTPS, "/hello").toString()) .isEqualTo("none+https: assertThat(naver.toUri("https", "")) .isEqualTo(naver.toUri("https", null)); }