Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 76868 invoked from network); 21 Jul 2007 11:52:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jul 2007 11:52:26 -0000 Received: (qmail 22089 invoked by uid 500); 21 Jul 2007 11:52:27 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 22069 invoked by uid 500); 21 Jul 2007 11:52:27 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 22060 invoked by uid 99); 21 Jul 2007 11:52:27 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Jul 2007 04:52:27 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 Jul 2007 04:52:25 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B77851A981C; Sat, 21 Jul 2007 04:52:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r558319 - /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java Date: Sat, 21 Jul 2007 11:52:04 -0000 To: httpcomponents-commits@jakarta.apache.org From: rolandw@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070721115204.B77851A981C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rolandw Date: Sat Jul 21 04:52:03 2007 New Revision: 558319 URL: http://svn.apache.org/viewvc?view=rev&rev=558319 Log: changed HttpHost to cache and use lowercase hostname Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java?view=diff&rev=558319&r1=558318&r2=558319 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpHost.java Sat Jul 21 04:52:03 2007 @@ -46,34 +46,44 @@ * @since 4.0 */ public class HttpHost { + /** The default scheme is "http". */ public static final String DEFAULT_SCHEME_NAME = "http"; /** The host to use. */ - private String hostname = null; + protected final String hostname; + + /** The lowercase host, for {@link #equals} and {@link #hashCode}. */ + protected final String lcHostname; + /** The port to use. */ - private int port = -1; + protected final int port; /** The scheme */ - private String schemeName = null; + protected final String schemeName; + /** + * Creates a new {@link HttpHost HttpHost}, specifying all values. * Constructor for HttpHost. * - * @param hostname the hostname (IP or DNS name). Can be null. - * @param port the port. Value -1 can be used to set default scheme port - * @param schemeName the name of the scheme. Value null can be used to set - * default scheme + * @param hostname the hostname (IP or DNS name) + * @param port the port number. + * -1 indicates the scheme default port. + * @param scheme the name of the scheme. + * null indicates the + * {@link #DEFAULT_SCHEME_NAME default scheme} */ - public HttpHost(final String hostname, int port, final String schemeName) { + public HttpHost(final String hostname, int port, final String scheme) { super(); if (hostname == null) { throw new IllegalArgumentException("Host name may not be null"); } - this.hostname = hostname; - if (schemeName != null) { - this.schemeName = schemeName.toLowerCase(); + this.hostname = hostname; + this.lcHostname = hostname.toLowerCase(); + if (scheme != null) { + this.schemeName = scheme.toLowerCase(); } else { this.schemeName = DEFAULT_SCHEME_NAME; } @@ -81,40 +91,38 @@ } /** - * Constructor for HttpHost. + * Creates a new {@link HttpHost HttpHost}, with default scheme. * - * @param hostname the hostname (IP or DNS name). Can be null. - * @param port the port. Value -1 can be used to set default scheme port + * @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) { this(hostname, port, null); } /** - * Constructor for HttpHost. + * Creates a new {@link HttpHost HttpHost}, with default scheme and port. * - * @param hostname the hostname (IP or DNS name). Can be null. + * @param hostname the hostname (IP or DNS name) */ public HttpHost(final String hostname) { this(hostname, -1, null); } /** - * Copy constructor for HttpHost + * Copy constructor for {@link HttpHost HttpHost}. * * @param httphost the HTTP host to copy details from */ public HttpHost (final HttpHost httphost) { - super(); - this.hostname = httphost.hostname; - this.port = httphost.port; - this.schemeName = httphost.schemeName; + this(httphost.hostname, httphost.port, httphost.schemeName); } /** - * Returns the host name (IP or DNS name). + * Returns the host name. * - * @return the host name (IP or DNS name), or null if not set + * @return the host name (IP or DNS name) */ public String getHostName() { return this.hostname; @@ -130,17 +138,18 @@ } /** - * Returns the scheme. - * @return The scheme. + * Returns the scheme name. + * + * @return the scheme name */ public String getSchemeName() { return this.schemeName; } /** - * Return the host uri. + * Return the host URI, as a string. * - * @return The host uri. + * @return the host URI */ public String toURI() { CharArrayBuffer buffer = new CharArrayBuffer(32); @@ -154,6 +163,12 @@ return buffer.toString(); } + + /** + * Obtains the host string, without scheme prefix. + * + * @return the host string, for example localhost:8080 + */ public String toHostString() { CharArrayBuffer buffer = new CharArrayBuffer(32); buffer.append(this.hostname); @@ -164,22 +179,18 @@ return buffer.toString(); } - /** - * @see java.lang.Object#toString() - */ + public String toString() { return toURI(); } - /** - * @see java.lang.Object#equals(java.lang.Object) - */ + 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.hostname.equalsIgnoreCase(that.hostname) + return this.lcHostname.equals(that.lcHostname) && this.port == that.port && this.schemeName.equals(that.schemeName); } else { @@ -192,7 +203,7 @@ */ public int hashCode() { int hash = LangUtils.HASH_SEED; - hash = LangUtils.hashCode(hash, this.hostname.toUpperCase()); + hash = LangUtils.hashCode(hash, this.lcHostname); hash = LangUtils.hashCode(hash, this.port); hash = LangUtils.hashCode(hash, this.schemeName); return hash;