|
Groovy example source code file (Groovy3818Bug.groovy)
The Groovy Groovy3818Bug.groovy source code
package groovy.bugs
class Groovy3818Bug extends GroovyTestCase {
void testCreatingSimilarSetandMapWithComparator() {
def scompare = { a, b -> a.id <=> b.id } as Comparator
def set = new TreeSet( scompare )
set << [name: "Han Solo", id: 1]
set << [name: "Luke Skywalker", id: 2]
set << [name: "L. Skywalker", id: 3]
def result = set.findAll { elt -> elt.name =~ /Sky/ }
assert result.size() == 2
result = set.grep { elt -> elt.name =~ /Sky/ }
assert result.size() == 2
def mcompare = { a, b -> a.id <=> b.id } as Comparator
def map = new TreeMap( mcompare )
map[[name: "Han Solo", id: 1]] = "Dummy"
map[[name: "Luke Skywalker", id: 2]] = "Dummy"
map[[name: "L. Skywalker", id: 3]] = "Dummy"
result = map.findAll { elt ->elt.key.name =~ /Sky/ }
assert result.size() == 2
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy Groovy3818Bug.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.