Return-Path: Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@www.apache.org Received: (qmail 94089 invoked from network); 8 Sep 2003 08:40:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 8 Sep 2003 08:40:31 -0000 Received: (qmail 12845 invoked by uid 500); 8 Sep 2003 08:40:01 -0000 Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@jakarta.apache.org Received: (qmail 12820 invoked by uid 500); 8 Sep 2003 08:40:00 -0000 Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Commons HttpClient Project" Reply-To: "Commons HttpClient Project" Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 12765 invoked from network); 8 Sep 2003 08:39:59 -0000 Received: from unknown (HELO nose.ch) (195.134.131.71) by daedalus.apache.org with SMTP; 8 Sep 2003 08:39:59 -0000 Received: (qmail 1635 invoked from network); 8 Sep 2003 08:40:05 -0000 Received: from calvin.nose.ch (HELO nose.ch) (192.168.1.7) by 0 with SMTP; 8 Sep 2003 08:40:05 -0000 Message-ID: <3F5C4065.7020800@nose.ch> Date: Mon, 08 Sep 2003 10:40:05 +0200 From: =?ISO-8859-1?Q?Ortwin_Gl=FCck?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030612 X-Accept-Language: de-ch, en-us MIME-Version: 1.0 To: Commons HttpClient Project Subject: Re: [PATCH] NameValuePair.equals References: <3F5C29A4.8080302@nose.ch> In-Reply-To: <3F5C29A4.8080302@nose.ch> Content-Type: multipart/mixed; boundary="------------040009010607090504020905" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --------------040009010607090504020905 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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. --------------040009010607090504020905 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.txt" 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 object is equal to me. In this implementation, - * an object is equal to me iff it has the same runtime type and the - * name and value attributes are both equal (or - * ==). + * 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 + * @param object the {@link Object} to compare to or null * @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)); } } --------------040009010607090504020905 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org --------------040009010607090504020905--