Index: src/main/java/org/apache/http/HttpHost.java =================================================================== --- src/main/java/org/apache/http/HttpHost.java (revision 899420) +++ src/main/java/org/apache/http/HttpHost.java (working copy) @@ -36,8 +36,8 @@ /** * Holds all of the variables needed to describe an HTTP connection to a host. * This includes remote host name, port and scheme. - * - * + * + * * @since 4.0 */ //@Immutable @@ -47,7 +47,7 @@ /** The default scheme is "http". */ public static final String DEFAULT_SCHEME_NAME = "http"; - + /** The host to use. */ protected final String hostname; @@ -65,7 +65,7 @@ /** * Creates a new {@link HttpHost HttpHost}, specifying all values. * Constructor for HttpHost. - * + * * @param hostname the hostname (IP or DNS name) * @param port the port number. * -1 indicates the scheme default port. @@ -73,7 +73,7 @@ * null indicates the * {@link #DEFAULT_SCHEME_NAME default scheme} */ - public HttpHost(final String hostname, int port, final String scheme) { + public HttpHost(final String hostname, final int port, final String scheme) { super(); if (hostname == null) { throw new IllegalArgumentException("Host name may not be null"); @@ -90,27 +90,27 @@ /** * Creates a new {@link HttpHost HttpHost}, with default scheme. - * + * * @param hostname the hostname (IP or DNS name) * @param port the port number. * -1 indicates the scheme default port. */ - public HttpHost(final String hostname, int port) { + public HttpHost(final String hostname, final int port) { this(hostname, port, null); } - + /** * Creates a new {@link HttpHost HttpHost}, with default scheme and port. - * + * * @param hostname the hostname (IP or DNS name) */ public HttpHost(final String hostname) { this(hostname, -1, null); } - + /** * Copy constructor for {@link HttpHost HttpHost}. - * + * * @param httphost the HTTP host to copy details from */ public HttpHost (final HttpHost httphost) { @@ -119,7 +119,7 @@ /** * Returns the host name. - * + * * @return the host name (IP or DNS name) */ public String getHostName() { @@ -128,7 +128,7 @@ /** * Returns the port. - * + * * @return the host port, or -1 if not set */ public int getPort() { @@ -146,11 +146,11 @@ /** * Return the host URI, as a string. - * + * * @return the host URI */ public String toURI() { - CharArrayBuffer buffer = new CharArrayBuffer(32); + final CharArrayBuffer buffer = new CharArrayBuffer(32); buffer.append(this.schemeName); buffer.append("://"); buffer.append(this.hostname); @@ -168,27 +168,24 @@ * @return the host string, for example localhost:8080 */ public String toHostString() { - CharArrayBuffer buffer = new CharArrayBuffer(32); - buffer.append(this.hostname); - if (this.port != -1) { - buffer.append(':'); - buffer.append(Integer.toString(this.port)); - } - return buffer.toString(); + if (this.port != -1) + return this.hostname + ":" + Integer.toString(this.port); + else + return this.hostname; } public String toString() { return toURI(); - } - + } + public boolean equals(final Object obj) { if (obj == null) return false; if (this == obj) return true; if (obj instanceof HttpHost) { - HttpHost that = (HttpHost) obj; - return this.lcHostname.equals(that.lcHostname) + final HttpHost that = (HttpHost) obj; + return this.lcHostname.equals(that.lcHostname) && this.port == that.port && this.schemeName.equals(that.schemeName); } else { @@ -210,5 +207,5 @@ public Object clone() throws CloneNotSupportedException { return super.clone(); } - + }