Made #equals and #hashCode of HttpRoute consistent with implementations in other classes
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1044411 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
75e94a15dc
commit
50906f44e3
|
@ -30,6 +30,7 @@ package org.apache.http.conn.routing;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
import org.apache.http.annotation.Immutable;
|
import org.apache.http.annotation.Immutable;
|
||||||
|
import org.apache.http.util.LangUtils;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
|
|
||||||
|
@ -329,35 +330,17 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
||||||
* <code>false</code>
|
* <code>false</code>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(Object o) {
|
public final boolean equals(Object obj) {
|
||||||
if (o == this)
|
if (obj == null) return false;
|
||||||
return true;
|
if (this == obj) return true;
|
||||||
if (!(o instanceof HttpRoute))
|
if (obj instanceof HttpRoute) {
|
||||||
return false;
|
HttpRoute that = (HttpRoute) obj;
|
||||||
|
return LangUtils.equals(this.targetHost, that.targetHost) &&
|
||||||
HttpRoute that = (HttpRoute) o;
|
LangUtils.equals(this.localAddress, that.localAddress) &&
|
||||||
|
|
||||||
if (
|
|
||||||
this.targetHost.equals(that.targetHost) &&
|
|
||||||
( ( this.localAddress == that.localAddress) ||
|
|
||||||
(( this.localAddress != null) &&
|
|
||||||
this.localAddress.equals(that.localAddress))
|
|
||||||
) &&
|
|
||||||
( ( this.proxyChain == that.proxyChain) ||
|
|
||||||
( this.proxyChain.length == that.proxyChain.length)
|
|
||||||
// comparison of actual proxies follows below
|
|
||||||
) &&
|
|
||||||
(this.secure == that.secure) &&
|
(this.secure == that.secure) &&
|
||||||
(this.tunnelled == that.tunnelled) &&
|
(this.tunnelled == that.tunnelled) &&
|
||||||
(this.layered == that.layered)
|
(this.layered == that.layered) &&
|
||||||
) {
|
LangUtils.equals(this.proxyChain, that.proxyChain);
|
||||||
boolean equal = true;
|
|
||||||
// chain length has been compared above, now check the proxies
|
|
||||||
if (this.proxyChain != null) {
|
|
||||||
for (int i=0; equal && (i<this.proxyChain.length); i++)
|
|
||||||
equal = this.proxyChain[i].equals(that.proxyChain[i]);
|
|
||||||
}
|
|
||||||
return equal;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -371,21 +354,16 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public final int hashCode() {
|
||||||
|
int hash = LangUtils.HASH_SEED;
|
||||||
int hc = this.targetHost.hashCode();
|
hash = LangUtils.hashCode(hash, this.targetHost);
|
||||||
|
hash = LangUtils.hashCode(hash, this.localAddress);
|
||||||
if (this.localAddress != null)
|
for (int i = 0; i < this.proxyChain.length; i++) {
|
||||||
hc ^= localAddress.hashCode();
|
hash = LangUtils.hashCode(hash, this.proxyChain[i]);
|
||||||
hc ^= proxyChain.length;
|
}
|
||||||
for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode();
|
hash = LangUtils.hashCode(hash, this.secure);
|
||||||
|
hash = LangUtils.hashCode(hash, this.tunnelled);
|
||||||
if (this.secure)
|
hash = LangUtils.hashCode(hash, this.layered);
|
||||||
hc ^= 0x11111111;
|
return hash;
|
||||||
|
|
||||||
hc ^= this.tunnelled.hashCode();
|
|
||||||
hc ^= this.layered.hashCode();
|
|
||||||
|
|
||||||
return hc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue