|
Groovy example source code file (Groovy3818Bug.groovy)
The Groovy Groovy3818Bug.groovy source codepackage 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: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.