Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/test/org/apache/commons/httpclient/TestNVP.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/test/org/apache/commons/httpclient/TestNVP.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/test/org/apache/commons/httpclient/TestNVP.java (working copy)
@@ -24,8 +24,6 @@
* information on the Apache Software Foundation, please see
* .
*
- * [Additional notices, if required by prior licensing conditions]
- *
*/
package org.apache.commons.httpclient;
@@ -86,44 +84,24 @@
assertEquals("value",pair.getValue());
}
- public void testEqualsAndHashCode() {
- NameValuePair pair1 = makePair();
- NameValuePair pair2 = makePair();
-
- assertEquals(pair1,pair1);
- assertEquals(pair1.hashCode(),pair1.hashCode());
- assertEquals(pair2,pair2);
- assertEquals(pair2.hashCode(),pair2.hashCode());
- assertEquals(pair1,pair2);
- assertEquals(pair1.hashCode(),pair2.hashCode());
- assertEquals(pair2,pair1);
-
- pair1.setName("name");
- pair1.setValue("value");
-
- assertEquals(pair1,pair1);
- assertEquals(pair1.hashCode(),pair1.hashCode());
- assertTrue(!pair1.equals(pair2));
- assertTrue(!pair2.equals(pair1));
-
- pair2.setName("name");
-
- assertEquals(pair1,pair1);
- assertEquals(pair1.hashCode(),pair1.hashCode());
- assertEquals(pair2,pair2);
- assertEquals(pair2.hashCode(),pair2.hashCode());
- assertTrue(!pair1.equals(pair2));
- assertTrue(!pair2.equals(pair1));
-
-
- pair2.setValue("value");
-
- assertEquals(pair1,pair1);
- assertEquals(pair1.hashCode(),pair1.hashCode());
- assertEquals(pair2,pair2);
- assertEquals(pair2.hashCode(),pair2.hashCode());
- assertEquals(pair1,pair2);
- assertEquals(pair1.hashCode(),pair2.hashCode());
- assertEquals(pair2,pair1);
+ public void testHashCode() {
+ NameValuePair param1 = new NameValuePair("name1", "value1");
+ NameValuePair param2 = new NameValuePair("name2", "value2");
+ NameValuePair param3 = new NameValuePair("name1", "value1");
+ assertTrue(param1.hashCode() != param2.hashCode());
+ assertTrue(param1.hashCode() == param3.hashCode());
}
+
+ public void testEquals() {
+ NameValuePair param1 = new NameValuePair("name1", "value1");
+ NameValuePair param2 = new NameValuePair("name2", "value2");
+ NameValuePair param3 = new NameValuePair("name1", "value1");
+ assertFalse(param1.equals(param2));
+ assertFalse(param1.equals(null));
+ assertFalse(param1.equals("name1 = value1"));
+ assertTrue(param1.equals(param1));
+ assertTrue(param2.equals(param2));
+ assertTrue(param1.equals(param3));
+ }
+
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HostConfiguration.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HostConfiguration.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HostConfiguration.java (working copy)
@@ -31,6 +31,7 @@
import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.util.LangUtils;
import java.net.InetAddress;
@@ -533,13 +534,10 @@
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- if (host != null) {
- return host.hashCode();
- } else if (proxyHost != null) {
- return proxyHost.hashCode();
- } else {
- return super.hashCode();
- }
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.host);
+ hash = LangUtils.hashCode(hash, this.proxyHost);
+ return hash;
}
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/Cookie.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/Cookie.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/Cookie.java (working copy)
@@ -37,6 +37,7 @@
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
+import org.apache.commons.httpclient.util.LangUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -400,9 +401,11 @@
* @return A hash code
*/
public int hashCode() {
- return super.hashCode()
- ^ (null == cookiePath ? 0 : cookiePath.hashCode())
- ^ (null == cookieDomain ? 0 : cookieDomain.hashCode());
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.getName());
+ hash = LangUtils.hashCode(hash, this.cookieDomain);
+ hash = LangUtils.hashCode(hash, this.cookiePath);
+ return hash;
}
@@ -412,20 +415,13 @@
* @return true if the two objects are equal.
*/
public boolean equals(Object obj) {
- LOG.trace("enter Cookie.equals(Object)");
-
- if ((obj != null) && (obj instanceof Cookie)) {
+ if (obj == null) return false;
+ if (this == obj) return true;
+ if (obj instanceof Cookie) {
Cookie that = (Cookie) obj;
- return
- (null == this.getName()
- ? null == that.getName()
- : this.getName().equals(that.getName()))
- && (null == this.getPath()
- ? null == that.getPath()
- : this.getPath().equals(that.getPath()))
- && (null == this.getDomain()
- ? null == that.getDomain()
- : this.getDomain().equals(that.getDomain()));
+ return LangUtils.equals(this.getName(), that.getName())
+ && LangUtils.equals(this.cookieDomain, that.cookieDomain)
+ && LangUtils.equals(this.cookiePath, that.cookiePath);
} else {
return false;
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/protocol/Protocol.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/protocol/Protocol.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/protocol/Protocol.java (working copy)
@@ -32,6 +32,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.httpclient.util.LangUtils;
+
/**
* A class to encapsulate the specifics of a protocol. This class class also
* provides the ability to customize the set and characteristics of the
@@ -283,6 +285,11 @@
* @return The hash code.
*/
public int hashCode() {
- return scheme.hashCode();
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.defaultPort);
+ hash = LangUtils.hashCode(hash, this.scheme.toLowerCase());
+ hash = LangUtils.hashCode(hash, this.secure);
+ hash = LangUtils.hashCode(hash, this.socketFactory);
+ return hash;
}
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/auth/AuthScope.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/auth/AuthScope.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/auth/AuthScope.java (working copy)
@@ -29,6 +29,8 @@
package org.apache.commons.httpclient.auth;
+import org.apache.commons.httpclient.util.LangUtils;
+
/**
* The class represents an authentication scope consisting of a host name,
* a port number, a realm name and an authentication scheme name which
@@ -316,9 +318,11 @@
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- return ((this.host != null) ? this.host.toLowerCase().hashCode() : 0) +
- ((this.port >= 0) ? this.port : -1) +
- ((this.realm != null) ? this.realm.hashCode() : 0) +
- ((this.scheme != null) ? this.scheme.toLowerCase().hashCode() : 0);
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.host);
+ hash = LangUtils.hashCode(hash, this.port);
+ hash = LangUtils.hashCode(hash, this.realm);
+ hash = LangUtils.hashCode(hash, this.scheme);
+ return hash;
}
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HttpHost.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HttpHost.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/HttpHost.java (working copy)
@@ -30,6 +30,7 @@
package org.apache.commons.httpclient;
import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.util.LangUtils;
/**
* Holds all of the variables needed to describe an HTTP connection to a host. This includes
@@ -209,10 +210,11 @@
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- return
- this.hostname.hashCode() +
- this.port +
- this.protocol.hashCode();
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.hostname);
+ hash = LangUtils.hashCode(hash, this.port);
+ hash = LangUtils.hashCode(hash, this.protocol);
+ return hash;
}
}
Index: /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/NameValuePair.java
===================================================================
--- /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/NameValuePair.java (revision 157243)
+++ /home/oleg/src/apache.org/jakarta-commons/httpclient-trunk/src/java/org/apache/commons/httpclient/NameValuePair.java (working copy)
@@ -31,6 +31,8 @@
import java.io.Serializable;
+import org.apache.commons.httpclient.util.LangUtils;
+
/**
*
A simple class encapsulating a name/value pair.
*
@@ -128,46 +130,22 @@
return ("name=" + name + ", " + "value=" + value);
}
- /**
- * Test if the given object is equal to me. NameValuePairs
- * are equals if both their name and value fields are equal.
- * If object is null this method returns false.
- *
- * @param object the {@link Object} to compare to or null
- * @return true if the objects are equal.
- */
- public boolean equals(Object object) {
+ public boolean equals(final Object object) {
if (object == null) return false;
if (this == object) return true;
- if (!(object instanceof NameValuePair)) return false;
-
- NameValuePair pair = (NameValuePair) object;
- return ((null == name ? null == pair.name : name.equals(pair.name))
- && (null == value ? null == pair.value : value.equals(pair.value)));
+ if (object instanceof NameValuePair) {
+ NameValuePair that = (NameValuePair) object;
+ return LangUtils.equals(this.name, that.name)
+ && LangUtils.equals(this.value, that.value);
+ } else {
+ return false;
+ }
}
- /**
- * hashCode. Returns a hash code for this object such that if a.{@link
- * #equals equals}(b) then a.hashCode() == b.hashCode().
- * @return The hash code.
- */
public int hashCode() {
- return (this.getClass().hashCode()
- ^ (null == name ? 0 : name.hashCode())
- ^ (null == value ? 0 : value.hashCode()));
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.name);
+ hash = LangUtils.hashCode(hash, this.value);
+ return hash;
}
-
- /*
- public Object clone() {
- try {
- NameValuePair that = (NameValuePair)(super.clone());
- that.setName(this.getName());
- that.setValue(this.getValue());
- return that;
- } catch(CloneNotSupportedException e) {
- // this should never happen
- throw new RuntimeException("Panic. super.clone not supported in NameValuePair.");
- }
- }
- */
}