Sort on linkedlists with double values (inside main list)

"M.v.Gulik" <[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAOSpiuHNbAMwTARyeO_Os_Cfm0EMtsz7qitBeP0ZOHghKapKiA@mail.gmail.com>
I'm totally bewildered by the following. (And googling it did not help).

Erm ... markup ... don't know.

[code]
    def sorttest = []
    if(1){
        sorttest = [[x:3,y:2],[x:4,y:1],[x:2,y:3],[x:1,y:4]]
        // if(DBL){println('sorttest|1a: ' + sorttest)}
        assert sorttest instanceof List
        assert sorttest.size() == 4
        assert sorttest[0] instanceof java.util.LinkedHashMap
        assert sorttest[0].size() == 2
        assert sorttest[0].x instanceof Integer

        sorttest.sort{[it.x, it.y]}
        // if(DBL){println('sorttest|1a: ' + sorttest)}
        sorttest.sort{[-it.x, -it.y]}
        // if(DBL){println('sorttest|1b: ' + sorttest)}

        sorttest.sort{[it.y, it.x]}
        // if(DBL){println('sorttest|2a: ' + sorttest)}
        sorttest.sort{[-it.y, -it.x]}
        // if(DBL){println('sorttest|2b: ' + sorttest)}
    }
    if(1){
        sorttest = [[x:3,y:2],[x:4,y:1],[x:2,y:3],[x:1,y:4]]
        // if(DBL){println('sorttest|0a: ' + sorttest)}
        for (int i in 1..sorttest.size()){
            i -= 1
            sorttest[i] = [x:sorttest[i].x.toDouble(),
y:sorttest[i].y.toDouble()]
        }
        // if(DBL){println('sorttest|0b: ' + sorttest)}
        assert sorttest instanceof List
        assert sorttest.size() == 4
        assert sorttest[0] instanceof java.util.LinkedHashMap
        assert sorttest[0].size() == 2
        assert sorttest[0].x instanceof Double

        sorttest.sort{[it.x, it.y]}
        // if(DBL){println('sorttest|1a: ' + sorttest)}
        sorttest.sort{[-it.x, -it.y]} // reversing the output (well trying)
        // if(DBL){println('sorttest|1b: ' + sorttest)}

        sorttest.sort{[it.y, it.x]}
        // if(DBL){println('sorttest|2a: ' + sorttest)}
        sorttest.sort{[-it.y, -it.x]} // reversing the output (well trying)
        // if(DBL){println('sorttest|2b: ' + sorttest)}
    }

[/code]
[Output]:
    sorttest|0: [[x:3, y:2], [x:4, y:1], [x:2, y:3], [x:1, y:4]]
    sorttest|1a: [[x:1, y:4], [x:2, y:3], [x:3, y:2], [x:4, y:1]]
    sorttest|1b: [[x:4, y:1], [x:3, y:2], [x:2, y:3], [x:1, y:4]]
    sorttest|2a: [[x:4, y:1], [x:3, y:2], [x:2, y:3], [x:1, y:4]]
    sorttest|2b: [[x:1, y:4], [x:2, y:3], [x:3, y:2], [x:4, y:1]]

    sorttest|0a: [[x:3, y:2], [x:4, y:1], [x:2, y:3], [x:1, y:4]]
    sorttest|0b: [[x:3.0, y:2.0], [x:4.0, y:1.0], [x:2.0, y:3.0],
[x:1.0, y:4.0]]
    sorttest|1a: [[x:1.0, y:4.0], [x:2.0, y:3.0], [x:3.0, y:2.0],
[x:4.0, y:1.0]]
    sorttest|1b: [[x:1.0, y:4.0], [x:2.0, y:3.0], [x:3.0, y:2.0],
[x:4.0, y:1.0]] -- No Change ???
    sorttest|2a: [[x:4.0, y:1.0], [x:3.0, y:2.0], [x:2.0, y:3.0],
[x:1.0, y:4.0]]
    sorttest|2b: [[x:4.0, y:1.0], [x:3.0, y:2.0], [x:2.0, y:3.0],
[x:1.0, y:4.0]] -- No Change ???
[/Output]

If this it something version specific (like: groovy-3.0.12) ... I
can't change that (not in this case).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.