groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Strachan, Paul" <Paul.Strac...@det.nsw.edu.au>
Subject not sure about Collection.intersect
Date Mon, 08 Feb 2016 14:11:48 GMT
Groovy 2.4.4 / 2.4.5

Hi - I'd like to get a list of objects from collection A that exist in collection B using
intersect() but I'm getting no results:


def c1 = []// as Set
def c2 = []// as Set
c1 << new TestClass(name: 'mike')
c2 << new TestClass(name: 'mike')
println c1.contains(c2[0])
assert c1.intersect(c2).size() == 1




Output:

true
Assertion failed:

assert c1.intersect(c2).size() == 1
       |  |         |   |      |
       |  []        |   0      false
       |            [sample.TestClass@333357]
       [sample.TestClass@333357]


TestClass.groovy


package sample

import groovy.transform.EqualsAndHashCode
@EqualsAndHashCode(includes = 'name')
class TestClass {
    String name
}


Is intersect only for simple types?



**********************************************************************
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**********************************************************************

Mime
View raw message