home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (Groovy3818Bug.groovy)

This example Groovy source code file (Groovy3818Bug.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

comparator, dummy, dummy, groovytestcase, han, l, luke, luke, sky, sky, skywalker, skywalker, solo, treeset

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:

new blog posts

 

Copyright 1998-2016 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.