see attached patch:

removed strict class check from NameValuePair#equals and rewrote code for better readability. Updated API Doc. Test case changed to the modified contract.

Index: java/org/apache/commons/httpclient/NameValuePair.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v
retrieving revision 1.14
diff -u -r1.14 NameValuePair.java
--- java/org/apache/commons/httpclient/NameValuePair.java       31 Jan 2003 00:33:36 
-0000      1.14
+++ java/org/apache/commons/httpclient/NameValuePair.java       8 Sep 2003 08:36:58 
-0000
@@ -163,24 +163,21 @@
     }
 
     /**
-     * Test if the given <i>object</i> is equal to me. In this implementation,
-     * an <i>object</i> is equal to me iff it has the same runtime type and the
-     * <i>name</i> and <i>value</i> attributes are both <tt>equal</tt> (or
-     * <tt>==</tt>).
+     * Test if the given <i>object</i> is equal to me. <tt>NameValuePair</tt>s
+     * are equals if both their <tt>name</tt> and <tt>value</tt> fields are equal.
+     * If <tt>object</tt> is <tt>null</tt> this method returns <tt>false</tt>.
      *
-     * @param object the [EMAIL PROTECTED] Object} to compare to
+     * @param object the [EMAIL PROTECTED] Object} to compare to or <tt>null</tt>
      * @return true if the objects are equal.
      */
     public boolean equals(Object object) {
-        if (this == object) {
-            return true;
-        } else if (this.getClass().equals(object.getClass())) {
-            NameValuePair pair = (NameValuePair) object;
-            return ((null == name ? null == pair.name : name.equals(pair.name))
-                   && (null == value ? null == pair.value : 
value.equals(pair.value)));
-        } else {
-            return false;
-        }
+        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)));
     }
 
     /**
Index: test/org/apache/commons/httpclient/TestHeader.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHeader.java,v
retrieving revision 1.4
diff -u -r1.4 TestHeader.java
--- test/org/apache/commons/httpclient/TestHeader.java  23 Jan 2003 22:48:25 -0000     
 1.4
+++ test/org/apache/commons/httpclient/TestHeader.java  8 Sep 2003 08:37:09 -0000
@@ -122,10 +122,10 @@
         assertEquals("a: b\r\n",header.toExternalForm());
     }
 
-    public void testNotEqualToNVP() {
+    public void testEqualToNVP() {
         NameValuePair header = makePair("a","b");
         NameValuePair pair = new NameValuePair("a","b");
-        assertTrue(!header.equals(pair));
-        assertTrue(!pair.equals(header));
+        assertTrue(header.equals(pair));
+        assertTrue(pair.equals(header));
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to