Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2D67510205 for ; Thu, 10 Apr 2014 21:55:58 +0000 (UTC) Received: (qmail 13338 invoked by uid 500); 10 Apr 2014 21:55:56 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 13022 invoked by uid 500); 10 Apr 2014 21:55:55 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 12862 invoked by uid 99); 10 Apr 2014 21:55:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Apr 2014 21:55:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Apr 2014 21:55:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CE99E23889E1; Thu, 10 Apr 2014 21:55:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1586477 - in /commons/proper/collections/trunk/src: changes/changes.xml main/java/org/apache/commons/collections4/comparators/TransformingComparator.java test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java Date: Thu, 10 Apr 2014 21:55:29 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140410215529.CE99E23889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tn Date: Thu Apr 10 21:55:29 2014 New Revision: 1586477 URL: http://svn.apache.org/r1586477 Log: [COLLECTIONS-512] Fix equals method for TransformingComparator. Thanks to Cyrille Artho. Modified: commons/proper/collections/trunk/src/changes/changes.xml commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java Modified: commons/proper/collections/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1586477&r1=1586476&r2=1586477&view=diff ============================================================================== --- commons/proper/collections/trunk/src/changes/changes.xml (original) +++ commons/proper/collections/trunk/src/changes/changes.xml Thu Apr 10 21:55:29 2014 @@ -22,6 +22,9 @@ + + "TransformingComparator" did not comply with the contract of Object#equals. + Fix compilation errors when using source level 1.8 and a recent java 8 compiler. Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java?rev=1586477&r1=1586476&r2=1586477&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java Thu Apr 10 21:55:29 2014 @@ -120,8 +120,8 @@ public class TransformingComparator comp = (TransformingComparator) object; - return null == decorated ? null == comp.decorated : decorated.equals(comp.decorated) && - null == transformer ? null == comp.transformer : transformer.equals(comp.transformer); + return (null == decorated ? null == comp.decorated : decorated.equals(comp.decorated)) && + (null == transformer ? null == comp.transformer : transformer.equals(comp.transformer)); } return false; } Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java?rev=1586477&r1=1586476&r2=1586477&view=diff ============================================================================== --- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java (original) +++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/comparators/TransformingComparatorTest.java Thu Apr 10 21:55:29 2014 @@ -21,6 +21,7 @@ import java.util.LinkedList; import java.util.List; import org.apache.commons.collections4.ComparatorUtils; +import org.apache.commons.collections4.Transformer; import org.apache.commons.collections4.TransformerUtils; /** @@ -60,6 +61,20 @@ public class TransformingComparatorTest return list; } + public void testEquals() { + Transformer t1 = TransformerUtils.nopTransformer(); + TransformingComparator comp1 = new TransformingComparator(t1); + TransformingComparator comp2 = new TransformingComparator(t1, comp1); + + // Checks the contract: equals-hashcode on comp1 and comp2 + assertTrue("Contract failed: equals-hashcode", + comp1.equals(comp2) ? comp1.hashCode() == comp2.hashCode() : true); + + // Checks the contract: equals-hashcode on comp1 and comp2 + assertTrue("Contract failed: equals-hashcode", + comp2.equals(comp1) ? comp2.hashCode() == comp1.hashCode() : true); + } + @Override public String getCompatibilityVersion() { return "4";