singalen: (Default)

Originally published at code name. You can comment here or there.

Google Buzz

I wonder why this was not in JDK/Groovy Collections.

Just put together a Comparator for StackOverflow question – a Groovy Comparator that would sort class field names in the declaration order. Feel free to use:

class PropComparator implements Comparator {
    private Class clazz
    PropComparator(Class clazz) { this.clazz = clazz }

    int compare(Object o1, Object o2) {
        clazz.declaredFields.findIndexOf{it.name == o1}
          - clazz.declaredFields.findIndexOf{it.name == o2}
    }
}

Tags:

April 2017

S M T W T F S
      1
2345 678
9101112131415
16171819202122
23242526272829
30      

Syndicate

RSS Atom
Page generated 25/9/17 18:48

Expand Cut Tags

No cut tags