commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
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 GMT
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 @@
   <body>
 
   <release version="4.1" date="TBD" description="">
+    <action issue="COLLECTIONS-512" dev="tn" type="fix" due-to="Cyrille Artho">
+      "TransformingComparator" did not comply with the contract of Object#equals.
+    </action>
     <action issue="COLLECTIONS-510" dev="tn" type="fix" due-to="Hollis Waite">
       Fix compilation errors when using source level 1.8 and a recent java 8 compiler.
     </action>

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<I, O
         }
         if (object.getClass().equals(this.getClass())) {
             final 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<String, String> t1 = TransformerUtils.nopTransformer();
+        TransformingComparator<String, String> comp1 = new TransformingComparator<String,
String>(t1);
+        TransformingComparator<String, String> comp2 = new TransformingComparator<String,
String>(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";



Mime
View raw message