Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 730df4f1f -> bf1a2386c


GROOVY-7530 and GROOVY-7602: intersect and disjoint broken for non-Comparable 
objects (closes #276)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f4c49d1b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f4c49d1b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f4c49d1b

Branch: refs/heads/GROOVY_2_4_X
Commit: f4c49d1b1aef94f3b436d5c78938dc3a14679c98
Parents: 730df4f
Author: paulk <pa...@asert.com.au>
Authored: Wed Mar 2 21:37:07 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Mar 3 22:16:06 2016 +1000

----------------------------------------------------------------------
 .../groovy/runtime/NumberAwareComparator.java   |  1 +
 src/test/groovy/GroovyMethodsTest.groovy        | 49 ++++++++++++++++++++
 2 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f4c49d1b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java 
b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
index 1d780af..c85cd04 100644
--- a/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
+++ b/src/main/org/codehaus/groovy/runtime/NumberAwareComparator.java
@@ -48,6 +48,7 @@ public class NumberAwareComparator<T> implements 
Comparator<T> {
         // may mean the removal of x or y in a sorting operation, which we 
don't want.
         int x1 = o1.hashCode();
         int x2 = o2.hashCode();
+        if (x1 == x2 && o1.equals(o2)) return 0;
         if (x1 > x2) return 1;
         return -1;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/f4c49d1b/src/test/groovy/GroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/GroovyMethodsTest.groovy 
b/src/test/groovy/GroovyMethodsTest.groovy
index b32db93..1e16f93 100644
--- a/src/test/groovy/GroovyMethodsTest.groovy
+++ b/src/test/groovy/GroovyMethodsTest.groovy
@@ -1564,6 +1564,55 @@ class GroovyMethodsTest extends GroovyTestCase {
         assert [4, 5] == iterableA.intersect(iterableB)
     }
 
+    // GROOVY-7602
+    void testIntersectForMaps() {
+        def list1 = [[language: 'Java'], [language: 'Groovy'], [language: 
'Scala']]
+        def list2 = [[language: 'Groovy'], [language: 'JRuby'], [language: 
'Java']]
+        def intersection = list1.intersect(list2)
+        assert intersection == [[language: 'Groovy'], [language: 'Java']]
+    }
+
+    // GROOVY-7602
+    void testIntersectForURL() {
+        def c1 = []
+        def c2 = []
+        c1 << new URL("http://sample.com/";)
+        c2 << new URL("http://sample.com/";)
+        assert c1.intersect(c2)
+    }
+
+    // GROOVY-7530
+    void testDisjointForMaps() {
+        def list1 = [[language: 'Java'], [language: 'Groovy'], [language: 
'Scala']]
+        def list2 = [[language: 'Groovy'], [language: 'JRuby'], [language: 
'Java']]
+        assert !list1.disjoint(list2)
+    }
+
+    class Foo {
+        private String name
+
+        Foo(String name) {
+            this.name = name
+        }
+
+        boolean equals(Object o) {
+            if (this.is(o)) return true
+            if (o == null || getClass() != o.getClass()) return false
+            name == o.name
+        }
+
+        int hashCode() {
+            return 13 + 7 * name.hashCode()
+        }
+    }
+
+    // GROOVY-7530
+    void testDisjointForFoo() {
+        def a = [new Foo("foo")]
+        def b = [new Foo("foo")]
+        assert !a.disjoint(b)
+    }
+
     void testDisjointForLists() {
         assert [].disjoint([])
         assert [].disjoint([4, 5, 6, 7, 8])

Reply via email to