HttpHost implements NamedEndpoint, Serializable { public String toHostString() { if (this.port != -1) { final StringBuilder buffer = new StringBuilder(this.hostname.length() + 6); buffer.append(this.hostname); buffer.append(":"); buffer.append(Integer.toString(this.port)); return buffer.toString(); } return this.hostname; } HttpHost(final String scheme, final InetAddress address, final String hostname, final int port);  HttpHost(final String scheme, final String hostname, final int port);  HttpHost(final String hostname, final int port);  HttpHost(final String scheme, final String hostname);  HttpHost(final String hostname);  HttpHost(final String scheme, final InetAddress address, final int port);  HttpHost(final InetAddress address, final int port);  HttpHost(final InetAddress address);  HttpHost(final String scheme, final NamedEndpoint namedEndpoint);  HttpHost(final URIAuthority authority); static HttpHost create(final String s); static HttpHost create(final URI uri); @Override String getHostName(); @Override int getPort(); String getSchemeName(); InetAddress getAddress(); String toURI(); String toHostString(); @Override String toString(); @Override boolean equals(final Object obj); @Override int hashCode(); static final URIScheme DEFAULT_SCHEME; }
@Test public void testToHostString() { final HttpHost host1 = new HttpHost("somehost"); Assert.assertEquals("somehost", host1.toHostString()); final HttpHost host2 = new HttpHost("somehost"); Assert.assertEquals("somehost", host2.toHostString()); final HttpHost host3 = new HttpHost("somehost", -1); Assert.assertEquals("somehost", host3.toHostString()); final HttpHost host4 = new HttpHost("somehost", 8888); Assert.assertEquals("somehost:8888", host4.toHostString()); }