1. Multiple sorting
How Java? reference this
http://stackoverflow.com/questions/1421322/how-do-i-sort-a-list-with-multiple-sort-parameters
?
How?Groovy? only one recursive + dynamic can instand the enum class(or switch statement).
?
class Clazz { String name String uid String firstName String lastName } Clazz c = new Clazz(name : "Andy", uid :1, firstName: 1, lastName: 1) Clazz c1 = new Clazz (name: "Andy", uid: 2, firstName: 1, lastName: 1) Clazz c2 = new Clazz (name: "Andy", uid: 2, firstName: 2, lastName: 1) Clazz c3 = new Clazz (name: "Andy", uid: 2, firstName: 2, lastName: 2) def objects = [c,c1,c2,c3] def properties = ["name"] sorting(objects, properties).each { println "=============" println it.name+" "+it.uid+" "+it.firstName+" "+it.lastName } protected def sorting(List<?> items, List properties){ items.sort {i1, i2-> println "---------------------" println i1.name+" "+i1.uid+" "+i1.firstName+" "+i1.lastName println i2.name+" "+i2.uid+" "+i2.firstName+" "+i2.lastName compare(i1, i2, properties, 0) } } private def compare(i1, i2, properties, i){ def flag = i1."${properties[i]}" <=> i2."${properties[i]}" if(flag == 0 && properties.size()>1){ compare(i1, i2, properties, i+1) } else { return flag } }